public function MainSitePagesTest::testCreate in Bakery Single Sign-On System 8.2
File
- tests/
src/ Functional/ MainSitePagesTest.php, line 13
Class
Namespace
Drupal\Tests\bakery\FunctionalCode
public function testCreate() {
$account = $this
->createUser();
$client = $this
->getHttpClient();
/** @var \Drupal\bakery\Kitchen $kitchen */
$kitchen = $this->container
->get('bakery.kitchen');
$options = [
'http_errors' => FALSE,
];
$cookie = new Gingerbread($account
->getAccountName(), 0, 'child.example.com', '123');
$url = Url::fromRoute('bakery.create')
->setAbsolute(TRUE)
->toString();
$response = $client
->request('GET', $url, $options);
$this
->assertEquals(403, $response
->getStatusCode(), 'Access denied without cookie.');
$response = $client
->request('POST', $url, $options + [
'form_params' => [
$cookie::getName() => 'bad' . $kitchen
->bakeData($cookie),
],
]);
$this
->assertEquals(403, $response
->getStatusCode(), 'Access denied bad cookie.');
$response = $client
->request('POST', $url, $options + [
'form_params' => [
$cookie::getName() => $kitchen
->bakeData($cookie),
],
]);
$this
->assertEquals(200, $response
->getStatusCode(), 'Cookie posted successfully.');
// TODO test child user map.
$data = (string) $response
->getBody();
$tmp = $kitchen
->tasteData($data, 'gingerbread');
$this
->assertEquals($account
->getAccountName(), $tmp['name']);
$this
->assertEquals($account
->getEmail(), $tmp['mail']);
$this
->assertEquals($account
->id(), $tmp['uid']);
$this
->assertEquals('gingerbread', $tmp['type']);
$cookie = new Gingerbread($account
->getEmail(), 0, 'child.example.com', '123');
$response = $client
->request('POST', $url, $options + [
'form_params' => [
$cookie::getName() => $kitchen
->bakeData($cookie),
],
]);
$this
->assertEquals(Response::HTTP_CONFLICT, $response
->getStatusCode());
$cookie = new Gingerbread($account
->getEmail(), 1, 'child.example.com', '123');
$response = $client
->request('POST', $url, $options + [
'form_params' => [
$cookie::getName() => $kitchen
->bakeData($cookie),
],
]);
$this
->assertEquals(200, $response
->getStatusCode(), 'Cookie posted successfully.');
// TODO test child user map. some more? No dupes or any weirdness.
}