ArgumentValidateTest.php in Zircon Profile 8.0
File
core/modules/user/src/Tests/Views/ArgumentValidateTest.php
View source
<?php
namespace Drupal\user\Tests\Views;
use Drupal\Core\Form\FormState;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\views\Views;
class ArgumentValidateTest extends UserTestBase {
public static $testViews = array(
'test_view_argument_validate_user',
'test_view_argument_validate_username',
);
protected $account;
protected function setUp() {
parent::setUp();
$this->account = $this
->drupalCreateUser();
}
function testArgumentValidateUserUid() {
$account = $this->account;
$view = Views::getView('test_view_argument_validate_user');
$this
->executeView($view);
$this
->assertTrue($view->argument['null']
->validateArgument($account
->id()));
$view->argument['null']->argument_validated = NULL;
$this
->assertFalse($view->argument['null']
->validateArgument(32));
$form = array();
$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']);
}
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()));
$view->argument['null']->argument_validated = NULL;
$this
->assertFalse($view->argument['null']
->validateArgument($this
->randomMachineName()));
}
}