public function ContextDefinitionTest::testGetDataDefinition in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php \Drupal\Tests\Core\Plugin\Context\ContextDefinitionTest::testGetDataDefinition()
@dataProvider providerGetDataDefinition @covers ::getDataDefinition @uses \Drupal
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ Context/ ContextDefinitionTest.php, line 37 - Contains \Drupal\Tests\Core\Plugin\Context\ContextDefinitionTest.
Class
- ContextDefinitionTest
- Tests the ContextDefinition class.
Namespace
Drupal\Tests\Core\Plugin\ContextCode
public function testGetDataDefinition($is_multiple) {
$data_type = 'valid';
$mock_data_definition = $this
->getMockBuilder('\\Drupal\\Core\\TypedData\\ListDataDefinitionInterface')
->setMethods(array(
'setLabel',
'setDescription',
'setRequired',
'getConstraints',
'setConstraints',
))
->getMockForAbstractClass();
$mock_data_definition
->expects($this
->once())
->method('setLabel')
->willReturnSelf();
$mock_data_definition
->expects($this
->once())
->method('setDescription')
->willReturnSelf();
$mock_data_definition
->expects($this
->once())
->method('setRequired')
->willReturnSelf();
$mock_data_definition
->expects($this
->once())
->method('getConstraints')
->willReturn(array());
$mock_data_definition
->expects($this
->once())
->method('setConstraints')
->willReturn(NULL);
// Follow code paths for both multiple and non-multiple definitions.
$create_definition_method = 'createDataDefinition';
if ($is_multiple) {
$create_definition_method = 'createListDataDefinition';
}
$mock_data_manager = $this
->getMockBuilder('\\Drupal\\Core\\TypedData\\TypedDataManager')
->disableOriginalConstructor()
->setMethods(array(
$create_definition_method,
))
->getMock();
// Our mocked data manager will return our mocked data definition for a
// valid data type.
$mock_data_manager
->expects($this
->once())
->method($create_definition_method)
->willReturnMap(array(
array(
'not_valid',
NULL,
),
array(
'valid',
$mock_data_definition,
),
));
// Mock a ContextDefinition object, setting up expectations for many of the
// methods.
$mock_context_definition = $this
->getMockBuilder('Drupal\\Core\\Plugin\\Context\\ContextDefinition')
->disableOriginalConstructor()
->setMethods(array(
'isMultiple',
'getTypedDataManager',
'getDataType',
'getLabel',
'getDescription',
'isRequired',
'getConstraints',
'setConstraints',
))
->getMock();
$mock_context_definition
->expects($this
->once())
->method('isMultiple')
->willReturn($is_multiple);
$mock_context_definition
->expects($this
->once())
->method('getTypedDataManager')
->willReturn($mock_data_manager);
$mock_context_definition
->expects($this
->once())
->method('getDataType')
->willReturn($data_type);
$mock_context_definition
->expects($this
->once())
->method('getConstraints')
->willReturn(array());
$this
->assertSame($mock_data_definition, $mock_context_definition
->getDataDefinition());
}