function QueryGroupByTest::testGroupByWithFieldsNotExistingOnBundle

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByWithFieldsNotExistingOnBundle()
  2. 8.9.x core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByWithFieldsNotExistingOnBundle()
  3. 11.x core/modules/views/tests/src/Kernel/QueryGroupByTest.php \Drupal\Tests\views\Kernel\QueryGroupByTest::testGroupByWithFieldsNotExistingOnBundle()

Tests groupby with a non-existent field on some bundle.

File

core/modules/views/tests/src/Kernel/QueryGroupByTest.php, line 320

Class

QueryGroupByTest
Tests aggregate functionality of views, for example count.

Namespace

Drupal\Tests\views\Kernel

Code

public function testGroupByWithFieldsNotExistingOnBundle() : void {
    $field_storage = FieldStorageConfig::create([
        'type' => 'integer',
        'field_name' => 'field_test',
        'cardinality' => 4,
        'entity_type' => 'entity_test_mul',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
        'field_name' => 'field_test',
        'entity_type' => 'entity_test_mul',
        'bundle' => 'entity_test_mul',
    ]);
    $field->save();
    $entities = [];
    $entity = EntityTestMul::create([
        'field_test' => [
            1,
        ],
        'type' => 'entity_test_mul',
    ]);
    $entity->save();
    $entities[] = $entity;
    $entity = EntityTestMul::create([
        'type' => 'entity_test_mul2',
    ]);
    $entity->save();
    $entities[] = $entity;
    $view = Views::getView('test_group_by_field_not_within_bundle');
    $this->executeView($view);
    $this->assertCount(2, $view->result);
    // The first result is coming from entity_test_mul2, so no field could be
    // rendered.
    $this->assertEquals('', $view->getStyle()
        ->getField(0, 'field_test'));
    // The second result is coming from entity_test_mul, so its field value
    // could be rendered.
    $this->assertEquals('1', $view->getStyle()
        ->getField(1, 'field_test'));
}

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