BakerySiteTestBase.php in Bakery Single Sign-On System 8.2
File
tests/src/Functional/BakerySiteTestBase.php
View source
<?php
namespace Drupal\Tests\bakery\Functional;
use Drupal\bakery\Cookies\CookieInterface;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\BrowserKit\Cookie;
class BakerySiteTestBase extends BrowserTestBase {
protected static $modules = [
'bakery',
];
private $domain;
public function setUp() {
parent::setUp();
$this->domain = preg_replace('/^[^.]+/', '', rtrim($this->baseUrl, '/'));
$this
->config('bakery.settings')
->set('bakery_key', 'asdf')
->set('bakery_domain', $this->domain)
->set('bakery_master', 'https://example.com/')
->save();
}
protected function bakeCookie(CookieInterface $cookie) {
$this
->setCookie($cookie::getName(), $this->container
->get('bakery.kitchen')
->bakeData($cookie));
}
protected function eatCookie(string $name) {
$this
->setCookie($name);
}
protected function assertCookieTastesGood(string $cookie, string $name = NULL) {
$this
->assertTrue((bool) $this->container
->get('bakery.kitchen')
->tasteData($cookie, $name));
}
private function setCookie($name, $value = NULL) {
$jar = $this
->getClient()
->getCookieJar();
if ($value === NULL) {
$jar
->expire($name, '/', $this->domain);
return;
}
$jar
->set(new Cookie($name, $value, NULL, '/', $this->domain));
}
private function getClient() {
return $this
->getSession()
->getDriver()
->getClient();
}
}