node_access_rebuild example

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

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    node_access_rebuild();
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->addDefaultCommentField('node', 'page');
    $this->webUser = $this->drupalCreateUser([
      'access content',
      'access comments',
      'node test view',
    ]);
  }

  /** * Tests the comment pager for nodes with multiple grants per realm. */

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // After enabling a node access module, the {node_access} table has to be     // rebuilt.     node_access_rebuild();

    // Add Hungarian, Catalan, and Afrikaans.     ConfigurableLanguage::createFromLangcode('hu')->save();
    ConfigurableLanguage::createFromLangcode('ca')->save();
    ConfigurableLanguage::createFromLangcode('af')->save();

    // Enable content translation for the current entity type.     \Drupal::service('content_translation.manager')->setEnabled('node', 'page', TRUE);
  }

  /** * Tests node access fallback handling with multiple node languages. */
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    node_access_rebuild();
    $this->drupalCreateContentType(['type' => 'page']);
    node_access_test_add_field(NodeType::load('page'));
    $this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
    \Drupal::state()->set('node_access_test.private', TRUE);
  }

  /** * Ensure that tracker_cron is not access sensitive. */
  public function testTrackerNodeAccessIndexing() {
    // The node is private and not authored by the anonymous user, so any entity
    $options = ['language' => $languages[$langcodes[1]]];
    $url = $node->toUrl('edit-form', $options);
    $this->drupalGet($url);
    $this->assertSession()->fieldValueEquals('edit-menu-title', $translated_node_title);
  }

  /** * Tests creating menu links via node form widget for nodes with grants. */
  public function testMenuNodeWithGrantsFormWidget() {
    \Drupal::service('module_installer')->install(['node_access_test']);
    node_access_rebuild();
    $this->assertTrue(\Drupal::moduleHandler()->hasImplementations('node_grants'));

    $admin_user = $this->drupalCreateUser([
      'access administration pages',
      'administer content types',
      'administer nodes',
      'administer menu',
      'create page content',
      'edit any page content',
    ]);
    $this->drupalLogin($admin_user);

    

  protected $fieldName;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    node_access_rebuild();

    // Create some users.     $this->adminUser = $this->drupalCreateUser([
      'access content',
      'bypass node access',
    ]);
    $this->contentAdminUser = $this->drupalCreateUser([
      'access content',
      'administer content types',
      'administer node fields',
    ]);

    

  protected User $noAccessUser2;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    node_access_rebuild();

    // Create some content.     $this->drupalCreateNode();
    $this->drupalCreateNode();
    $this->drupalCreateNode();
    $this->drupalCreateNode();

    // Create user with simple node access permission. The 'node test view'     // permission is implemented and granted by the node_access_test module.     $this->accessUser = $this->drupalCreateUser([
      'access content overview',
      
'bundle' => 'page',
      'widget' => [
        'type' => 'options_buttons',
      ],
      'settings' => [
        'on_label' => 'Private',
        'off_label' => 'Not private',
      ],
    ])->save();

    // After enabling a node access module, the access table has to be rebuild.     node_access_rebuild();

    // Add Hungarian and Catalan.     ConfigurableLanguage::createFromLangcode('hu')->save();
    ConfigurableLanguage::createFromLangcode('ca')->save();

    // Create a normal authenticated user.     $this->webUser = $this->drupalCreateUser(['access content']);

    // Load the user 1 user for later use as an admin user with permission to     // see everything.     $this->adminUser = User::load(1);

    

  public $testUser;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);

    node_access_rebuild();
    // Create a test user and log in.     $this->testUser = $this->drupalCreateUser([
      'access content',
      'search content',
      'use advanced search',
      'access user profiles',
    ]);
    $this->drupalLogin($this->testUser);
  }

  /** * Tests that search works with punctuation and HTML entities. */
