You are here

class BaseFieldAccessTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php \Drupal\Tests\views\Functional\Entity\BaseFieldAccessTest
  2. 9 core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php \Drupal\Tests\views\Functional\Entity\BaseFieldAccessTest

Tests views base field access.

@group views

Hierarchy

  • class \Drupal\Tests\views\Functional\Entity\BaseFieldAccessTest extends \Drupal\Tests\views\Functional\ViewTestBase

Expanded class hierarchy of BaseFieldAccessTest

File

core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php, line 13

Namespace

Drupal\Tests\views\Functional\Entity
View source
class BaseFieldAccessTest extends ViewTestBase {

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

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'views',
    'views_test_config',
    'entity_test',
    'node',
    'views_entity_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE, $modules = [
    'views_test_config',
    'comment_test_views',
  ]) : void {
    parent::setUp($import_test_views, $modules);
    \Drupal::state()
      ->set('entity_test.views_data', [
      'entity_test' => [
        'test_text_access' => [
          'field' => [
            'id' => 'standard',
          ],
        ],
      ],
    ]);
    $entity_1 = EntityTest::create([
      'test_text_access' => 'no access value',
    ]);
    $entity_1
      ->save();
    $entity_2 = EntityTest::create([
      'test_text_access' => 'ok to see this one',
    ]);
    $entity_2
      ->save();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'access content',
    ]));
  }

  /**
   * Tests access to protected base fields.
   */
  public function testProtectedField() {
    $this
      ->drupalGet('test-entity-protected-access');
    $this
      ->assertSession()
      ->pageTextContains('ok to see this one');
    $this
      ->assertSession()
      ->pageTextNotContains('no access value');
  }

}

Members