function FilterInOperatorTest::testFilterOptionAsMarkup

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

Tests that the InOperator filter can handle TranslatableMarkup.

File

core/modules/views/tests/src/Kernel/Handler/FilterInOperatorTest.php, line 241

Class

FilterInOperatorTest
Tests the core <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21filter%21InOperator.php/class/InOperator/11.x" title="Simple filter to handle matching of multiple options selectable via checkboxes." class="local">Drupal\views\Plugin\views\filter\InOperator</a> handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testFilterOptionAsMarkup() : void {
    $view = $this->prophesize(ViewExecutable::class);
    $display = $this->prophesize(DisplayPluginBase::class);
    $display->getOption('relationships')
        ->willReturn(FALSE);
    $view->display_handler = $display->reveal();
    
    /** @var \Drupal\views\Plugin\ViewsHandlerManager $manager */
    $manager = $this->container
        ->get('plugin.manager.views.filter');
    
    /** @var \Drupal\views\Plugin\views\filter\InOperator $operator */
    $operator = $manager->createInstance('in_operator');
    $options = [
        'value' => [
            'foo' => [],
            'baz' => [],
        ],
    ];
    $operator->init($view->reveal(), $display->reveal(), $options);
    $input_options = [
        'foo' => 'bar',
        'baz' => $this->t('qux'),
        'foobar' => (object) [
            'option' => [
                'foobar' => 'dog',
            ],
        ],
    ];
    $reduced_values = $operator->reduceValueOptions($input_options);
    $this->assertSame([
        'foo',
        'baz',
    ], array_keys($reduced_values));
    $this->assertInstanceOf(TranslatableMarkup::class, $reduced_values['baz']);
    $this->assertSame('qux', (string) $reduced_values['baz']);
    $this->assertSame('bar', $reduced_values['foo']);
}

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