-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathFeatureContext.php
More file actions
143 lines (127 loc) · 3.7 KB
/
FeatureContext.php
File metadata and controls
143 lines (127 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
* This file is part of the CCDNUser SecurityBundle
*
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/>
*
* Available on github <http://www.github.com/codeconsortium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CCDNUser\SecurityBundle\features\bootstrap;
use Behat\MinkExtension\Context\RawMinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use CCDNUser\SecurityBundle\features\bootstrap\WebUser;
/**
*
* Features context.
*
* @category CCDNUser
* @package SecurityBundle
*
* @author Reece Fowell <reece@codeconsortium.com>
* @license http://opensource.org/licenses/MIT MIT
* @version Release: 2.0
* @link https://github.com/codeconsortium/CCDNUserSecurityBundle
*
*/
class FeatureContext extends RawMinkContext implements KernelAwareInterface
{
/**
*
* Kernel.
*
* @var KernelInterface
*/
private $kernel;
/**
*
* Parameters.
*
* @var array
*/
private $parameters;
/**
*
* Initializes context.
* Every scenario gets it's own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/
public function __construct(array $parameters)
{
// Initialize your context here
$this->parameters = $parameters;
// Web user context.
$this->useContext('web-user', new WebUser());
}
/**
*
* {@inheritdoc}
*/
public function setKernel(KernelInterface $kernel)
{
$this->kernel = $kernel;
}
/**
*
* @BeforeScenario
*/
public function purgeDatabase()
{
$entityManager = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
$purger = new ORMPurger($entityManager);
$purger->purge();
}
/**
*
* @Given /^I am logged in as "([^"]*)"$/
*/
public function iAmLoggedInAs($user)
{
$session = $this->getMainContext()->getSession();
$session->setBasicAuth($user . '@foo.com', 'root');
}
/**
* @Given /^I logout$/
*/
public function iLogout()
{
$this->kernel->getContainer()->get('security.context')->getToken()->eraseCredentials();
}
/**
* @Given /^I should be logged in$/
*/
public function iShouldBeLoggedIn()
{
WebTestCase::assertTrue($this->kernel->getContainer()->get('security.context')->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\UserInterface);
}
/**
* @Given /^I should not be logged in$/
*/
public function iShouldNotBeLoggedIn()
{
WebTestCase::assertFalse($this->kernel->getContainer()->get('security.context')->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\UserInterface);
}
/**
* @Given /^I circumvent login with "([^"]*)" and "([^"]*)"$/
*/
public function iCircumventLoginWithAnd($username, $password)
{
$this->getMainContext()->getSession()->visit('/circumvent_login');
$this->getMainContext()->getSession()->getPage()->fillField('_username', $username);
$this->getMainContext()->getSession()->getPage()->fillField('_password', $password);
$this->getMainContext()->getSession()->getPage()->pressButton('Login');
}
/**
* @Given /^I should be blocked$/
*/
public function iShouldBeBlocked()
{
WebTestCase::assertSame(429, $this->getMainContext()->getSession()->getStatusCode());
}
}