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

Commit

Permalink
TPresenter: add suppor for checkAjaxSignal test method
Browse files Browse the repository at this point in the history
Related PR: #38
  • Loading branch information
mrtnzlml committed Oct 9, 2016
1 parent 93b7680 commit 1723771
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Traits/TPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ protected function checkSignal($destination, $signal, $params = [], $post = [])
] + $params, $post);
}

protected function checkAjaxSignal($destination, $signal, $params = [], $post = [])
{
$this->__testbench_ajaxMode = TRUE;
$response = $this->check($destination, [
'do' => $signal,
] + $params, $post);
Assert::true($this->__testbench_presenter->isAjax());
if (!$this->__testbench_exception) {
Assert::same(200, $this->getReturnCode());
Assert::type('Nette\Application\Responses\JsonResponse', $response);
}
$this->__testbench_ajaxMode = FALSE;
return $response;
}

/**
* @param string $destination fully qualified presenter name (module:module:presenter)
* @param string $path
Expand Down
6 changes: 6 additions & 0 deletions tests/Scaffold/Presenter.expected
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class PresenterPresenterTest extends \Tester\TestCase
}


public function testHandleAjaxSignal()
{
$this->checkSignal('Presenter:', 'ajaxSignal');
}


public function testCreateComponentForm1()
{
$this->checkForm('Presenter:', 'form1', [
Expand Down
7 changes: 7 additions & 0 deletions tests/Traits/TPresenterTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ class TPresenterTest extends \Testbench\CustomPresenterTestCase
$this->checkSignal('Presenter:default', 'signal');
}

public function testAjaxSignal()
{
/** @var \Nette\Application\Responses\JsonResponse $response */
$response = $this->checkAjaxSignal('Presenter:default', 'ajaxSignal');
Assert::same(['ok'], $response->getPayload());
}

public function testFormEnhanced()
{
$this->checkForm('Presenter:default', 'form1', [
Expand Down
5 changes: 5 additions & 0 deletions tests/_helpers/presenters/PresenterPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,9 @@ public function handleSignal()
$this->redirect('this');
}

public function handleAjaxSignal()
{
$this->sendJson(['ok']);
}

}

0 comments on commit 1723771

Please sign in to comment.