@@ 50-82 (lines=33) @@ | ||
47 | * |
|
48 | * @return Crawler $crawler of the page of the url or the page after the login |
|
49 | */ |
|
50 | private function loginUserIfRequired(Client $client, $url, $username = 'dominik', $password = 'lkjlkjlkjlkj') |
|
51 | { |
|
52 | // try to get the url |
|
53 | $client->followRedirects(); |
|
54 | $crawler = $client->request('GET', $url); |
|
55 | ||
56 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Status-Code 200 expected.'); |
|
57 | ||
58 | // if redirected to a login-page, login as admin-user |
|
59 | if (5 == $crawler->filter('input')->count() && 1 == $crawler->filter('#username')->count() && 1 == $crawler->filter('#password')->count()) { |
|
60 | // set the password of the admin |
|
61 | $userProvider = $this->getContainer()->get('fos_user.user_provider.username_email'); |
|
62 | $user = $userProvider->loadUserByUsername($username); |
|
63 | $user->setPlainPassword($password); |
|
64 | $user->addRole('ROLE_ADMIN'); |
|
65 | ||
66 | $userManager = $this->getContainer()->get('fos_user.user_manager'); |
|
67 | $userManager->updateUser($user); |
|
68 | ||
69 | $crawler = $crawler->filter("input[type='submit']"); |
|
70 | $form = $crawler->form(); |
|
71 | $form->get('_username')->setValue($username); |
|
72 | $form->get('_password')->setValue($password); |
|
73 | $crawler = $client->submit($form); |
|
74 | } |
|
75 | ||
76 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Login failed.'); |
|
77 | $client->followRedirects(false); |
|
78 | ||
79 | $this->assertStringEndsWith($url, $client->getRequest()->getUri(), "Login failed or not redirected to requested url: $url vs. ".$client->getRequest()->getUri()); |
|
80 | ||
81 | return $crawler; |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * @var ContainerInterface |
@@ 221-253 (lines=33) @@ | ||
218 | * |
|
219 | * @return Crawler $crawler of the page of the url or the page after the login |
|
220 | */ |
|
221 | private function loginUserIfRequired(Client $client, $url, $username = 'dominik', $password = 'lkjlkjlkjlkj') |
|
222 | { |
|
223 | // try to get the url |
|
224 | $client->followRedirects(); |
|
225 | $crawler = $client->request('GET', $url); |
|
226 | ||
227 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Status-Code 200 expected.'); |
|
228 | ||
229 | // if redirected to a login-page, login as admin-user |
|
230 | if (5 == $crawler->filter('input')->count() && 1 == $crawler->filter('#username')->count() && 1 == $crawler->filter('#password')->count()) { |
|
231 | // set the password of the admin |
|
232 | $userProvider = $this->getContainer()->get('fos_user.user_provider.username_email'); |
|
233 | $user = $userProvider->loadUserByUsername($username); |
|
234 | $user->setPlainPassword($password); |
|
235 | $user->addRole('ROLE_ADMIN'); |
|
236 | ||
237 | $userManager = $this->getContainer()->get('fos_user.user_manager'); |
|
238 | $userManager->updateUser($user); |
|
239 | ||
240 | $crawler = $crawler->filter("input[type='submit']"); |
|
241 | $form = $crawler->form(); |
|
242 | $form->get('_username')->setValue($username); |
|
243 | $form->get('_password')->setValue($password); |
|
244 | $crawler = $client->submit($form); |
|
245 | } |
|
246 | ||
247 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Login failed.'); |
|
248 | $client->followRedirects(false); |
|
249 | ||
250 | $this->assertStringEndsWith($url, $client->getRequest()->getUri(), "Login failed or not redirected to requested url: $url vs. ".$client->getRequest()->getUri()); |
|
251 | ||
252 | return $crawler; |
|
253 | } |
|
254 | ||
255 | /** |
|
256 | * @var ContainerInterface |