function RelationshipRepresentativeNodeTest::testRelationship

Same name in this branch
  1. 9 core/modules/taxonomy/tests/src/Functional/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\taxonomy\Functional\Views\RelationshipRepresentativeNodeTest::testRelationship()
Same name in other branches
  1. 8.9.x core/modules/taxonomy/tests/src/Functional/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\taxonomy\Functional\Views\RelationshipRepresentativeNodeTest::testRelationship()
  2. 8.9.x core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\user\Kernel\Views\RelationshipRepresentativeNodeTest::testRelationship()
  3. 10 core/modules/taxonomy/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\taxonomy\Kernel\Views\RelationshipRepresentativeNodeTest::testRelationship()
  4. 10 core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\user\Kernel\Views\RelationshipRepresentativeNodeTest::testRelationship()
  5. 11.x core/modules/taxonomy/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\taxonomy\Kernel\Views\RelationshipRepresentativeNodeTest::testRelationship()
  6. 11.x core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php \Drupal\Tests\user\Kernel\Views\RelationshipRepresentativeNodeTest::testRelationship()

Tests the relationship.

File

core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php, line 45

Class

RelationshipRepresentativeNodeTest
Tests the representative node relationship for users.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testRelationship() {
    $this->installSchema('system', [
        'sequences',
    ]);
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installConfig([
        'filter',
    ]);
    ViewTestData::createTestViews(static::class, [
        'user_test_views',
    ]);
    $users[] = $this->createUser([], NULL, FALSE, [
        'uid' => 2,
    ]);
    $users[] = $this->createUser([], NULL, FALSE, [
        'uid' => 1,
    ]);
    $nodes[] = $this->createNode([
        'uid' => $users[0]->id(),
    ]);
    $nodes[] = $this->createNode([
        'uid' => $users[1]->id(),
    ]);
    $view = Views::getView('test_groupwise_user');
    $view->preview();
    $map = [
        'node_field_data_users_field_data_nid' => 'nid',
        'uid' => 'uid',
    ];
    $expected_result = [
        [
            'uid' => $users[1]->id(),
            'nid' => $nodes[1]->id(),
        ],
        [
            'uid' => $users[0]->id(),
            'nid' => $nodes[0]->id(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected_result, $map);
}

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