1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenOrchestra\FunctionalTests\BackOfficeBundle\Security; |
4
|
|
|
|
5
|
|
|
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractWebTestCase; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Client; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class FormLoginTest |
10
|
|
|
*/ |
11
|
|
|
class FormLoginTest extends AbstractWebTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Client |
15
|
|
|
*/ |
16
|
|
|
protected $client; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Set up the test |
20
|
|
|
*/ |
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->client = static::createClient(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Test form login with valid user |
28
|
|
|
*/ |
29
|
|
|
public function testLoginWithValidUser() |
30
|
|
|
{ |
31
|
|
|
$userName = 'p-admin'; |
32
|
|
|
$password = 'p-admin'; |
33
|
|
|
$crawler = $this->client->request('GET', '/login'); |
34
|
|
|
|
35
|
|
|
$form = $crawler->selectButton('Log in')->form(); |
36
|
|
|
$form['_username'] = $userName; |
37
|
|
|
$form['_password'] = $password; |
38
|
|
|
$this->client->submit($form); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->assertEquals(302, $this->client->getResponse()->getStatusCode()); |
41
|
|
|
$user = $this->client->getContainer()->get('security.token_storage')->getToken()->getUser(); |
42
|
|
|
$this->assertInstanceOf('OpenOrchestra\UserBundle\Model\UserInterface', $user); |
43
|
|
|
$this->assertEquals($user->getUserName(), $userName); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test form login with invalid user |
48
|
|
|
*/ |
49
|
|
|
public function testLoginWithInvalidUser() |
50
|
|
|
{ |
51
|
|
|
$userName = 'invalidUserName'; |
52
|
|
|
$password = 'invalidUserName'; |
53
|
|
|
$crawler = $this->client->request('GET', '/login'); |
54
|
|
|
|
55
|
|
|
$form = $crawler->selectButton('Log in')->form(); |
56
|
|
|
$form['_username'] = $userName; |
57
|
|
|
$form['_password'] = $password; |
58
|
|
|
$this->client->submit($form); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->assertEquals(302, $this->client->getResponse()->getStatusCode()); |
61
|
|
|
$token = $this->client->getContainer()->get('security.token_storage')->getToken(); |
62
|
|
|
$this->assertNull($token); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: