class ContextTypedDataTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Plugin/Context/ContextTypedDataTest.php \Drupal\Tests\Core\Plugin\Context\ContextTypedDataTest
Tests that contexts work properly with the typed data manager.
@coversDefaultClass \Drupal\Core\Plugin\Context\Context @group Context
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Plugin\Context\ContextTypedDataTest
Expanded class hierarchy of ContextTypedDataTest
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ Context/ ContextTypedDataTest.php, line 23 - Contains \Drupal\Tests\Core\Plugin\Context\ContextTypedDataTest.
Namespace
Drupal\Tests\Core\Plugin\ContextView source
class ContextTypedDataTest extends UnitTestCase {
/**
* The typed data object used during testing.
*
* @var \Drupal\Core\TypedData\Plugin\DataType\StringData
*/
protected $typedData;
/**
* Tests that getting a context value does not throw fatal errors.
*
* This test ensures that the typed data manager is set correctly on the
* Context class.
*
* @covers ::getContextValue
*/
public function testGetContextValue() {
// Prepare a container that holds the typed data manager mock.
$typed_data_manager = $this
->getMockBuilder('Drupal\\Core\\TypedData\\TypedDataManager')
->disableOriginalConstructor()
->getMock();
$typed_data_manager
->expects($this
->once())
->method('getCanonicalRepresentation')
->will($this
->returnCallback(array(
$this,
'getCanonicalRepresentation',
)));
$container = new ContainerBuilder();
$container
->set('typed_data_manager', $typed_data_manager);
\Drupal::setContainer($container);
$definition = new ContextDefinition('any');
$data_definition = DataDefinition::create('string');
$this->typedData = new StringData($data_definition);
$this->typedData
->setValue('example string');
$context = new Context($definition, $this->typedData);
$value = $context
->getContextValue();
$this
->assertSame($value, $this->typedData
->getValue());
}
/**
* Helper mock callback to return the typed data value.
*/
public function getCanonicalRepresentation() {
return $this->typedData
->getValue();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextTypedDataTest:: |
protected | property | The typed data object used during testing. | |
ContextTypedDataTest:: |
public | function | Helper mock callback to return the typed data value. | |
ContextTypedDataTest:: |
public | function | Tests that getting a context value does not throw fatal errors. | |
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 |