You are here

ChocolateChipTest.php in Bakery Single Sign-On System 8.2

File

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

namespace Drupal\Tests\bakery\Unit\Cookies;

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

/**
 * @coversDefaultClass \Drupal\bakery\Cookies\ChocolateChip
 */
class ChocolateChipTest extends UnitTestCase {
  use CookieTestTrait {
    testFromData as traitFromDataTest;
    testGetName as traitGetNameTest;
  }
  public function setUp() {
    parent::setUp();
    $this->cookie = ChocolateChip::class;
    $this->cookieName = 'CHOCOLATECHIP';
    $this->dataExtra = [
      'calories' => 480,
    ];
    $this
      ->setupBrowserContainer();
  }
  public function provideTestData() {
    return [
      'basic' => [
        [
          'name' => 'testuser1',
          'mail' => 'asdfasdfasdfa',
          'init' => 'foobar',
        ],
      ],
    ];
  }

  /**
   * @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.
    $this->bakeryService
      ->isMain()
      ->willReturn(1, 0);
    $this->bakeryService
      ->isChild()
      ->willReturn(0, 1);
    $this->dataExtra['master'] = 1;
    $this
      ->traitFromDataTest($data);
    $this->dataExtra['master'] = 0;
    $this
      ->traitFromDataTest($data);
  }

}

Classes