public function GroupIdArgumentTest::testGroupIdArgument in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Kernel/Views/GroupIdArgumentTest.php \Drupal\Tests\group\Kernel\Views\GroupIdArgumentTest::testGroupIdArgument()
Tests the group_id argument.
File
- tests/
src/ Kernel/ Views/ GroupIdArgumentTest.php, line 56
Class
- GroupIdArgumentTest
- Tests the group_id argument handler.
Namespace
Drupal\Tests\group\Kernel\ViewsCode
public function testGroupIdArgument() {
$view = Views::getView('test_group_id_argument');
$view
->setDisplay();
/* @var \Drupal\group\Entity\GroupInterface $group1 */
$group1 = Group::create([
'type' => 'default',
'label' => $this
->randomMachineName(),
]);
$group1
->save();
/* @var \Drupal\group\Entity\GroupInterface $group2 */
$group2 = Group::create([
'type' => 'default',
'label' => $this
->randomMachineName(),
]);
$group2
->save();
$view
->preview();
$this
->assertEquals(2, count($view->result), 'Found the expected number of results.');
// Set the second group id as an argument.
$view
->destroy();
$view
->preview('default', [
$group2
->id(),
]);
// Verify that the title is overridden.
$this
->assertEquals($group2
->label(), $view
->getTitle());
// Verify that the argument filtering works.
$this
->assertEquals(1, count($view->result), 'Found the expected number of results.');
$this
->assertEquals((string) $view->style_plugin
->getField(0, 'id'), $group2
->id(), 'Found the correct group id.');
// Verify that setting a non-existing id as argument results in no groups
// being shown.
$view
->destroy();
$view
->preview('default', [
22,
]);
$this
->assertEquals(0, count($view->result), 'Found the expected number of results.');
}