Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Merge branch 'honzavaclavik-master' into 'master'
Browse files Browse the repository at this point in the history
Close PR #40
  • Loading branch information
mrtnzlml committed Nov 7, 2016
2 parents f62bcca + a2c1e66 commit 7362fe7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Traits/TComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ protected function attachToPresenter(IComponent $component, $name = NULL)
$this->__testbench_presenterMock->run(new Mocks\ApplicationRequestMock);
}

protected function checkRenderOutput(IComponent $control, $expected)
protected function checkRenderOutput(IComponent $control, $expected, array $renderParameters = [])
{
if (!$control->getParent()) {
$this->attachToPresenter($control);
}
ob_start();
$control->render();
$control->render(...$renderParameters);
if (is_file($expected)) {
\Tester\Assert::matchFile($expected, ob_get_clean());
} else {
Expand Down
21 changes: 21 additions & 0 deletions tests/Traits/TComponentTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ class TComponentTest extends \Tester\TestCase
$this->checkRenderOutput($control, __DIR__ . '/Component.expected');
}

/**
* @see vendor/nette/application/tests/Bridges.Latte/UIMacros.control.2.phpt
*/
public function testRenderWithParametersNetteCompatibility() {
$latte = new \Latte\Engine;
$latte->setLoader(new \Latte\Loaders\StringLoader);
\Nette\Bridges\ApplicationLatte\UIMacros::install($latte->getCompiler());
$latte->addProvider('uiControl', new \ComponentWithParameters);

Assert::same('["var1"]', $latte->renderToString('{control cwp var1}'));
Assert::same('["var1",1,2]', $latte->renderToString('{control cwp var1, 1, 2}'));
Assert::same('[{"var1":5,"0":1,"1":2}]', $latte->renderToString('{control cwp var1 => 5, 1, 2}'));
}

public function testRenderWithParameters()
{
$control = new \ComponentWithParameters;
$this->checkRenderOutput($control, '[1]', [1]);
$this->checkRenderOutput($control, '[1,"2"]', [1, '2']);
}

public function testRenderWithExplicitAttach()
{
$this->attachToPresenter($control = new \Component);
Expand Down
16 changes: 16 additions & 0 deletions tests/_helpers/components/ComponentWithParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

class ComponentWithParameters extends \Nette\Application\UI\Control
{

public function render($parameterOne, $parameterTwo = NULL)
{
echo json_encode(func_get_args(), JSON_OBJECT_AS_ARRAY);
}

public function getComponent($name, $need = TRUE)
{
return new self;
}

}

0 comments on commit 7362fe7

Please sign in to comment.