linkNotExists example

$account = $this->drupalCreateUser([
      'access media overview',
      'administer media',
    ]);
    $this->drupalLogin($account);

    $this->drupalGet('/admin/content/media');
    $assert_session = $this->assertSession();
    $assert_session->statusCodeEquals(200);
    $assert_session->linkExists($accessible_media->label());
    $assert_session->linkNotExists($hidden_media->label());
  }

  /** * Tests that the 'block_content_access' query tag is respected by Views. */
  public function testBlockContentEntityQueryAccess() {
    $this->container->get('module_installer')->install(['block_content']);

    BlockContentType::create([
      'id' => 'test',
      'label' => 'Test',
    ])
'access comments' => FALSE,
      'post comments' => FALSE,
      'skip comment approval' => FALSE,
    ]);

    // Attempt to view comments while disallowed.     // NOTE: if authenticated user has permission to post comments, then a     // "Login or register to post comments" type link may be shown.     $this->drupalGet('node/' . $this->node->id());
    // Verify that comments were not displayed.     $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@');
    $this->assertSession()->linkNotExists('Add new comment', 'Link to add comment was found.');

    // Attempt to view node-comment form while disallowed.     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
    $this->assertSession()->statusCodeEquals(403);

    user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => TRUE,
      'post comments' => FALSE,
      'skip comment approval' => FALSE,
    ]);
    $this->drupalGet('node/' . $this->node->id());
    
    // only tests this case.     // @see \node_test_node_grants()     $this->assertTrue(\Drupal::moduleHandler()->hasImplementations('node_grants'));

    // Create an unpublished node.     $referenced = $this->createNode(['status' => FALSE]);
    // Create a node referencing $referenced.     $node = $this->createNode(['ref' => $referenced]);

    // Check that the referenced entity link doesn't show on the host entity.     $this->drupalGet($node->toUrl());
    $this->assertSession()->linkNotExists($referenced->label());

    // Publish the referenced node.     $referenced->setPublished()->save();

    // Check that the referenced entity link shows on the host entity.     $this->getSession()->reload();
    $this->assertSession()->linkExists($referenced->label());
  }

}
$this->assertSession()->pageTextNotContains('Tours guide you through workflows');
    }

    $titles = $this->getTourList();

    // Test the titles that should be links.     foreach ($titles[0] as $title) {
      if ($tours_ok) {
        $this->assertSession()->linkExists($title);
      }
      else {
        $this->assertSession()->linkNotExists($title);
        // Just test the first item in the list of links that should not         // be there, because the second matches the name of a module that is         // in the Module overviews section, so the link will be there and         // this test will fail. Testing one should be sufficient to verify         // the page is working correctly.         break;
      }
    }

    // Test the titles that should not be links.     foreach ($titles[1] as $title) {
      
    $this->cronRun();

    // Test the keyword filter by visiting the page.     // The views are in the test view 'test_search', and they just display the     // titles of the nodes in the result, as links.
    // Page with a keyword filter of 'pizza'. This should find the Spanish     // translated node, which has 'pizza' in the title, but not the English     // one, which does not have the word 'pizza' in it.     $this->drupalGet('test-filter');
    $this->assertSession()->linkExists('pizza', 0, 'Found translation with matching title');
    $this->assertSession()->linkNotExists('sandwich', 'Did not find translation with non-matching title');
  }

}
// Access the update page with a schema version that is too old for system     // and the test module, only the generic core message should be shown.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl);
    $assert_session = $this->assertSession();
    $assert_session->pageTextContains('Requirements problem');
    $assert_session->pageTextContains('The version of Drupal you are trying to update from is too old');
    $assert_session->pageTextContains('Updating to Drupal 10 is only supported from Drupal version 9.4.0 or higher. If you are trying to update from an older version, first update to the latest version of Drupal 9');
    $assert_session->pageTextNotContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');

    $assert_session->linkNotExists('Continue');

    // Update the installed version of system and then assert that now,     // the test module is shown instead.     $update_registry->setInstalledVersion('user', 9301);
    $this->drupalGet($this->updateUrl);

    $assert_session->pageTextNotContains('The version of Drupal you are trying to update from is too old');

    $assert_session->pageTextContains('Unsupported schema version: Update test with hook_update_last_removed() implementation');
    $assert_session->pageTextContains('The installed version of the Update test with hook_update_last_removed() implementation module is too old to update. Update to an intermediate version first (last removed version: 8002, installed version: 8000).');
    $assert_session->linkNotExists('Continue');

    
