diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 5fcb23ab14e30e30bf498649a1f94e684779d7e1..e7ca259940e2c24cafbadee8d8cddfa48e1fc9de 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -451,7 +451,7 @@ public function validate() { } } elseif (!empty($this->value) && ($this->operator == 'in' || $this->operator == 'not in')) { - $errors[] = $this->t('The value @value is not an array for @operator on filter: @filter', ['@value' => var_export($this->value), '@operator' => $this->operator, '@filter' => $this->adminLabel(TRUE)]); + $errors[] = $this->t('The value @value is not an array for @operator on filter: @filter', ['@value' => var_export($this->value, TRUE), '@operator' => $this->operator, '@filter' => $this->adminLabel(TRUE)]); } return $errors; } diff --git a/core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php b/core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7f80c6842d771d74be09741b033a9eaf01a2578f --- /dev/null +++ b/core/modules/views/tests/src/Unit/Plugin/filter/InOperatorTest.php @@ -0,0 +1,39 @@ +<?php + +namespace Drupal\Tests\views\Unit\Plugin\filter; + +use Drupal\Tests\UnitTestCase; +use Drupal\views\Plugin\views\filter\InOperator; + +/** + * @coversDefaultClass \Drupal\views\Plugin\views\filter\InOperator + * @group views + */ +class InOperatorTest extends UnitTestCase { + + /** + * @covers ::validate + */ + public function testValidate() { + $definition = [ + 'title' => 'Is InOperator Test', + 'group' => 'Test', + 'options callback' => '\Drupal\Tests\views\Unit\Plugin\filter\InOperatorTest::validate_options_callback', + ]; + $filter = new InOperator([], 'in_operator', $definition); + $filter->value = 'string'; + $filter->operator = 'in'; + $translation_stub = $this->getStringTranslationStub(); + $filter->setStringTranslation($translation_stub); + $errors = $filter->validate(); + $this->assertSame('The value 'string' is not an array for in on filter: ' . $filter->adminLabel(TRUE), (string) $errors[0]); + } + + /** + * @return array + */ + public static function validate_options_callback() { + return ['Yes', 'No']; + } + +}