$entity_type_manager
      ->getStorage('entity_form_display')
      ->load('node.article.default')
      ->setComponent($field_name[
        'type' => 'entity_reference_autocomplete_tags',
        'weight' => -4,
      ])
      ->save();

    node_access_test_add_field(NodeType::load('article'));

    node_access_rebuild();
    \Drupal::state()->set('node_access_test.private', TRUE);
  }

  /** * Tests the "private" node access functionality. * * - Create 2 users with "access content" and "create article" permissions. * - Each user creates one private and one not private article. * * - Test that each user can view the other user's non-private article. * - Test that each user cannot view the other user's private article. * - Test that each user finds only appropriate (non-private + own private) * in taxonomy listing. * - Create another user with 'view any private content'. * - Test that user 4 can view all content created above. * - Test that user 4 can view all content on taxonomy listing. */

  protected $webUser;

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

  protected function setUp(): void {
    parent::setUp();

    node_access_rebuild();
    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->webUser = $this->drupalCreateUser([
      'access content',
      'node test view',
    ]);
  }

  /** * Tests the forum node pager for nodes with multiple grants per realm. */
  public function testForumPager() {
    
/** * Tests workspace publishing is not sensitive to node access. * * The node_access_test module makes anonymous nodes unviewable, * so enable it and test getDifferringRevisionIdsOnTarget() with an anonymous * node. */
  public function testNodeAccessDifferringRevisionIdsOnTarget() {
    $this->initializeWorkspacesModule();
    \Drupal::service('module_installer')->install(['node_access_test']);
    node_access_rebuild();

    // Edit node 1 in 'stage'.     $this->switchToWorkspace('stage');
    $node = $this->entityTypeManager->getStorage('node')->load(1);
    $node->setTitle('stage - 1 - r3 - unpublished');
    $node->save();

    // Edit node 1 in 'live', and ensure it's anonymous.     $this->switchToWorkspace('live');
    $node = $this->entityTypeManager->getStorage('node')->load(1);
    $node->setTitle('live - 1 - r4 - unpublished');
    
/** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    node_access_rebuild();
    node_access_test_add_field(NodeType::load('forum'));
    \Drupal::state()->set('node_access_test.private', TRUE);
  }

  /** * Creates some users and creates a public node and a private node. * * Adds both active forum topics and new forum topics blocks to the sidebar. * Tests to ensure private node/public node access is respected on blocks. */
  public function testForumNodeAccess() {
    
protected static $modules = ['language', 'node_access_test'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    node_access_test_add_field(NodeType::load('page'));

    // After enabling a node access module, the access table has to be rebuild.     node_access_rebuild();

    // Enable the private node feature of the node_access_test module.     \Drupal::state()->set('node_access_test.private', TRUE);

    // Add Hungarian, Catalan and Croatian.     ConfigurableLanguage::createFromLangcode('hu')->save();
    ConfigurableLanguage::createFromLangcode('ca')->save();
    ConfigurableLanguage::createFromLangcode('hr')->save();
  }

  /** * Tests node access with multiple node languages and no private nodes. */
    // have access to the nodes has been successful.     $this->assertFalse($this->adminUser->hasPermission('bypass node access'));
    $this->assertNull(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions have been rebuilt');
    foreach ($nodes as $node) {
      $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.');
      $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.');
    }
    $this->assertEmpty(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record');

    // Test an anonymous node access rebuild from code.     $this->drupalLogout();
    node_access_rebuild();
    foreach ($nodes as $node) {
      $this->assertTrue($grant_storage->access($node, 'view', $this->webUser)->isAllowed(), 'After rebuilding node access the grant storage returns allowed for the node author.');
      $this->assertFalse($grant_storage->access($node, 'view', $this->adminUser)->isForbidden(), 'After rebuilding node access the grant storage returns forbidden for the admin user.');
    }
    $this->assertEmpty(\Drupal::service('node.grant_storage')->checkAll($this->webUser), 'There is no all realm access record');
  }

  /** * Tests rebuilding the node access permissions table with no content. */
  public function testNodeAccessRebuildNoAccessModules() {
    
protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->adminUser);
    $this->createContentTypeFromUi('Moderated content', 'moderated_content', FALSE);
    $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');

    // Add the private field to the node type.     node_access_test_add_field(NodeType::load('moderated_content'));

    // Rebuild permissions because hook_node_grants() is implemented by the     // node_access_test_empty module.     node_access_rebuild();
  }

  /** * Verifies that a non-admin user can still access the appropriate pages. */
  public function testPageAccess() {
    // Initially disable access grant records in     // node_access_test_node_access_records().     \Drupal::state()->set('node_access_test.private', TRUE);

    $this->drupalLogin($this->adminUser);

    
Home | Imprint | This part of the site doesn't use cookies.