function ArgumentNullTest::testAreaText

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/ArgumentNullTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentNullTest::testAreaText()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/ArgumentNullTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentNullTest::testAreaText()
  3. 10 core/modules/views/tests/src/Kernel/Handler/ArgumentNullTest.php \Drupal\Tests\views\Kernel\Handler\ArgumentNullTest::testAreaText()

File

core/modules/views/tests/src/Kernel/Handler/ArgumentNullTest.php, line 31

Class

ArgumentNullTest
Tests the core Drupal\views\Plugin\views\argument\NullArgument handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testAreaText() : void {
    // Test validation
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Add a null argument.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('arguments', [
        'null' => [
            'id' => 'null',
            'table' => 'views',
            'field' => 'null',
        ],
    ]);
    $this->executeView($view);
    // Make sure that the argument is not validated yet.
    unset($view->argument['null']->argument_validated);
    $this->assertTrue($view->argument['null']
        ->validateArgument(26));
    // Test must_not_be option.
    unset($view->argument['null']->argument_validated);
    $view->argument['null']->options['must_not_be'] = TRUE;
    $this->assertFalse($view->argument['null']
        ->validateArgument(26), 'must_not_be returns FALSE, if there is an argument');
    unset($view->argument['null']->argument_validated);
    $this->assertTrue($view->argument['null']
        ->validateArgument(NULL), 'must_not_be returns TRUE, if there is no argument');
    // Test execution.
    $view->destroy();
    $view->setDisplay();
    // Add an argument, which has null as handler.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('arguments', [
        'id' => [
            'id' => 'id',
            'table' => 'views_test_data',
            'field' => 'id',
        ],
    ]);
    $this->executeView($view, [
        26,
    ]);
    // The argument should be ignored, so every result should return.
    $this->assertCount(5, $view->result);
}

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