linkByHrefNotExists example

// Menu link URIs are stored as 'internal:/node/$nid'.       $node = Node::load(str_replace('internal:/node/', '', $item->link->uri));
      $this->verifyMenuLink($item$node);
    }

    // Log in the administrator.     $this->drupalLogin($this->adminUser);

    // Verify delete link exists and reset link does not exist.     $this->drupalGet('admin/structure/menu/manage/' . $this->menu->id());
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.menu_link_content.delete_form', ['menu_link_content' => $this->items[0]->id()])->toString());
    $this->assertSession()->linkByHrefNotExists(Url::fromRoute('menu_ui.link_reset', ['menu_link_plugin' => $this->items[0]->getPluginId()])->toString());
    // Check delete and reset access.     $this->drupalGet('admin/structure/menu/item/' . $this->items[0]->id() . '/delete');
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('admin/structure/menu/link/' . $this->items[0]->getPluginId() . '/reset');
    $this->assertSession()->statusCodeEquals(403);

    // Delete menu links.     foreach ($this->items as $item) {
      $this->deleteMenuLink($item);
    }

    
// Update site name and slogan for French.     $edit = [
      'translation[config_names][system.site][name]' => $fr_site_name,
      'translation[config_names][system.site][slogan]' => $fr_site_slogan,
    ];

    $this->drupalGet("{$translation_base_url}/fr/add");
    $this->submitForm($edit, 'Save translation');
    $this->assertSession()->pageTextContains('Successfully saved French translation.');

    // Check for edit, delete links (and no 'add' link) for French language.     $this->assertSession()->linkByHrefNotExists("$translation_base_url/fr/add");
    $this->assertSession()->linkByHrefExists("$translation_base_url/fr/edit");
    $this->assertSession()->linkByHrefExists("$translation_base_url/fr/delete");

    // Check translation saved proper.     $this->drupalGet("$translation_base_url/fr/edit");
    $this->assertSession()->fieldValueEquals('translation[config_names][system.site][name]', $fr_site_name);
    $this->assertSession()->fieldValueEquals('translation[config_names][system.site][slogan]', $fr_site_slogan);

    // Place branding block with site name and slogan into header region.     $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);

    
    $admin_user_1 = $this->drupalCreateUser([
      'administer content types',
      'administer node fields',
      'administer permissions',
    ]);
    $this->drupalLogin($admin_user_1);

    // Test that the user only sees the actions available to them.     $this->drupalGet('admin/structure/types');
    $this->assertSession()->linkByHrefExists('admin/structure/types/manage/article/fields');
    $this->assertSession()->linkByHrefExists('admin/structure/types/manage/article/permissions');
    $this->assertSession()->linkByHrefNotExists('admin/structure/types/manage/article/display');

    // Create another admin user who can manage node fields display.     $admin_user_2 = $this->drupalCreateUser([
      'administer content types',
      'administer node display',
    ]);
    $this->drupalLogin($admin_user_2);

    // Test that the user only sees the actions available to them.     $this->drupalGet('admin/structure/types');
    $this->assertSession()->linkByHrefNotExists('admin/structure/types/manage/article/fields');
    
    $image_path = $this->createSampleImage($style);
    $this->assertEquals(1, $this->getImageCount($style)new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path]));

    // Delete the 'image_crop' effect from the style.     $this->drupalGet($style_path . '/effects/' . $uuids['image_crop'] . '/delete');
    $this->submitForm([], 'Delete');
    // Confirm that the form submission was successful.     $this->assertSession()->statusCodeEquals(200);
    $image_crop_effect = $style->getEffect($uuids['image_crop']);
    $this->assertSession()->statusMessageContains("The image effect {$image_crop_effect->label()} has been deleted.", 'status');
    // Confirm that there is no longer a link to the effect.     $this->assertSession()->linkByHrefNotExists($style_path . '/effects/' . $uuids['image_crop'] . '/delete');
    // Refresh the image style information and verify that the effect was     // actually deleted.     $entity_type_manager = $this->container->get('entity_type.manager');
    $style = $entity_type_manager->getStorage('image_style')->loadUnchanged($style->id());
    $this->assertFalse($style->getEffects()->has($uuids['image_crop'])new FormattableMarkup(
      'Effect with ID %uuid no longer found on image style %style',
      [
        '%uuid' => $uuids['image_crop'],
        '%style' => $style->label(),
      ]));

    