$translated_entity_url = $this->entity->toUrl('canonical', ['language' => $language])->toString();
    $translated_layout_url = $translated_entity_url . '/layout';

    $this->drupalGet($entity_url);
    $assert_session->pageTextNotContains('The translated field value');
    $assert_session->pageTextContains('The untranslated field value');
    $assert_session->linkExists('Layout');

    $this->drupalGet($translated_entity_url);
    $assert_session->pageTextNotContains('The untranslated field value');
    $assert_session->pageTextContains('The translated field value');
    $assert_session->linkNotExists('Layout');

    $this->drupalGet($translated_layout_url);
    $assert_session->pageTextContains('Access denied');

    $this->addLayoutOverride();

    $this->drupalGet($entity_url);
    $assert_session->pageTextNotContains('The translated field value');
    $assert_session->pageTextContains('The untranslated field value');
    $assert_session->pageTextContains('Powered by Drupal');

    


    // When user does not have view access to referenced entities in entity     // reference field blocks, test that the cache tags of the referenced entity     // are still bubbled to page cache.     $referencing_node_url = $referencing_node->toUrl();
    $this->verifyPageCacheContainsTags($referencing_node_url, 'MISS');
    $this->verifyPageCacheContainsTags($referencing_node_url, 'HIT', $referenced_node->getCacheTags());
    // Since the referenced node is inaccessible, it should not appear on the     // referencing node.     $this->drupalGet($referencing_node_url);
    $assert_session->linkNotExists('The referenced node title');

    // Publish the referenced entity.     $referenced_node->setPublished()
      ->save();

    // Revisit the node with the reference field without clearing cache. Now     // that the referenced node is published, it should appear.     $this->verifyPageCacheContainsTags($referencing_node_url, 'MISS');
    $this->verifyPageCacheContainsTags($referencing_node_url, 'HIT', $referenced_node->getCacheTags());
    $this->drupalGet($referencing_node_url);
    $assert_session->linkExists('The referenced node title');
  }
