class DisplayVariantTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php \Drupal\Tests\Core\Display\DisplayVariantTest
- 8 core/modules/system/src/Tests/Render/DisplayVariantTest.php \Drupal\system\Tests\Render\DisplayVariantTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php \Drupal\Tests\Core\Display\DisplayVariantTest
@coversDefaultClass \Drupal\Core\Display\VariantBase @group Display
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Display\DisplayVariantTest
Expanded class hierarchy of DisplayVariantTest
File
- core/
tests/ Drupal/ Tests/ Core/ Display/ DisplayVariantTest.php, line 17 - Contains \Drupal\Tests\Core\Display\DisplayVariantTest.
Namespace
Drupal\Tests\Core\DisplayView source
class DisplayVariantTest extends UnitTestCase {
/**
* Sets up a display variant plugin for testing.
*
* @param array $configuration
* An array of plugin configuration.
* @param array $definition
* The plugin definition array.
*
* @return \Drupal\Core\Display\VariantBase|\PHPUnit_Framework_MockObject_MockObject
* A mocked display variant plugin.
*/
public function setUpDisplayVariant($configuration = array(), $definition = array()) {
return $this
->getMockBuilder('Drupal\\Core\\Display\\VariantBase')
->setConstructorArgs(array(
$configuration,
'test',
$definition,
))
->setMethods(array(
'build',
))
->getMock();
}
/**
* Tests the label() method.
*
* @covers ::label
*/
public function testLabel() {
$display_variant = $this
->setUpDisplayVariant(array(
'label' => 'foo',
));
$this
->assertSame('foo', $display_variant
->label());
}
/**
* Tests the label() method using a default value.
*
* @covers ::label
*/
public function testLabelDefault() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertSame('', $display_variant
->label());
}
/**
* Tests the getWeight() method.
*
* @covers ::getWeight
*/
public function testGetWeight() {
$display_variant = $this
->setUpDisplayVariant(array(
'weight' => 5,
));
$this
->assertSame(5, $display_variant
->getWeight());
}
/**
* Tests the getWeight() method using a default value.
*
* @covers ::getWeight
*/
public function testGetWeightDefault() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertSame(0, $display_variant
->getWeight());
}
/**
* Tests the getConfiguration() method.
*
* @covers ::getConfiguration
*
* @dataProvider providerTestGetConfiguration
*/
public function testGetConfiguration($configuration, $expected) {
$display_variant = $this
->setUpDisplayVariant($configuration);
$this
->assertSame($expected, $display_variant
->getConfiguration());
}
/**
* Provides test data for testGetConfiguration().
*/
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;
}
/**
* Tests the access() method.
*
* @covers ::access
*/
public function testAccess() {
$display_variant = $this
->setUpDisplayVariant();
$this
->assertTrue($display_variant
->access());
}
/**
* Tests the submitConfigurationForm() method.
*
* @covers ::submitConfigurationForm
*/
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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DisplayVariantTest:: |
public | function | Provides test data for testGetConfiguration(). | |
DisplayVariantTest:: |
public | function | Sets up a display variant plugin for testing. | |
DisplayVariantTest:: |
public | function | Tests the access() method. | |
DisplayVariantTest:: |
public | function | Tests the getConfiguration() method. | |
DisplayVariantTest:: |
public | function | Tests the getWeight() method. | |
DisplayVariantTest:: |
public | function | Tests the getWeight() method using a default value. | |
DisplayVariantTest:: |
public | function | Tests the label() method. | |
DisplayVariantTest:: |
public | function | Tests the label() method using a default value. | |
DisplayVariantTest:: |
public | function | Tests the submitConfigurationForm() method. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |