You are here

class OatmealCookieTest in Bakery Single Sign-On System 8.2

@coversDefaultClass \Drupal\bakery\Cookies\OatmealCookie

Hierarchy

Expanded class hierarchy of OatmealCookieTest

File

tests/src/Unit/Cookies/OatmealCookieTest.php, line 12

Namespace

Drupal\Tests\bakery\Unit\Cookies
View source
class OatmealCookieTest extends UnitTestCase {
  use CookieTestTrait {
    testFromData as traitFromDataTest;
    testGetName as traitGetNameTest;
  }
  public function setUp() {
    parent::setUp();
    $this->cookie = OatmealCookie::class;
    $this->cookieName = 'OATMEALCOOKIE';
    $this->dataExtra = [
      'calories' => 320,
    ];
    $this
      ->setupBrowserContainer();
  }
  public function provideTestData() {
    return [
      'main' => [
        [
          'name' => 'testuser1',
          'data' => 'asdfasdfasdfa',
          'master' => 1,
        ],
      ],
      'child' => [
        [
          'name' => 'testuser1',
          'data' => 'asdfasdfasdfa',
          'master' => 0,
        ],
      ],
    ];
  }

  /**
   * @covers ::__construct
   * @covers ::toData
   * @covers ::fromData
   * @dataProvider provideTestData
   */
  public function testFromData($data) {

    // Mock reasonable function calls based on if cookie is from main site or child.
    if ($data['master']) {
      $this->bakeryService
        ->isMain()
        ->willReturn(1);
      $this->bakeryService
        ->isChild()
        ->willReturn(0);
    }
    else {
      $this->bakeryService
        ->isMain()
        ->willReturn(0);
      $this->bakeryService
        ->isChild()
        ->willReturn(1);

      // If on child, the slave property needs to be populated.
      $this->dataExtra += [
        'slave' => '/',
      ];
    }
    $this
      ->traitFromDataTest($data);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CookieTestTrait::$bakeryService protected property
CookieTestTrait::$cookie protected property
CookieTestTrait::$cookieName protected property
CookieTestTrait::$dataExtra protected property
CookieTestTrait::$kitchenService protected property
CookieTestTrait::setupBrowserContainer protected function
CookieTestTrait::testFromData public function @covers ::__construct @covers ::toData @covers ::fromData @dataProvider provideTestData Aliased as: traitFromDataTest
CookieTestTrait::testGetName public function @covers ::getName Aliased as: traitGetNameTest
OatmealCookieTest::provideTestData public function Overrides CookieTestTrait::provideTestData
OatmealCookieTest::setUp public function Overrides UnitTestCase::setUp
OatmealCookieTest::testFromData public function @covers ::__construct @covers ::toData @covers ::fromData @dataProvider provideTestData
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.