You are here

class ArgumentValidatorTest in Drupal 10

Same name in this branch
  1. 10 core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php \Drupal\Tests\views_ui\Functional\ArgumentValidatorTest
  2. 10 core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php \Drupal\Tests\views\Kernel\Plugin\ArgumentValidatorTest
  3. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php \Drupal\views_test_data\Plugin\views\argument_validator\ArgumentValidatorTest
Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php \Drupal\Tests\views\Kernel\Plugin\ArgumentValidatorTest
  2. 9 core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php \Drupal\Tests\views\Kernel\Plugin\ArgumentValidatorTest

Tests Views argument validators.

@group views

Hierarchy

  • class \Drupal\Tests\views\Kernel\Plugin\ArgumentValidatorTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase

Expanded class hierarchy of ArgumentValidatorTest

3 string references to 'ArgumentValidatorTest'
ArgumentValidatorTest::calculateDependencies in core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php
ViewEntityDependenciesTest::testGetDependencies in core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php
Tests the getDependencies method.
views.view.test_argument_dependency.yml in core/modules/views/tests/modules/views_test_config/test_views/views.view.test_argument_dependency.yml
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_argument_dependency.yml

File

core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php, line 14

Namespace

Drupal\Tests\views\Kernel\Plugin
View source
class ArgumentValidatorTest extends ViewsKernelTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = [
    'test_view_argument_validate_numeric',
    'test_view',
  ];
  public function testArgumentValidateNumeric() {
    $view = Views::getView('test_view_argument_validate_numeric');
    $view
      ->initHandlers();
    $this
      ->assertFalse($view->argument['null']
      ->validateArgument($this
      ->randomString()));

    // Reset saved argument validation.
    $view->argument['null']->argument_validated = NULL;
    $this
      ->assertTrue($view->argument['null']
      ->validateArgument(12));
  }

  /**
   * Tests the argument validator test plugin.
   *
   * @see Drupal\views_test_data\Plugin\views\argument_validator\ArgumentValidatorTest
   */
  public function testArgumentValidatorPlugin() {
    $view = Views::getView('test_view');

    // Add a new argument and set the test plugin for the argument_validator.
    $options = [
      'specify_validation' => TRUE,
      'validate' => [
        'type' => 'argument_validator_test',
      ],
    ];
    $id = $view
      ->addHandler('default', 'argument', 'views_test_data', 'name', $options);
    $view
      ->initHandlers();
    $test_value = $this
      ->randomMachineName();
    $argument = $view->argument[$id];
    $argument->options['validate_options']['test_value'] = $test_value;
    $this
      ->assertFalse($argument
      ->validateArgument($this
      ->randomMachineName()), 'A random value does not validate.');

    // Reset internal flag.
    $argument->argument_validated = NULL;
    $this
      ->assertTrue($argument
      ->validateArgument($test_value), 'The right argument validates.');
    $plugin = $argument
      ->getPlugin('argument_validator');
    $this
      ->assertInstanceOf(ArgumentValidatorTestPlugin::class, $plugin);
    $this
      ->assertFalse($plugin
      ->validateArgument($this
      ->randomMachineName()), 'A random value does not validate.');
    $this
      ->assertTrue($plugin
      ->validateArgument($test_value), 'The right argument validates.');
  }

}

Members