class RdfMappingConfigEntityUnitTest

Same name and namespace in other branches
  1. 8.9.x core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php \Drupal\Tests\rdf\Unit\RdfMappingConfigEntityUnitTest

@coversDefaultClass \Drupal\rdf\Entity\RdfMapping
@group rdf @group legacy

Hierarchy

Expanded class hierarchy of RdfMappingConfigEntityUnitTest

File

core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php, line 15

Namespace

Drupal\Tests\rdf\Unit
View source
class RdfMappingConfigEntityUnitTest extends UnitTestCase {
  
  /**
   * The entity type used for testing.
   *
   * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityType;
  
  /**
   * The entity type manager used for testing.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityTypeManager;
  
  /**
   * 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() : void {
    $this->entityTypeId = $this->randomMachineName();
    $this->entityType = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $this->entityType
      ->expects($this->any())
      ->method('getProvider')
      ->willReturn('entity');
    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $this->uuid = $this->createMock('\\Drupal\\Component\\Uuid\\UuidInterface');
    $container = new ContainerBuilder();
    $container->set('entity_type.manager', $this->entityTypeManager);
    $container->set('uuid', $this->uuid);
    \Drupal::setContainer($container);
  }
  
  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependencies() {
    $target_entity_type_id = $this->randomMachineName(16);
    $target_entity_type = $this->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $target_entity_type->expects($this->any())
      ->method('getProvider')
      ->willReturn('test_module');
    $values = [
      'targetEntityType' => $target_entity_type_id,
    ];
    $target_entity_type->expects($this->any())
      ->method('getBundleEntityType')
      ->willReturn(NULL);
    $target_entity_type->expects($this->any())
      ->method('getBundleConfigDependency')
      ->willReturn([
      'type' => 'module',
      'name' => 'test_module',
    ]);
    $this->entityTypeManager
      ->expects($this->any())
      ->method('getDefinition')
      ->willReturnMap([
      [
        $target_entity_type_id,
        TRUE,
        $target_entity_type,
      ],
      [
        $this->entityTypeId,
        TRUE,
        $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->createMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
    $target_entity_type->expects($this->any())
      ->method('getProvider')
      ->willReturn('test_module');
    $bundle_id = $this->randomMachineName(10);
    $values = [
      'targetEntityType' => $target_entity_type_id,
      'bundle' => $bundle_id,
    ];
    $target_entity_type->expects($this->any())
      ->method('getBundleConfigDependency')
      ->willReturn([
      'type' => 'config',
      'name' => 'test_module.type.' . $bundle_id,
    ]);
    $this->entityTypeManager
      ->expects($this->any())
      ->method('getDefinition')
      ->willReturnMap([
      [
        $target_entity_type_id,
        TRUE,
        $target_entity_type,
      ],
      [
        $this->entityTypeId,
        TRUE,
        $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

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RdfMappingConfigEntityUnitTest::$entityType protected property The entity type used for testing.
RdfMappingConfigEntityUnitTest::$entityTypeId protected property The ID of the type of the entity under test.
RdfMappingConfigEntityUnitTest::$entityTypeManager protected property The entity type manager used for testing.
RdfMappingConfigEntityUnitTest::$uuid protected property The UUID generator used for testing.
RdfMappingConfigEntityUnitTest::setUp protected function Overrides UnitTestCase::setUp
RdfMappingConfigEntityUnitTest::testCalculateDependencies public function @covers ::calculateDependencies[[api-linebreak]]
RdfMappingConfigEntityUnitTest::testCalculateDependenciesWithEntityBundle public function @covers ::calculateDependencies[[api-linebreak]]
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.