function EntityTest::setUp

Same name in this branch
  1. 9 core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::setUp()
Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  2. 8.9.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. 11.x core/modules/views/tests/src/Unit/Plugin/argument_validator/EntityTest.php \Drupal\Tests\views\Unit\Plugin\argument_validator\EntityTest::setUp()
  6. 11.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 54

Class

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

Namespace

Drupal\Tests\views\Unit\Plugin\argument_validator

Code

protected function setUp() : void {
    parent::setUp();
    $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $this->entityTypeBundleInfo = $this->createMock(EntityTypeBundleInfoInterface::class);
    $mock_entity = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityBase', [], '', FALSE, TRUE, TRUE, [
        'bundle',
        'access',
    ]);
    $mock_entity->expects($this->any())
        ->method('bundle')
        ->willReturn('test_bundle');
    $mock_entity->expects($this->any())
        ->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->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityBase', [], '', FALSE, TRUE, TRUE, [
        'bundle',
        'access',
    ]);
    $mock_entity_bundle_2->expects($this->any())
        ->method('bundle')
        ->willReturn('test_bundle_2');
    $mock_entity_bundle_2->expects($this->any())
        ->method('access')
        ->willReturnMap([
        [
            'test_op',
            NULL,
            FALSE,
            FALSE,
        ],
        [
            'test_op_2',
            NULL,
            FALSE,
            FALSE,
        ],
        [
            'test_op_3',
            NULL,
            FALSE,
            TRUE,
        ],
    ]);
    $storage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
    // 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->expects($this->any())
        ->method('loadMultiple')
        ->willReturnMap($value_map);
    $this->entityTypeManager
        ->expects($this->any())
        ->method('getStorage')
        ->with('entity_test')
        ->willReturn($storage);
    $this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')
        ->disableOriginalConstructor()
        ->getMock();
    $this->display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')
        ->disableOriginalConstructor()
        ->getMock();
    $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.