Skip to content

Commit

Permalink
Fix compatibility with nette/application v2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag committed Aug 18, 2016
1 parent 7fdaca2 commit 99e5419
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Extension/Application/Type/SignalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
{
parent::buildView($view, $form, $options);

$view->vars['full_name'] = Presenter::SIGNAL_KEY;
// Detect nette/application v2.4+.
$prefix = property_exists('Nette\Application\UI\Component', 'onAnchor') && $form->getRoot()->getConfig()->getMethod() === 'POST';
$view->vars['full_name'] = ($prefix ? '_' : '').Presenter::SIGNAL_KEY;
$view->vars['value'] = $options['data'];
}

Expand Down
3 changes: 3 additions & 0 deletions tests/functional/src/Fixtures/ArticlePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function actionDefault()
protected function createComponentForm()
{
$builder = $this->formFactory->createBuilder(FormType::class, new Task());
if ($this->getRequest()->getParameter('useget')) {
$builder->setMethod('GET');
}
$builder->add('text', TextType::class);
$builder->add('save', SubmitType::class);

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/src/Fixtures/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RouterFactory extends Object
public function create()
{
$router = new RouteList();
$router[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
$router[] = new Route('<presenter>[/useget/<useget>]', 'Homepage:default');

return $router;
}
Expand Down
41 changes: 37 additions & 4 deletions tests/functional/src/SimpleFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,65 @@
*/
class SimpleFormTest extends Unit
{
public function testRendering()
public function testPostMethodRendering()
{
$this->tester->amOnPage('/article/');
$this->tester->seeResponseCodeIs(200);
$this->tester->see(null, 'form');
$this->tester->see(null, 'input#form__token'); // CSRF protection
$this->tester->see(null, 'input[name="do"]'); // Signal for Nette/Application
$this->tester->see(null, 'input[name="'.(property_exists('Nette\Application\UI\Component', 'onAnchor') ? '_' : '').'do"]'); // Signal for Nette/Application
$this->tester->see(null, 'button');
}

public function testValidation()
public function testPostMethodValidation()
{
$this->tester->amOnPage('/article/');
$this->tester->seeResponseCodeIs(200);
$this->tester->fillField('#form_text', '');
$this->tester->click('button');
$this->tester->see(null, 'input[name="'.(property_exists('Nette\Application\UI\Component', 'onAnchor') ? '_' : '').'do"]');
$this->tester->see('error', '.state');
$this->tester->see('This value should not be blank.');
}

public function testSuccess()
public function testPostMethodSuccess()
{
$this->tester->amOnPage('/article/');
$this->tester->seeResponseCodeIs(200);
$this->tester->fillField('#form_text', 'lorem ipsum');
$this->tester->click('button');
$this->tester->see(null, 'input[name="'.(property_exists('Nette\Application\UI\Component', 'onAnchor') ? '_' : '').'do"]');
$this->tester->see('success', '.state');
}

public function testGetMethodRendering()
{
$this->tester->amOnPage('/article/useget/1');
$this->tester->seeResponseCodeIs(200);
$this->tester->see(null, 'form');
$this->tester->see(null, 'input#form__token'); // CSRF protection
$this->tester->see(null, 'input[name="do"]'); // Signal for Nette/Application
$this->tester->see(null, 'button');
}

public function testGetMethodValidation()
{
$this->tester->amOnPage('/article/useget/1');
$this->tester->seeResponseCodeIs(200);
$this->tester->fillField('#form_text', '');
$this->tester->click('button');
$this->tester->see(null, 'input[name="do"]');
$this->tester->see('error', '.state');
$this->tester->see('This value should not be blank.');
}

public function testGetMethodSuccess()
{
$this->tester->amOnPage('/article/useget/1');
$this->tester->seeResponseCodeIs(200);
$this->tester->fillField('#form_text', 'lorem ipsum');
$this->tester->click('button');
$this->tester->see(null, 'input[name="do"]');
$this->tester->see('success', '.state');
}
}

0 comments on commit 99e5419

Please sign in to comment.