$this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("Role {$role_name} has been updated.");
    \Drupal::entityTypeManager()->getStorage('user_role')->resetCache([$role->id()]);
    $new_role = Role::load($role->id());
    $this->assertEquals($role_name$new_role->label(), 'The role name has been successfully changed.');

    // Test deleting a role.     $this->drupalGet("admin/people/roles/manage/{$role->id()}");
    $this->clickLink('Delete');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains("Role {$role_name} has been deleted.");
    $this->assertSession()->linkByHrefNotExists("admin/people/roles/manage/{$role->id()}", 'Role edit link removed.');
    \Drupal::entityTypeManager()->getStorage('user_role')->resetCache([$role->id()]);
    $this->assertNull(Role::load($role->id()), 'A deleted role can no longer be loaded.');

    // Make sure that the system-defined roles can be edited via the user     // interface.     $this->drupalGet('admin/people/roles/manage/' . RoleInterface::ANONYMOUS_ID);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextNotContains('Delete role');
    $this->drupalGet('admin/people/roles/manage/' . RoleInterface::AUTHENTICATED_ID);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextNotContains('Delete role');
  }
    $node = $storage->load($node->id());
    $node->isDefaultRevision(FALSE);
    $node->setNewRevision(TRUE);
    $node->save();

    $node_id = $node->id();

    $this->drupalGet('node/' . $node_id . '/revisions');

    // Verify that the latest affected revision having been a default revision     // is displayed as the current one.     $this->assertSession()->linkByHrefNotExists('/node/' . $node_id . '/revisions/1/revert');
    // The site may be installed in a subdirectory, so check if the URL is     // contained in the retrieved one.     $this->assertSession()->elementAttributeContains('xpath', '//tr[contains(@class, "revision-current")]/td/a[1]', 'href', '/node/1');

    // Verify that the default revision can be an older revision than the latest     // one.     // Assert that the revisions with translations changes are shown.     $this->assertSession()->linkByHrefExists('/node/' . $node_id . '/revisions/4/revert');

    // Assert that the revisions without translations changes are filtered out:     // 2, 3 and 5.
$this->drupalGet('archive');
    $this->assertSession()->statusCodeEquals(403);

    // Test deleting a view.     $this->drupalLogin($this->fullAdminUser);
    $this->drupalGet('admin/structure/views');
    $this->clickViewsOperationLink('Delete', '/glossary/');
    // Submit the confirmation form.     $this->submitForm([], 'Delete');
    // Ensure the view is no longer listed.     $this->assertSession()->addressEquals('admin/structure/views');
    $this->assertSession()->linkByHrefNotExists($edit_href);
    // Ensure the view is no longer available.     $this->drupalGet($edit_href);
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSession()->pageTextContains('Page not found');

    // Delete all duplicated Glossary views.     $this->drupalGet('admin/structure/views');
    $this->clickViewsOperationLink('Delete', 'duplicate_of_glossary');
    // Submit the confirmation form.     $this->submitForm([], 'Delete');

    

  protected function verifySearchPageOperations($id$edit$delete$disable$enable) {
    if ($edit) {
      $this->assertSession()->linkByHrefExists("admin/config/search/pages/manage/$id");
    }
    else {
      $this->assertSession()->linkByHrefNotExists("admin/config/search/pages/manage/$id");
    }
    if ($delete) {
      $this->assertSession()->linkByHrefExists("admin/config/search/pages/manage/$id/delete");
    }
    else {
      $this->assertSession()->linkByHrefNotExists("admin/config/search/pages/manage/$id/delete");
    }
    if ($disable) {
      $this->assertSession()->linkByHrefExists("admin/config/search/pages/manage/$id/disable");
    }
    else {
      
$assert_session = $this->assertSession();

    // Language options should not exist without language module.     $test_views = [
      'test_view' => 'default',
      'test_display' => 'page_1',
    ];
    foreach ($test_views as $view_name => $display) {
      $this->drupalGet('admin/structure/views/view/' . $view_name);
      $this->assertSession()->statusCodeEquals(200);
      $langcode_url = 'admin/structure/views/nojs/display/' . $view_name . '/' . $display . '/rendering_language';
      $this->assertSession()->linkByHrefNotExists($langcode_url);
      $assert_session->linkNotExistsExact('Content language selected for page');
      $this->assertSession()->linkNotExists('Content language of view row');
    }

    // Make the site multilingual and test the options again.     $this->container->get('module_installer')->install(['language', 'content_translation']);
    ConfigurableLanguage::createFromLangcode('hu')->save();
    $this->resetAll();
    $this->rebuildContainer();

    // Language options should now exist with entity language the default.
// Create revision of the node.     $nodes[1]->setNewRevision();
    $nodes[1]->save();
    $second_revision = $nodes[1]->getRevisionId();

    $this->drupalGet('test-node-revision-links');
    $this->assertSession()->statusCodeEquals(200);
    // The first node revision should link to the node directly as you get an     // access denied if you link to the revision.     $url = $nodes[0]->toUrl()->toString();
    $this->assertSession()->linkByHrefExists($url);
    $this->assertSession()->linkByHrefNotExists($url . '/revisions/' . $nodes[0]->getRevisionId() . '/view');
    $this->assertSession()->linkByHrefNotExists($url . '/revisions/' . $nodes[0]->getRevisionId() . '/delete');
    $this->assertSession()->linkByHrefNotExists($url . '/revisions/' . $nodes[0]->getRevisionId() . '/revert');

    // For the second node the current revision got set to the last revision, so     // the first one should also link to the node page itself.     $url = $nodes[1]->toUrl()->toString();
    $this->assertSession()->linkByHrefExists($url);
    $this->assertSession()->linkByHrefExists($url . '/revisions/' . $first_revision . '/view');
    $this->assertSession()->linkByHrefExists($url . '/revisions/' . $first_revision . '/delete');
    $this->assertSession()->linkByHrefExists($url . '/revisions/' . $first_revision . '/revert');
    $this->assertSession()->linkByHrefNotExists($url . '/revisions/' . $second_revision . '/view');
    
'alias[0][value]' => $alias3,
    ];
    $this->drupalGet('admin/config/search/path/add');
    $this->submitForm($edit, 'Save');

    // Filter by the first alias.     $edit = [
      'filter' => $alias1,
    ];
    $this->submitForm($edit, 'Filter');
    $this->assertSession()->linkByHrefExists($alias1);
    $this->assertSession()->linkByHrefNotExists($alias2);
    $this->assertSession()->linkByHrefNotExists($alias3);

    // Filter by the second alias.     $edit = [
      'filter' => $alias2,
    ];
    $this->submitForm($edit, 'Filter');
    $this->assertSession()->linkByHrefNotExists($alias1);
    $this->assertSession()->linkByHrefExists($alias2);
    $this->assertSession()->linkByHrefNotExists($alias3);

    
