function FilterEntityReferenceTest::setUp

Same name in this branch
  1. 11.x core/modules/views_ui/tests/src/FunctionalJavascript/FilterEntityReferenceTest.php \Drupal\Tests\views_ui\FunctionalJavascript\FilterEntityReferenceTest::setUp()

Overrides ViewsKernelTestBase::setUp

File

core/modules/views/tests/src/Kernel/Handler/FilterEntityReferenceTest.php, line 80

Class

FilterEntityReferenceTest
Tests the core Drupal\views\Plugin\views\filter\EntityReference handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

protected function setUp($import_test_views = TRUE) : void {
    parent::setUp(FALSE);
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installConfig([
        'node',
        'user',
        'filter',
    ]);
    ViewTestData::createTestViews(static::class, [
        'views_test_config',
    ]);
    // Create two node types.
    $this->createContentType([
        'type' => 'page',
    ]);
    $this->createContentType([
        'type' => 'article',
    ]);
    // Add an entity reference field to the page type referencing the article
    // type.
    $selection_handler_settings = [
        'target_bundles' => [
            'article' => 'article',
        ],
    ];
    $this->createEntityReferenceField('node', 'page', 'field_test', 'Test reference', 'node', $selection_handler = 'default', $selection_handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    // Create user 1.
    $this->user1 = $this->createUser();
    $this->user2 = $this->createUser();
    // Create target nodes to be referenced.
    foreach (range(0, 5) as $count) {
        $this->targetNodes[$count] = $this->createNode([
            'type' => 'article',
            'title' => 'Article ' . $count,
            'status' => 1,
            'uid' => $this->user1,
        ]);
    }
    // Create a page referencing Article 0 and Article 1.
    $this->hostNodes[0] = $this->createNode([
        'type' => 'page',
        'title' => 'Page 0',
        'status' => 1,
        'created' => time(),
        'field_test' => [
            $this->targetNodes[0]
                ->id(),
            $this->targetNodes[1]
                ->id(),
        ],
        'uid' => $this->user2,
    ]);
    // Create a page referencing Article 1, Article 2, and Article 3.
    $this->hostNodes[1] = $this->createNode([
        'type' => 'page',
        'title' => 'Page 1',
        'status' => 1,
        'created' => time() - 100,
        'field_test' => [
            $this->targetNodes[1]
                ->id(),
            $this->targetNodes[2]
                ->id(),
            $this->targetNodes[3]
                ->id(),
        ],
        'uid' => $this->user2,
    ]);
    // Create a page referencing nothing.
    $this->hostNodes[2] = $this->createNode([
        'type' => 'page',
        'title' => 'Page 2',
        'status' => 1,
        'created' => time() - 200,
        'uid' => $this->user2,
    ]);
}

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