3 namespace Drupal\Tests\Core\Display;
5 use Drupal\Core\Form\FormState;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Display\VariantBase
12 class DisplayVariantTest extends UnitTestCase {
15 * Sets up a display variant plugin for testing.
17 * @param array $configuration
18 * An array of plugin configuration.
19 * @param array $definition
20 * The plugin definition array.
22 * @return \Drupal\Core\Display\VariantBase|\PHPUnit_Framework_MockObject_MockObject
23 * A mocked display variant plugin.
25 public function setUpDisplayVariant($configuration = [], $definition = []) {
26 return $this->getMockBuilder('Drupal\Core\Display\VariantBase')
27 ->setConstructorArgs([$configuration, 'test', $definition])
28 ->setMethods(['build'])
33 * Tests the label() method.
37 public function testLabel() {
38 $display_variant = $this->setUpDisplayVariant(['label' => 'foo']);
39 $this->assertSame('foo', $display_variant->label());
43 * Tests the label() method using a default value.
47 public function testLabelDefault() {
48 $display_variant = $this->setUpDisplayVariant();
49 $this->assertSame('', $display_variant->label());
53 * Tests the getWeight() method.
57 public function testGetWeight() {
58 $display_variant = $this->setUpDisplayVariant(['weight' => 5]);
59 $this->assertSame(5, $display_variant->getWeight());
63 * Tests the getWeight() method using a default value.
67 public function testGetWeightDefault() {
68 $display_variant = $this->setUpDisplayVariant();
69 $this->assertSame(0, $display_variant->getWeight());
73 * Tests the getConfiguration() method.
75 * @covers ::getConfiguration
77 * @dataProvider providerTestGetConfiguration
79 public function testGetConfiguration($configuration, $expected) {
80 $display_variant = $this->setUpDisplayVariant($configuration);
82 $this->assertSame($expected, $display_variant->getConfiguration());
86 * Provides test data for testGetConfiguration().
88 public function providerTestGetConfiguration() {
121 * Tests the access() method.
125 public function testAccess() {
126 $display_variant = $this->setUpDisplayVariant();
127 $this->assertTrue($display_variant->access());
131 * Tests the submitConfigurationForm() method.
133 * @covers ::submitConfigurationForm
135 public function testSubmitConfigurationForm() {
136 $display_variant = $this->setUpDisplayVariant();
137 $this->assertSame('', $display_variant->label());
140 $label = $this->randomMachineName();
141 $form_state = new FormState();
142 $form_state->setValue('label', $label);
143 $display_variant->submitConfigurationForm($form, $form_state);
144 $this->assertSame($label, $display_variant->label());