class CookieMonsterTest in Bakery Single Sign-On System 8.2
@coversDefaultClass \Drupal\bakery\EventSubscriber\CookieMonster
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\bakery\Unit\EventSubscriber\CookieMonsterTest
Expanded class hierarchy of CookieMonsterTest
File
- tests/
src/ Unit/ EventSubscriber/ CookieMonsterTest.php, line 24
Namespace
Drupal\Tests\bakery\Unit\EventSubscriberView source
class CookieMonsterTest extends UnitTestCase {
/**
* @var \Drupal\bakery\EventSubscriber\CookieMonster
*/
private $sot;
/**
* @var \Symfony\Component\HttpFoundation\ParameterBag
*/
private $cookieJar;
/**
* @var \Drupal\Core\Http\RequestStack
*/
private $request;
/**
* @var \Drupal\Component\Datetime\Time
*/
private $time;
public function setUp() {
parent::setUp();
$this->request = new RequestStack();
$this->request
->push(new Request());
$this->time = new Time($this->request);
$config = new Config('config.test', new MemoryStorage(), new EventDispatcher(), $this
->prophesize(TypedConfigManagerInterface::class)
->reveal());
$config
->set('bakery_domain', '.example.com');
$config
->set('bakery_freshness', 3600);
$cf = $this
->prophesize(ConfigFactoryInterface::class);
$cf
->get('bakery.settings')
->willReturn($config);
$this->cookieJar = new ParameterBag();
$this->sot = new CookieMonster($this->time, $cf
->reveal(), $this->cookieJar);
}
/**
* @covers ::meWantCookie
*/
public function testFoo() {
$response = new Response();
$event = new ResponseEvent($this
->prophesize(HttpKernelInterface::class)
->reveal(), $this->request
->getCurrentRequest(), HttpKernelInterface::MASTER_REQUEST, $response);
$this->sot
->meWantCookie($event);
$this
->assertCount(0, $response->headers
->getCookies());
$this->cookieJar
->set('cookie1', 'foo');
$this->cookieJar
->set('cookie2', 'bar');
$this->cookieJar
->set('cookie3', '');
$this->sot
->meWantCookie($event);
$this
->assertCount(4, $response->headers
->getCookies());
$expire = $this->time
->getRequestTime() + 3600;
$secure = !empty(ini_get('session.cookie_secure'));
$this
->assertEquals([
Cookie::create('cookie1', 'foo', $expire, '/', '.example.com', $secure),
Cookie::create('cookie2', 'bar', $expire, '/', '.example.com', $secure),
// This might cause problems with Symfony 5?
new Cookie('cookie3', NULL, 1, '/', '.example.com', $secure, TRUE, FALSE, NULL),
new Cookie('cookie3', NULL, 1, '/', '', $secure, TRUE, FALSE, NULL),
], $response->headers
->getCookies());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CookieMonsterTest:: |
private | property | ||
CookieMonsterTest:: |
private | property | ||
CookieMonsterTest:: |
private | property | ||
CookieMonsterTest:: |
private | property | ||
CookieMonsterTest:: |
public | function |
Overrides UnitTestCase:: |
|
CookieMonsterTest:: |
public | function | @covers ::meWantCookie | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |