You are here

OatmealCookieTest.php in Bakery Single Sign-On System 8.2

File

tests/src/Unit/Cookies/OatmealCookieTest.php
View source
<?php

namespace Drupal\Tests\bakery\Unit\Cookies;

use Drupal\bakery\Cookies\OatmealCookie;
use Drupal\Tests\bakery\Traits\CookieTestTrait;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\bakery\Cookies\OatmealCookie
 */
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);
  }

}

Classes