1 | <?php |
||
3 | class UserControllerTest extends AbstractControllerTestCase |
||
4 | { |
||
5 | protected $idUser; |
||
6 | protected $newUserData = [ |
||
7 | 'nickname' => 'new test user', |
||
8 | 'email' => '[email protected]', |
||
9 | 'password' => 'superpassword', |
||
10 | ]; |
||
11 | |||
12 | public function tearDown(): void |
||
20 | } |
||
21 | |||
22 | public function testIndexAction(): void |
||
23 | { |
||
24 | $params = ['action' => 'index', 'controller' => 'user', 'module' => 'default']; |
||
25 | $url = $this->url($this->urlizeOptions($params)); |
||
26 | $this->dispatch($url); |
||
27 | |||
28 | // assertions |
||
29 | $this->assertModule($params['module']); |
||
30 | $this->assertController($params['controller']); |
||
31 | $this->assertAction($params['action']); |
||
32 | |||
33 | $this->assertQueryContentContains('h2', 'Users list'); |
||
34 | } |
||
35 | |||
36 | public function testNewAction(): void |
||
37 | { |
||
38 | // First, query to display form |
||
39 | $params = ['action' => 'new', 'controller' => 'user', 'module' => 'default']; |
||
40 | $url = $this->url($this->urlizeOptions($params)); |
||
41 | $this->dispatch($url); |
||
42 | |||
43 | // assertions |
||
44 | $this->assertModule($params['module']); |
||
45 | $this->assertController($params['controller']); |
||
46 | $this->assertAction($params['action']); |
||
47 | |||
48 | $this->assertQueryContentContains('h2', 'Create new user'); |
||
49 | $this->assertQueryContentContains('form', 'Subscribe'); |
||
50 | |||
51 | // Find out csrf value to be re-used in POST |
||
52 | $captcha = null; |
||
53 | $captchaId = null; |
||
54 | $csrf = null; |
||
55 | foreach ($_SESSION as $key => $q) { |
||
56 | if (preg_match('~^Zend_Form_Captcha_(.*)$~', $key, $m)) { |
||
57 | $captcha = $q['word']; |
||
58 | $captchaId = $m[1]; |
||
59 | } elseif ($key === 'Zend_Form_Element_Hash_salt_csrf') { |
||
60 | $csrf = $q['hash']; |
||
61 | } |
||
62 | } |
||
63 | |||
64 | // Reset everything |
||
65 | $this->resetRequest(); |
||
66 | $this->resetResponse(); |
||
67 | |||
68 | // Prepare POST query |
||
69 | $this->newUserData['captcha'] = [ |
||
70 | 'id' => $captchaId, |
||
71 | 'input' => $captcha, |
||
72 | ]; |
||
73 | $this->newUserData['csrf'] = $csrf; |
||
74 | $this->request->setMethod('POST') |
||
|
|||
75 | ->setPost($this->newUserData); |
||
76 | |||
77 | // Subscribe new test user |
||
78 | $this->dispatch($url); |
||
79 | |||
80 | $this->assertRedirectTo('/movie', 'succesfull subscription redirect to movie list'); |
||
81 | } |
||
82 | |||
83 | public function testLoginAction(): void |
||
115 | } |
||
116 | } |
||
117 |