class RdfMappingConfigEntityUnitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php \Drupal\Tests\rdf\Unit\RdfMappingConfigEntityUnitTest
@coversDefaultClass \Drupal\rdf\Entity\RdfMapping @group rdf
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\rdf\Unit\RdfMappingConfigEntityUnitTest
Expanded class hierarchy of RdfMappingConfigEntityUnitTest
File
- core/
modules/ rdf/ tests/ src/ Unit/ RdfMappingConfigEntityUnitTest.php, line 18 - Contains \Drupal\Tests\rdf\Unit\RdfMappingConfigEntityUnitTest.
Namespace
Drupal\Tests\rdf\UnitView source
class RdfMappingConfigEntityUnitTest extends UnitTestCase {
/**
* The entity type used for testing.
*
* @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityType;
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The ID of the type of the entity under test.
*
* @var string
*/
protected $entityTypeId;
/**
* The UUID generator used for testing.
*
* @var \Drupal\Component\Uuid\UuidInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $uuid;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityTypeId = $this
->randomMachineName();
$this->entityType = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$this->entityType
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('entity'));
$this->entityManager = $this
->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->uuid = $this
->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$container = new ContainerBuilder();
$container
->set('entity.manager', $this->entityManager);
$container
->set('uuid', $this->uuid);
\Drupal::setContainer($container);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$target_entity_type_id = $this
->randomMachineName(16);
$target_entity_type = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$target_entity_type
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('test_module'));
$values = array(
'targetEntityType' => $target_entity_type_id,
);
$target_entity_type
->expects($this
->any())
->method('getBundleEntityType')
->will($this
->returnValue(NULL));
$this->entityManager
->expects($this
->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this
->returnValue($target_entity_type));
$this->entityManager
->expects($this
->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$entity = new RdfMapping($values, $this->entityTypeId);
$dependencies = $entity
->calculateDependencies()
->getDependencies();
$this
->assertArrayNotHasKey('config', $dependencies);
$this
->assertContains('test_module', $dependencies['module']);
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependenciesWithEntityBundle() {
$target_entity_type_id = $this
->randomMachineName(16);
$target_entity_type = $this
->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
$target_entity_type
->expects($this
->any())
->method('getProvider')
->will($this
->returnValue('test_module'));
$bundle_id = $this
->randomMachineName(10);
$values = array(
'targetEntityType' => $target_entity_type_id,
'bundle' => $bundle_id,
);
$target_entity_type
->expects($this
->any())
->method('getBundleConfigDependency')
->will($this
->returnValue(array(
'type' => 'config',
'name' => 'test_module.type.' . $bundle_id,
)));
$this->entityManager
->expects($this
->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this
->returnValue($target_entity_type));
$this->entityManager
->expects($this
->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this
->returnValue($this->entityType));
$entity = new RdfMapping($values, $this->entityTypeId);
$dependencies = $entity
->calculateDependencies()
->getDependencies();
$this
->assertContains('test_module.type.' . $bundle_id, $dependencies['config']);
$this
->assertContains('test_module', $dependencies['module']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RdfMappingConfigEntityUnitTest:: |
protected | property | The entity manager used for testing. | |
RdfMappingConfigEntityUnitTest:: |
protected | property | The entity type used for testing. | |
RdfMappingConfigEntityUnitTest:: |
protected | property | The ID of the type of the entity under test. | |
RdfMappingConfigEntityUnitTest:: |
protected | property | The UUID generator used for testing. | |
RdfMappingConfigEntityUnitTest:: |
protected | function |
Overrides UnitTestCase:: |
|
RdfMappingConfigEntityUnitTest:: |
public | function | @covers ::calculateDependencies | |
RdfMappingConfigEntityUnitTest:: |
public | function | @covers ::calculateDependencies | |
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. |