// Ensure that the user does have access to the autocompletion.     $this->assertSession()->elementsCount('xpath', '//input[@id="edit-uid-0-target-id" and contains(@data-autocomplete-path, "/entity_reference_autocomplete/user/default")]', 1);
  }

  /** * Check node/add when no node types exist. */
  public function testNodeAddWithoutContentTypes() {
    $this->drupalGet('node/add');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefNotExists('/admin/structure/types/add');

    // Test /node/add page without content types.     foreach (\Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple() as $entity) {
      $entity->delete();
    }

    $this->drupalGet('node/add');
    $this->assertSession()->statusCodeEquals(403);

    $admin_content_types = $this->drupalCreateUser([
      'administer content types',
    ]);

    $node3 = $this->drupalCreateNode([
      $field_name => [['target_id' => $this->terms[1][0]->id()]],
    ]);
    $node4 = $this->drupalCreateNode([
      $field_name => [['target_id' => $this->terms[2][0]->id()]],
    ]);

    // Only the nodes with the selected term should be shown.     $this->drupalGet('test-filter-taxonomy-index-tid');
    $this->assertSession()->pageTextNotContains($node1->getTitle());
    $this->assertSession()->linkByHrefNotExists($node1->toUrl()->toString());
    $xpath_node2_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node2->toUrl()->toString(),
      ':label' => $node2->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node2_link, 1);
    $xpath_node3_link = $this->assertSession()->buildXPathQuery('//div[@class="views-row"]//a[@href=:url and text()=:label]', [
      ':url' => $node3->toUrl()->toString(),
      ':label' => $node3->label(),
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath_node3_link, 1);
    $this->assertSession()->pageTextNotContains($node4->getTitle());
    
'name' => 'name',
      $this->fieldName => 'some_text',
    ])->save();
  }

  /** * Tests the entity reference display plugin. */
  public function testEntityReferenceDisplay() {
    // Test that the 'title' settings are not shown.     $this->drupalGet('admin/structure/views/view/test_display_entity_reference/edit/entity_reference_1');
    $this->assertSession()->linkByHrefNotExists('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/title');

    // Add the new field to the fields.     $this->drupalGet('admin/structure/views/nojs/add-handler/test_display_entity_reference/default/field');
    $this->submitForm([
      'name[entity_test__' . $this->fieldName . '.' . $this->fieldName . ']' => TRUE,
    ], 'Add and configure fields');
    $this->submitForm([], 'Apply');

    // Test that the right fields are shown on the display settings form.     $this->drupalGet('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/style_options');
    $this->assertSession()->pageTextContains('Test entity: Name');
    
->fields(['revision_id' => $revision_id])
      ->condition('id', $id)
      ->execute();

    // Increment the schema version.     \Drupal::state()->set('update_test_schema_version', 8002);
    $this->runUpdates();

    // Check that the alias defined earlier is not used during the update     // process.     $this->assertSession()->linkByHrefExists('/admin/structure');
    $this->assertSession()->linkByHrefNotExists('/admin-structure-alias');

    $account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']);
    $this->drupalLogin($account);

    // Go to the status report page and check that the alias is used.     $this->drupalGet('admin/reports/status');
    $this->assertSession()->linkByHrefNotExists('/admin/structure');
    $this->assertSession()->linkByHrefExists('/admin-structure-alias');
  }

  /** * Tests that test running environment is updated when module list changes. * * @see update_test_schema_update_8003() */
Home | Imprint | This part of the site doesn't use cookies.