You are here

public function EntityTest::testCalculateDependencies in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::testCalculateDependencies()

@covers ::calculateDependencies

File

core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php, line 180
Contains \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest.

Class

EntityTest
@coversDefaultClass \Drupal\views\Plugin\views\argument_validator\Entity @group views

Namespace

Drupal\Tests\views\Unit\Plugin\argument_validator

Code

public function testCalculateDependencies() {

  // Create an entity manager, storage, entity type, and entity to mock the
  // loading of entities providing bundles.
  $entityManager = $this
    ->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
  $storage = $this
    ->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $entity_type = $this
    ->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
  $mock_entity = $this
    ->getMock('Drupal\\Core\\Entity\\EntityInterface');
  $mock_entity
    ->expects($this
    ->any())
    ->method('getConfigDependencyKey')
    ->willReturn('config');
  $mock_entity
    ->expects($this
    ->any())
    ->method('getConfigDependencyName')
    ->willReturn('test_bundle');
  $storage
    ->expects($this
    ->any())
    ->method('loadMultiple')
    ->with([
    'test_bundle',
  ])
    ->willReturn([
    'test_bundle' => $mock_entity,
  ]);
  $entity_type
    ->expects($this
    ->any())
    ->method('getBundleEntityType')
    ->willReturn('entity_test_bundle');
  $entityManager
    ->expects($this
    ->any())
    ->method('getDefinition')
    ->with('entity_test')
    ->willReturn($entity_type);
  $entityManager
    ->expects($this
    ->any())
    ->method('hasHandler')
    ->with('entity_test_bundle', 'storage')
    ->willReturn(TRUE);
  $entityManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('entity_test_bundle')
    ->willReturn($storage);

  // Set up the argument validator.
  $argumentValidator = new Entity(array(), 'entity_test', [
    'entity_type' => 'entity_test',
  ], $entityManager);
  $options = array();
  $options['access'] = FALSE;
  $options['bundles'] = array(
    'test_bundle' => 1,
  );
  $argumentValidator
    ->init($this->executable, $this->display, $options);
  $this
    ->assertEquals([
    'config' => [
      'test_bundle',
    ],
  ], $argumentValidator
    ->calculateDependencies());
}