-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
latte: fixed parsing of {input} & {label} arguments
- Loading branch information
Showing
5 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** @phpVersion 8.0 */ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Bridges\FormsLatte\FormsExtension; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
if (version_compare(Latte\Engine::VERSION, '3', '<')) { | ||
Tester\Environment::skip('Test for Latte 3'); | ||
} | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
$latte->addExtension(new FormsExtension); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_input = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global))->getControlPart()->attributes() %A%', | ||
$latte->compile('<input n:name="foo">'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_input = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global))->getControlPart(\'\')->attributes() %A%', | ||
$latte->compile('<input n:name="foo:">'), | ||
); | ||
|
||
Assert::exception( | ||
fn() => $latte->compile('<input n:name="foo: class => foo">'), | ||
Latte\CompileException::class, | ||
"Unexpected '=>foo', expecting end of attribute in n:name (on line 1 at column 27)", | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_input = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global))->getControlPart(\'x\')->attributes() %A%', | ||
$latte->compile('<input n:name="foo:x">'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_input = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global))->getControlPart(\'x\')->attributes() %A%', | ||
$latte->compile('<input n:name=\'"foo":"x"\'>'), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** @phpVersion 8.0 */ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Bridges\FormsLatte\FormsExtension; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
if (version_compare(Latte\Engine::VERSION, '3', '<')) { | ||
Tester\Environment::skip('Test for Latte 3'); | ||
} | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
$latte->addExtension(new FormsExtension); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl() %A%', | ||
$latte->compile('{input foo}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl()->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{input foo class => foo}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControl()->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{input foo, class => foo}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\') %A%', | ||
$latte->compile('{input foo:}'), | ||
); | ||
|
||
Assert::exception( | ||
fn() => $latte->compile('{input foo: class => foo}'), | ||
Latte\CompileException::class, | ||
"Unexpected '=>foo', expecting end of tag in {input} (on line 1 at column 19)", | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\') %A%', | ||
$latte->compile('{input foo:,}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'\')->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{input foo:, class => foo}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', | ||
$latte->compile('{input foo:x}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\')->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{input foo:x, class => foo}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', | ||
$latte->compile('{input "foo":"x"}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getControlPart(\'x\') %A%', | ||
$latte->compile('{input "foo" : "x"}'), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** @phpVersion 8.0 */ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Bridges\FormsLatte\FormsExtension; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
if (version_compare(Latte\Engine::VERSION, '3', '<')) { | ||
Tester\Environment::skip('Test for Latte 3'); | ||
} | ||
|
||
|
||
$latte = new Latte\Engine; | ||
$latte->setLoader(new Latte\Loaders\StringLoader); | ||
$latte->addExtension(new FormsExtension); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel()) %A%', | ||
$latte->compile('{label foo /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{label foo class => foo /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabel())?->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{label foo, class => foo /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\')) %A%', | ||
$latte->compile('{label foo: /}'), | ||
); | ||
|
||
Assert::exception( | ||
fn() => $latte->compile('{label foo: class => foo /}'), | ||
Latte\CompileException::class, | ||
"Unexpected '=>foo', expecting end of tag in {label} (on line 1 at column 19)", | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\')) %A%', | ||
$latte->compile('{label foo:, /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'\'))?->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{label foo:, class => foo /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', | ||
$latte->compile('{label foo:x /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\'))?->addAttributes([\'class\' => \'foo\']) %A%', | ||
$latte->compile('{label foo:x, class => foo /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', | ||
$latte->compile('{label "foo":"x" /}'), | ||
); | ||
|
||
Assert::match( | ||
'%A%echo ($ʟ_label = Nette\Bridges\FormsLatte\Runtime::item(\'foo\', $this->global)->getLabelPart(\'x\')) %A%', | ||
$latte->compile('{label "foo" : "x" /}'), | ||
); |