Skip to content

Commit

Permalink
Presenter: added test for initGlobalParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 authored and dg committed Aug 13, 2015
1 parent a73e67e commit 1e947c7
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/Application/Presenter.parameters.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

/**
* Test: Nette\Application\UI\Presenter::initGlobalParameters() and signals
*/

use Nette\Http;
use Nette\Application;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


class TestPresenter extends Application\UI\Presenter
{
public $ajax = FALSE;


public function isAjax()
{
return $this->ajax;
}


protected function startup()
{
parent::startup();
throw new Application\AbortException();
}


}


function createPresenter()
{
$presenter = new TestPresenter();
$presenter->injectPrimary(NULL, NULL, NULL, new Http\Request(new Http\UrlScript()), new Http\Response());
$presenter->autoCanonicalize = FALSE;
return $presenter;
}


test(function () {
//signal in GET
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'GET', array(
'do' => 'foo'
)));
Assert::same(array('', 'foo'), $presenter->getSignal());
});

test(function () {
//signal for subcomponent in GET
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'GET', array(
'do' => 'foo-bar'
)));
Assert::same(array('foo', 'bar'), $presenter->getSignal());
});

test(function () {
//signal in POST
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'POST', array(), array(
'do' => 'foo'
)));
Assert::same(array('', 'foo'), $presenter->getSignal());
});

test(function () {
//signal in POST overwriting empty GET
$presenter = createPresenter();
$presenter->run(new Application\Request('Foo', 'POST', array('do' => NULL), array(
'do' => 'foo'
)));
Assert::same(array('', 'foo'), $presenter->getSignal());
});

test(function () {
//AJAX: signal in POST
$presenter = createPresenter();
$presenter->ajax = TRUE;
$presenter->run(new Application\Request('Foo', 'POST', array(), array(
'do' => 'foo'
)));
Assert::same(array('', 'foo'), $presenter->getSignal());
});

0 comments on commit 1e947c7

Please sign in to comment.