View source
<?php
namespace Drupal\Tests\Core\Display;
use Drupal\Core\Form\FormState;
use Drupal\Tests\UnitTestCase;
class DisplayVariantTest extends UnitTestCase {
public function setUpDisplayVariant($configuration = array(), $definition = array()) {
return $this
->getMockBuilder('Drupal\\Core\\Display\\VariantBase')
->setConstructorArgs(array(
$configuration,
'test',
$definition,
))
->setMethods(array(
'build',
))
->getMock();
}
public function testLabel() {
$display_variant = $this
->setUpDisplayVariant(array(
'label' => 'foo',
));
$this
->assertSame('foo', $display_variant
->label());
}
public function testLabelDefault() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertSame('', $display_variant
->label());
}
public function testGetWeight() {
$display_variant = $this
->setUpDisplayVariant(array(
'weight' => 5,
));
$this
->assertSame(5, $display_variant
->getWeight());
}
public function testGetWeightDefault() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertSame(0, $display_variant
->getWeight());
}
public function testGetConfiguration($configuration, $expected) {
$display_variant = $this
->setUpDisplayVariant($configuration);
$this
->assertSame($expected, $display_variant
->getConfiguration());
}
public function providerTestGetConfiguration() {
$data = array();
$data[] = array(
array(),
array(
'id' => 'test',
'label' => '',
'uuid' => '',
'weight' => 0,
),
);
$data[] = array(
array(
'label' => 'Test',
),
array(
'id' => 'test',
'label' => 'Test',
'uuid' => '',
'weight' => 0,
),
);
$data[] = array(
array(
'id' => 'foo',
),
array(
'id' => 'test',
'label' => '',
'uuid' => '',
'weight' => 0,
),
);
return $data;
}
public function testAccess() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertTrue($display_variant
->access());
}
public function testSubmitConfigurationForm() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertSame('', $display_variant
->label());
$form = array();
$label = $this
->randomMachineName();
$form_state = new FormState();
$form_state
->setValue('label', $label);
$display_variant
->submitConfigurationForm($form, $form_state);
$this
->assertSame($label, $display_variant
->label());
}
}