You are here

class PanelsDisplayVariantTest in Panels 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/PanelsDisplayVariantTest.php \Drupal\Tests\panels\Unit\PanelsDisplayVariantTest

@coversDefaultClass \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant @group Panels

Hierarchy

Expanded class hierarchy of PanelsDisplayVariantTest

File

tests/src/Unit/PanelsDisplayVariantTest.php, line 29
Contains \Drupal\Tests\panels\Unit\PanelsDisplayVariantTest.

Namespace

Drupal\Tests\panels\Unit
View source
class PanelsDisplayVariantTest extends UnitTestCase {

  /**
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $account;

  /**
   * @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
   */
  protected $contextHandler;

  /**
   * @var \Drupal\Component\Uuid\UuidInterface
   */
  protected $uuidGenerator;

  /**
   * @var \Drupal\Core\Utility\Token
   */
  protected $token;

  /**
   * @var \Drupal\Core\Condition\ConditionManager
   */
  protected $conditionManager;

  /**
   * @var \Drupal\Core\Block\BlockManager
   */
  protected $blockManager;

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * @var \Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderManagerInterface
   */
  protected $builderManager;

  /**
   * @var \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface
   */
  protected $layoutManager;

  /**
   * @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface
   */
  protected $layout;

  /**
   * @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant
   */
  protected $variant;
  public function setUp() {
    $this->account = $this
      ->prophesize(AccountInterface::class);
    $this->contextHandler = $this
      ->prophesize(ContextHandlerInterface::class);
    $this->uuidGenerator = $this
      ->prophesize(UuidInterface::class);
    $this->token = $this
      ->prophesize(Token::class);
    $this->blockManager = $this
      ->prophesize(BlockManager::class);
    $this->conditionManager = $this
      ->prophesize(ConditionManager::class);
    $this->moduleHandler = $this
      ->prophesize(ModuleHandlerInterface::class);
    $this->builderManager = $this
      ->prophesize(DisplayBuilderManagerInterface::class);
    $this->layoutManager = $this
      ->prophesize(LayoutPluginManagerInterface::class);
    $this->layout = $this
      ->prophesize(LayoutInterface::class);
    $this->layoutManager
      ->createInstance(Argument::type('string'), Argument::type('array'))
      ->willReturn($this->layout
      ->reveal());
    $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler
      ->reveal(), $this->account
      ->reveal(), $this->uuidGenerator
      ->reveal(), $this->token
      ->reveal(), $this->blockManager
      ->reveal(), $this->conditionManager
      ->reveal(), $this->moduleHandler
      ->reveal(), $this->builderManager
      ->reveal(), $this->layoutManager
      ->reveal());
  }

  /**
   * @covers ::submitConfigurationForm
   */
  public function testSubmitConfigurationForm() {
    $values = [
      'page_title' => "Go hang a salami, I'm a lasagna hog!",
    ];
    $form = [];
    $form_state = (new FormState())
      ->setValues($values);
    $this->variant
      ->submitConfigurationForm($form, $form_state);
    $configuration = $this->variant
      ->getConfiguration();
    $this
      ->assertSame($values['page_title'], $configuration['page_title']);
  }

  /**
   * @covers ::getLayout
   */
  public function testGetLayout() {
    $this
      ->assertSame($this->layout
      ->reveal(), $this->variant
      ->getLayout());
  }

  /**
   * @covers ::getRegionNames
   */
  public function testGetRegionNames() {
    $region_names = [
      'Foo',
      'Bar',
      'Baz',
    ];
    $this->layout
      ->getPluginDefinition()
      ->willReturn([
      'region_names' => $region_names,
    ]);
    $this
      ->assertSame($region_names, $this->variant
      ->getRegionNames());
  }

  /**
   * @covers ::access
   */
  public function testAccessNoBlocksConfigured() {
    $this
      ->assertFalse($this->variant
      ->access());
  }

  /**
   * @covers ::defaultConfiguration
   */
  public function testDefaultConfiguration() {
    $defaults = $this->variant
      ->defaultConfiguration();
    $this
      ->assertSame('', $defaults['layout']);
    $this
      ->assertSame('', $defaults['page_title']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PanelsDisplayVariantTest::$account protected property
PanelsDisplayVariantTest::$blockManager protected property
PanelsDisplayVariantTest::$builderManager protected property
PanelsDisplayVariantTest::$conditionManager protected property
PanelsDisplayVariantTest::$contextHandler protected property
PanelsDisplayVariantTest::$layout protected property
PanelsDisplayVariantTest::$layoutManager protected property
PanelsDisplayVariantTest::$moduleHandler protected property
PanelsDisplayVariantTest::$token protected property
PanelsDisplayVariantTest::$uuidGenerator protected property
PanelsDisplayVariantTest::$variant protected property
PanelsDisplayVariantTest::setUp public function Overrides UnitTestCase::setUp
PanelsDisplayVariantTest::testAccessNoBlocksConfigured public function @covers ::access
PanelsDisplayVariantTest::testDefaultConfiguration public function @covers ::defaultConfiguration
PanelsDisplayVariantTest::testGetLayout public function @covers ::getLayout
PanelsDisplayVariantTest::testGetRegionNames public function @covers ::getRegionNames
PanelsDisplayVariantTest::testSubmitConfigurationForm public function @covers ::submitConfigurationForm
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.