Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / ArgumentValidatorTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\views\Views;
6
7 /**
8  * Tests the Argument validator through the UI.
9  *
10  * @group views_ui
11  */
12 class ArgumentValidatorTest extends UITestBase {
13
14   /**
15    * Views used by this test.
16    *
17    * @var array
18    */
19   public static $testViews = ['test_argument'];
20
21   /**
22    * Tests the 'Specify validation criteria' checkbox functionality.
23    */
24   public function testSpecifyValidation() {
25     // Specify a validation based on Node for the 'id' argument on the default
26     // display and assert that this works.
27     $this->saveArgumentHandlerWithValidationOptions(TRUE);
28     $view = Views::getView('test_argument');
29     $handler = $view->getHandler('default', 'argument', 'id');
30     $this->assertTrue($handler['specify_validation'], 'Validation for this argument has been turned on.');
31     $this->assertEqual('entity:node', $handler['validate']['type'], 'Validation for the argument is based on the node.');
32
33     // Uncheck the 'Specify validation criteria' checkbox and expect the
34     // validation type to be reset back to 'none'.
35     $this->saveArgumentHandlerWithValidationOptions(FALSE);
36     $view = Views::getView('test_argument');
37     $handler = $view->getHandler('default', 'argument', 'id');
38     $this->assertFalse($handler['specify_validation'], 'Validation for this argument has been turned off.');
39     $this->assertEqual('none', $handler['validate']['type'], 'Validation for the argument has been reverted to Basic Validation.');
40   }
41
42   /**
43    * Saves the test_argument view with changes made to the argument handler
44    * both with and without specify_validation turned on.
45    *
46    * @param bool $specify_validation
47    */
48   protected function saveArgumentHandlerWithValidationOptions($specify_validation) {
49     $options = [
50       'options[validate][type]' => 'entity---node',
51       'options[specify_validation]' => $specify_validation,
52     ];
53     $this->drupalPostForm('admin/structure/views/nojs/handler/test_argument/default/argument/id', $options, t('Apply'));
54     $this->drupalPostForm('admin/structure/views/view/test_argument', [], t('Save'));
55   }
56
57 }