Testovani presenteru – odeslani emailu s sablonou
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- riski
- Člen | 53
Zdravim, s testy teprve zacinam a snazim se otestovat presenter v nem odeslani formulare, ktery nasledne odesle email (zapomenute heslo). Vse funguje jak ma do doby kdy vkladam do emailu sablonu:
clone $this->application->presenter->template;
nette tester vypise:
E_NOTICE: Trying to get property of non-object
protoze uz $this->application->presenter vraci NULL. Ptam se proc popripade jak to opravit, kdyz z fontendu odesilani funguje. Pokud je treba napsat nejaky kod neni problem.
Predem dekuji
- riski
- Člen | 53
samotny test vypada takto
public function testSendPassword()
{
$request = array(
'action' => 'registration',
'do' => 'loginForm-submit',
'email' => 'email@email.cz',
'noPassword' => TRUE,
'recover' => 'Obnovit'
);
$this->initPresenter('Front:Auth');
$response = $this->getResponse('POST', $request, $request);
Assert::type('Nette\Application\Responses\RedirectResponse', $response);
}
protected function initPresenter($presenterName)
{
$this->presenterName = $presenterName;
$this->presenter = $this->presenterFactory->createPresenter($this->presenterName);
$this->presenter->autoCanonicalize = FALSE;
}
protected function getResponse($method = 'GET', $params = [], $post = [])
{
return $this->presenter->run(new Request(
$this->presenterName, $method, $params, $post
));
}
- David Matějka
- Moderator | 6445
Bude lepsi tu sablonu vytvaret nasledovne: https://phpfashion.com/…-a-nette-2-3