This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Testbench\TComponent
Martin Zlámal edited this page Nov 7, 2016
·
3 revisions
It can be useful to check if rendered string (or HTML template) contains what you wanted. It can be achieved like this (using match
method from Nette\Tester)
use \Testbench\TComponent;
public function testComponentRender()
{
$control = new \Component;
$this->checkRenderOutput($control, '<strong>OK%A%'); //match string
$this->checkRenderOutput($control, __DIR__ . '/Component.expected'); //match file content
}
See: https://tester.nette.org/#toc-assert-match
It's also possible to send parameters to the render method via third parameter of checkRenderOutput
like this:
use \Testbench\TComponent;
public function testComponentRender()
{
$control = new \Component;
$this->checkRenderOutput($control, '<strong>OK%A%', ['OK']);
$this->checkRenderOutput($control, __DIR__ . '/Component.expected', [1, '2']);
}
If you only need to attach IComponent
to the presenter you can use attachToPresenter
:
use \Testbench\TComponent;
public function testComponentAttach() {
$control = new \Component;
$this->attachToPresenter($control);
}
Component is by default attached to the Testbench\PresenterMock
. If you want to change this behavior you can set custom presenter mock in config file:
services:
testbench.presenterMock: App\CustomPresenterMock