|
2 | 2 |
|
3 | 3 | namespace Drupal\Tests\views\Kernel\Handler; |
4 | 4 |
|
| 5 | +use Drupal\Core\StringTranslation\StringTranslationTrait; |
| 6 | +use Drupal\Core\StringTranslation\TranslatableMarkup; |
5 | 7 | use Drupal\Tests\views\Kernel\ViewsKernelTestBase; |
| 8 | +use Drupal\views\Plugin\views\display\DisplayPluginBase; |
| 9 | +use Drupal\views\ViewExecutable; |
6 | 10 | use Drupal\views\Views; |
7 | 11 |
|
8 | 12 | /** |
|
11 | 15 | * @group views |
12 | 16 | */ |
13 | 17 | class FilterInOperatorTest extends ViewsKernelTestBase { |
| 18 | + use StringTranslationTrait; |
14 | 19 |
|
15 | 20 | public static $modules = ['system']; |
16 | 21 |
|
@@ -195,4 +200,34 @@ protected function getGroupedExposedFilters() { |
195 | 200 | return $filters; |
196 | 201 | } |
197 | 202 |
|
| 203 | + /** |
| 204 | + * Tests that the InOperator filter can handle TranslateableMarkup. |
| 205 | + */ |
| 206 | + public function testFilterOptionAsMarkup() { |
| 207 | + $view = $this->prophesize(ViewExecutable::class); |
| 208 | + $display = $this->prophesize(DisplayPluginBase::class); |
| 209 | + $display->getOption('relationships')->willReturn(FALSE); |
| 210 | + $view->display_handler = $display->reveal(); |
| 211 | + |
| 212 | + /** @var \Drupal\views\Plugin\ViewsHandlerManager $manager */ |
| 213 | + $manager = $this->container->get('plugin.manager.views.filter'); |
| 214 | + /** @var \Drupal\views\Plugin\views\filter\InOperator $operator */ |
| 215 | + $operator = $manager->createInstance('in_operator'); |
| 216 | + $options = ['value' => ['foo' => [], 'baz' => []]]; |
| 217 | + $operator->init($view->reveal(), $display->reveal(), $options); |
| 218 | + |
| 219 | + $input_options = [ |
| 220 | + 'foo' => 'bar', |
| 221 | + 'baz' => $this->t('qux'), |
| 222 | + 'quux' => (object) ['option' => ['quux' => 'corge']], |
| 223 | + ]; |
| 224 | + $reduced_values = $operator->reduceValueOptions($input_options); |
| 225 | + |
| 226 | + $this->assertSame(['foo', 'baz'], array_keys($reduced_values)); |
| 227 | + $this->assertInstanceOf(TranslatableMarkup::class, $reduced_values['baz']); |
| 228 | + $this->assertSame('qux', (string) $reduced_values['baz']); |
| 229 | + $this->assertSame('bar', $reduced_values['foo']); |
| 230 | + |
| 231 | + } |
| 232 | + |
198 | 233 | } |
0 commit comments