Verified Commit 23da7683 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3074595 by Lendude, ravi.shankar, sime, jian he, Kristen Pol, longwave:...

Issue #3074595 by Lendude, ravi.shankar, sime, jian he, Kristen Pol, longwave: var_export only returns if the second parameter set to TRUE

(cherry picked from commit 98856bb1)
parent 46ee6c8e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -452,7 +452,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;
  }
+39 −0
Original line number Diff line number Diff line
<?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 &#039;string&#039; 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'];
  }

}