$wid = $query->execute()->fetchField();
    $this->drupalGet('admin/reports/dblog/event/' . $wid);

    // Verify table headers are present.     $this->assertSession()->pageTextContains('Location');

    // Verify severity.     $this->assertSession()->pageTextContains('Notice');

    // Verify location is available as plain text.     $this->assertEquals($request_uri$this->cssSelect('table.dblog-event > tbody > tr:nth-child(4) > td')[0]->getHtml());
    $this->assertSession()->linkNotExists($request_uri);
  }

  /** * Test that twig errors are displayed correctly. */
  public function testMessageParsing() {
    $this->drupalLogin($this->adminUser);
    // Log a common twig error with {{ }} and { } variables.     \Drupal::service('logger.factory')->get("php")
      ->error('Incorrect parameter {{foo}} in path {path}: {value}',
        ['foo' => 'bar', 'path' => '/baz', 'value' => 'horse']
      );
$query_string = isset($parts['query']) ? rawurldecode($parts['query']) : '';
    $this->assertStringContainsString('=language:fr', $query_string, 'Language filter language:fr add to the query string.');

    // Search for keyword node and language filter as Spanish.     $edit = ['keys' => 'node', 'language[es]' => TRUE];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'edit-submit--2');
    // Check for Spanish results.     $this->assertSession()->linkExists('Second node this is the Spanish title', 0, 'Second node Spanish title found in search results');
    $this->assertSession()->linkExists('Third node es', 0, 'Third node Spanish found in search results');
    // Ensure that results don't contain other language nodes.     $this->assertSession()->linkNotExists('First node en', 'Search results do not contain first English node');
    $this->assertSession()->linkNotExists('Second node en', 'Search results do not contain second English node');
    $this->assertSession()->linkNotExists('Third node en', 'Search results do not contain third English node');

    // Change the default language and delete English.     $path = 'admin/config/regional/language';
    $this->drupalGet($path);
    $this->assertSession()->checkboxChecked('edit-site-default-language-en');
    $edit = [
      'site_default_language' => 'fr',
    ];
    $this->drupalGet($path);
    
// Visit the Help page and make sure no warnings or notices are thrown.     $this->drupalGet('admin/help/field');

    // Enable the Options, Email and Field API Test modules.     \Drupal::service('module_installer')->install(['options', 'field_test']);

    $this->drupalGet('admin/help/field');
    $this->assertSession()->linkExists('Options', 0, 'Options module is listed on the Field help page.');
    // Verify that modules with field types that do not implement hook_help are     // listed.     $this->assertSession()->pageTextContains('Field API Test');
    $this->assertSession()->linkNotExists('Field API Test', 'Modules with field types that do not implement hook_help are not linked.');
    $this->assertSession()->linkNotExists('Link', 'Modules that have not been installed, are not listed.');
  }

}

  }

  /** * Tests new comment marker. */
  public function testCommentNewCommentsIndicator() {
    // Test if the right links are displayed when no comment is present for the     // node.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('node');
    $this->assertSession()->linkNotExists('0 comments');
    $this->assertSession()->linkExists('Read more');
    // Verify the data-history-node-last-comment-timestamp attribute, which is     // used by the drupal.node-new-comments-link library to determine whether     // a "x new comments" link might be necessary or not. We do this in     // JavaScript to prevent breaking the render cache.     $this->assertSession()->elementNotExists('xpath', '//*[@data-history-node-last-comment-timestamp]');

    // Create a new comment. This helper function may be run with different     // comment settings so use $comment->save() to avoid complex setup.     /** @var \Drupal\comment\CommentInterface $comment */
    $comment = Comment::create([
      

  public function testCommentApproveLink() {
    $this->drupalLogin($this->drupalCreateUser(['administer comments']));
    // Set the comment status to unpublished.     $this->comment->setUnpublished();
    $this->comment->save();
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->pageTextContains($this->comment->getSubject());
    $this->assertSession()->linkExists('Approve');
    $this->clickLink('Approve');
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->linkNotExists('Approve');
    // Ensure that "published" column in table is marked as yes.     $this->assertSession()->elementTextContains('xpath', "//table/tbody/tr/td[3]", 'Yes');
  }

}
$menu = $this->addCustomMenu();
    $node = $this->drupalCreateNode(['type' => 'article']);

    // Create three menu items, none of which are expanded.     $parent = $this->addMenuLink('', $node->toUrl()->toString()$menu->id(), FALSE);
    $child_1 = $this->addMenuLink($parent->getPluginId()$node->toUrl()->toString()$menu->id(), FALSE);
    $child_2 = $this->addMenuLink($parent->getPluginId()$node->toUrl()->toString()$menu->id(), FALSE);

    // The menu will not automatically show all levels of depth.     $this->drupalGet('<front>');
    $this->assertSession()->linkExists($parent->getTitle());
    $this->assertSession()->linkNotExists($child_1->getTitle());
    $this->assertSession()->linkNotExists($child_2->getTitle());

    // Update the menu block to show all levels of depth as expanded.     $block_id = $this->blockPlacements[$menu->id()];
    $this->drupalGet('admin/structure/block/manage/' . $block_id);
    $this->assertSession()->checkboxNotChecked('settings[expand_all_items]');
    $this->submitForm([
      'settings[depth]' => 2,
      'settings[level]' => 1,
      'settings[expand_all_items]' => 1,
    ], 'Save block');

    
// Create a bundle that the user is forbidden from creating (always).     EntityTestBundle::create([
      'id' => 'forbidden_access_bundle',
      'label' => 'Forbidden to create bundle',
      'description' => 'A bundle that can never be created',
    ])->save();

    $this->drupalGet('/entity_test_with_bundle/add');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkExists('Test label');
    $this->assertSession()->linkExists('Test2 label');
    $this->assertSession()->linkNotExists('Forbidden to create bundle');
    $this->assertSession()->linkNotExists('Test3 label');
    $this->clickLink('Test label');
    $this->assertSession()->statusCodeEquals(200);

    // Without any permissions, access must be denied.     $this->drupalLogout();
    $this->drupalGet('/entity_test_with_bundle/add');
    $this->assertSession()->statusCodeEquals(403);

    // Create a new user that has bundle create permissions.     $user = $this->drupalCreateUser([
      
Home | Imprint | This part of the site doesn't use cookies.