Mercurial > hg > isophonics-drupal-site
view core/modules/user/src/Tests/Views/ArgumentValidateTest.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line source
<?php namespace Drupal\user\Tests\Views; use Drupal\Core\Form\FormState; use Drupal\views\Plugin\views\argument\ArgumentPluginBase; use Drupal\views\Views; /** * Tests user argument validators for ID and name. * * @group user */ class ArgumentValidateTest extends UserTestBase { /** * Views used by this test. * * @var array */ public static $testViews = ['test_view_argument_validate_user', 'test_view_argument_validate_username']; /** * A user for this test. * * @var \Drupal\user\UserInterface */ protected $account; protected function setUp() { parent::setUp(); $this->account = $this->drupalCreateUser(); } /** * Tests the User (ID) argument validator. */ public function testArgumentValidateUserUid() { $account = $this->account; $view = Views::getView('test_view_argument_validate_user'); $this->executeView($view); $this->assertTrue($view->argument['null']->validateArgument($account->id())); // Reset argument validation. $view->argument['null']->argument_validated = NULL; // Fail for a valid numeric, but for a user that doesn't exist $this->assertFalse($view->argument['null']->validateArgument(32)); $form = []; $form_state = new FormState(); $view->argument['null']->buildOptionsForm($form, $form_state); $sanitized_id = ArgumentPluginBase::encodeValidatorId('entity:user'); $this->assertTrue($form['validate']['options'][$sanitized_id]['roles']['#states']['visible'][':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]']['checked']); } /** * Tests the UserName argument validator. */ public function testArgumentValidateUserName() { $account = $this->account; $view = Views::getView('test_view_argument_validate_username'); $this->executeView($view); $this->assertTrue($view->argument['null']->validateArgument($account->getUsername())); // Reset argument validation. $view->argument['null']->argument_validated = NULL; // Fail for a valid string, but for a user that doesn't exist $this->assertFalse($view->argument['null']->validateArgument($this->randomMachineName())); } }