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

Testbench\TComponent

Martin Zlámal edited this page Mar 28, 2016 · 3 revisions

Testing UI\Control render

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

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
Clone this wiki locally