setupPermissionTestData example

/** * Views used by this test. * * @var array */
  public static $testViews = ['test_field_permission'];

  /** * Tests the permission field handler output. */
  public function testFieldPermission() {
    $this->setupPermissionTestData();

    $view = Views::getView('test_field_permission');
    $this->executeView($view);
    $view->initStyle();
    $view->render();
    $style_plugin = $view->style_plugin;

    $expected_permissions = [];
    $expected_permissions[$this->users[0]->id()] = [];
    $expected_permissions[$this->users[1]->id()] = [];
    $expected_permissions[$this->users[2]->id()][] = 'Administer roles and permissions';
    
public static $testViews = ['test_filter_permission'];

  protected $columnMap;

  /** * Tests the permission filter handler. * * @todo Fix the different commented out tests by fixing the many to one * handler handling with the NOT operator. */
  public function testFilterPermission() {
    $this->setupPermissionTestData();

    $column_map = ['uid' => 'uid'];
    $view = Views::getView('test_filter_permission');

    // Filter by a non existing permission.     $view->initHandlers();
    $view->filter['permission']->value = ['non_existent_permission'];
    $this->executeView($view);
    $this->assertCount(4, $view->result, 'A non existent permission is not filtered so everything is the result.');
    $expected[] = ['uid' => 1];
    $expected[] = ['uid' => 2];
    

  protected $currentUser;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE): void {
    parent::setUp();
    $this->currentUser = $this->container->get('current_user');
    $this->setupPermissionTestData();
  }

  /** * Tests the current user filter handler with anonymous user. */
  public function testFilterCurrentUserAsAnonymous() {
    $column_map = ['uid' => 'uid'];
    $this->currentUser->setAccount(new AnonymousUserSession());

    $view = Views::getView('test_filter_current_user');
    $view->initHandlers();
    
Home | Imprint | This part of the site doesn't use cookies.