function EntityTest::setUp

Same name in this branch
  1. main core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()
Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  2. 11.x core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()
  3. 10 core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  4. 10 core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()
  5. 9 core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  6. 9 core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()
  7. 8.9.x core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  8. 8.9.x core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php, line 63

Class

EntityTest
Tests Drupal\views\Plugin\views\argument_validator\Entity.

Namespace

Drupal\Tests\views\Unit\Plugin\argument_validator

Code

protected function setUp() : void {
  parent::setUp();
  $this->entityTypeManager = $this->createStub(EntityTypeManagerInterface::class);
  $this->entityTypeBundleInfo = $this->createStub(EntityTypeBundleInfoInterface::class);
  $mock_entity = $this->createStub(StubEntityBase::class);
  $mock_entity->method('bundle')
    ->willReturn('test_bundle');
  $mock_entity->method('access')
    ->willReturnMap([
    [
      'test_op',
      NULL,
      FALSE,
      TRUE,
    ],
    [
      'test_op_2',
      NULL,
      FALSE,
      FALSE,
    ],
    [
      'test_op_3',
      NULL,
      FALSE,
      TRUE,
    ],
  ]);
  $mock_entity_bundle_2 = $this->createStub(StubEntityBase::class);
  $mock_entity_bundle_2->method('bundle')
    ->willReturn('test_bundle_2');
  $mock_entity_bundle_2->method('access')
    ->willReturnMap([
    [
      'test_op',
      NULL,
      FALSE,
      FALSE,
    ],
    [
      'test_op_2',
      NULL,
      FALSE,
      FALSE,
    ],
    [
      'test_op_3',
      NULL,
      FALSE,
      TRUE,
    ],
  ]);
  $storage = $this->createStub(EntityStorageInterface::class);
  // Setup values for IDs passed as strings or numbers.
  $value_map = [
    [
      [],
      [],
    ],
    [
      [
        1,
      ],
      [
        1 => $mock_entity,
      ],
    ],
    [
      [
        '1',
      ],
      [
        1 => $mock_entity,
      ],
    ],
    [
      [
        1,
        2,
      ],
      [
        1 => $mock_entity,
        2 => $mock_entity_bundle_2,
      ],
    ],
    [
      [
        '1',
        '2',
      ],
      [
        1 => $mock_entity,
        2 => $mock_entity_bundle_2,
      ],
    ],
    [
      [
        2,
      ],
      [
        2 => $mock_entity_bundle_2,
      ],
    ],
    [
      [
        '2',
      ],
      [
        2 => $mock_entity_bundle_2,
      ],
    ],
  ];
  $storage->method('loadMultiple')
    ->willReturnMap($value_map);
  $this->entityTypeManager
    ->method('getStorage')
    ->willReturn($storage);
  $this->executable = $this->createStub(ViewExecutable::class);
  $this->display = $this->createStub(DisplayPluginBase::class);
  $definition = [
    'entity_type' => 'entity_test',
  ];
  $this->argumentValidator = new Entity([], 'entity_test', $definition, $this->entityTypeManager, $this->entityTypeBundleInfo);
}

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