function FilterStringTest::testFilterStringWord

Same name and namespace in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringWord()
  2. 10 core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringWord()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php \Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringWord()

File

core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php, line 244

Class

FilterStringTest
Tests the core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21filter%21StringFilter.php/class/StringFilter/9" title="Basic textfield filter to handle string filtering commands." class="local">Drupal\views\Plugin\views\filter\StringFilter</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterStringWord() {
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Change the filtering
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'description' => [
            'id' => 'description',
            'table' => 'views_test_data',
            'field' => 'description',
            'relationship' => 'none',
            'operator' => 'word',
            'value' => 'aCtor',
        ],
    ]);
    $this->executeView($view);
    $resultset = [
        [
            'name' => 'George',
        ],
        [
            'name' => 'Ringo',
        ],
    ];
    $this->assertIdenticalResultset($view, $resultset, $this->columnMap);
    $view->destroy();
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Change the filtering
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'description' => [
            'id' => 'description',
            'table' => 'views_test_data',
            'field' => 'description',
            'relationship' => 'none',
            'operator' => 'allwords',
            'value' => 'Richard Starkey',
        ],
    ]);
    $this->executeView($view);
    $resultset = [
        [
            'name' => 'Ringo',
        ],
    ];
    $this->assertIdenticalResultset($view, $resultset, $this->columnMap);
    $view->destroy();
    $view = Views::getView('test_view');
    $view->setDisplay();
    // Change the filtering to a sting containing only illegal characters.
    $view->displayHandlers
        ->get('default')
        ->overrideOption('filters', [
        'description' => [
            'id' => 'description',
            'table' => 'views_test_data',
            'field' => 'description',
            'relationship' => 'none',
            'operator' => 'allwords',
            'value' => ':-)',
        ],
    ]);
    $this->executeView($view);
    $resultset = [
        [
            'name' => 'Ringo',
        ],
        [
            'name' => 'John',
        ],
        [
            'name' => 'George',
        ],
        [
            'name' => 'Paul',
        ],
        [
            'name' => 'Meredith',
        ],
    ];
    $this->assertIdenticalResultset($view, $resultset);
}

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