You are here

CookieTestTrait.php in Bakery Single Sign-On System 8.2

File

tests/src/Traits/CookieTestTrait.php
View source
<?php

namespace Drupal\Tests\bakery\Traits;

use Drupal\bakery\BakeryService;
use Drupal\bakery\Kitchen;
use Drupal\Core\DependencyInjection\Container;
use Prophecy\Argument;
trait CookieTestTrait {

  /**
   * @var string
   */
  protected $cookie;

  /**
   * @var string
   */
  protected $cookieName;
  protected $dataExtra = [];

  /**
   * @var \Drupal\bakery\Kitchen|\Prophecy\Prophecy\ObjectProphecy
   */
  protected $kitchenService;

  /**
   * @var \Drupal\bakery\BakeryService|\Prophecy\Prophecy\ObjectProphecy
   */
  protected $bakeryService;

  /**
   * @covers ::__construct
   * @covers ::toData
   * @covers ::fromData
   * @dataProvider provideTestData
   */
  public function testFromData($data) {
    $this
      ->assertEquals($data + $this->dataExtra, $this->cookie::fromData($data)
      ->toData());
  }
  public abstract function provideTestData();

  /**
   * @covers ::getName
   */
  public function testGetName() {
    $this
      ->assertEquals($this->cookieName, $this->cookie::getName());
  }
  protected function setupBrowserContainer() {
    $container = new Container();
    $this->kitchenService = $this
      ->prophesize(Kitchen::class);
    $this->bakeryService = $this
      ->prophesize(BakeryService::class);
    $this->kitchenService
      ->cookieName(Argument::any())
      ->willReturn($this->cookieName);
    $container
      ->set('bakery.kitchen', $this->kitchenService
      ->reveal());
    $container
      ->set('bakery.bakery_service', $this->bakeryService
      ->reveal());
    \Drupal::setContainer($container);
  }

}

Traits

Namesort descending Description
CookieTestTrait