linkByHrefExists example

    $edit_href = 'admin/structure/views/view/glossary';
    $this->drupalGet('admin/structure/views');
    // @todo Disabled default views do now appear on the front page. Test this     // behavior with templates instead.     // $this->assertSession()->linkByHrefNotExists($edit_href);
    // Enable the view, and make sure it is now visible on the main listing     // page.     $this->drupalGet('admin/structure/views');
    $this->clickViewsOperationLink('Enable', '/glossary/');
    $this->assertSession()->addressEquals('admin/structure/views');
    $this->assertSession()->linkByHrefExists($edit_href);

    // It should not be possible to revert the view yet.     // @todo Figure out how to handle this with the new configuration system.     // $this->assertSession()->linkNotExists('Revert');     // $revert_href = 'admin/structure/views/view/glossary/revert';     // $this->assertSession()->linkByHrefNotExists($revert_href);
    // Edit the view and change the title. Make sure that the new title is     // displayed.     $new_title = $this->randomMachineName(16);
    $edit = ['title' => $new_title];
    
$this->clickLink('Check manually');
    $this->checkForMetaRefresh();
  }

  /** * Runs a series of assertions that are applicable to all update statuses. */
  protected function standardTests() {
    $this->assertSession()->responseContains('<h3>Drupal core</h3>');
    // Verify that the link to the Drupal project appears.     $this->assertSession()->linkExists('Drupal');
    $this->assertSession()->linkByHrefExists('http://example.com/project/drupal');
    $this->assertSession()->pageTextNotContains('No available releases found');
    $this->assertSession()->pageTextContains('Last checked:');
    // No download URLs should be present.     $this->assertSession()->responseNotContains('.tar.gz');
  }

  /** * Asserts the expected security updates are displayed correctly on the page. * * @param string $project_path_part * The project path part needed for the release link. * @param string[] $expected_security_releases * The security releases, if any, that the status report should recommend. * @param string $expected_update_message_type * The type of update message expected. * @param string $update_element_css_locator * The CSS locator for the page element that contains the security updates. */
    $this->grantPermissions($role['access content overview']);
    $this->drupalGet('admin/content');
    $assert_session->linkByHrefNotExists('/admin/content/media');
    $this->assertCacheContext('user');

    // Create a new role, which implicitly checks if the permission exists.     $mediaOverviewRole = $this->createRole(['access content overview', 'access media overview']);
    $this->nonAdminUser->addRole($mediaOverviewRole);
    $this->nonAdminUser->save();

    $this->drupalGet('admin/content');
    $assert_session->linkByHrefExists('/admin/content/media');
    $this->clickLink('Media');
    $this->assertCacheContext('user');
    $assert_session->statusCodeEquals(200);
    $assert_session->elementExists('css', '.views-element-container');
    // First row of the View contains media created by admin user.     $assert_session->elementTextEquals('xpath', '//div[@class="views-element-container"]//tbody/tr[1]/td[contains(@class, "views-field-uid")]/a', $this->adminUser->getDisplayName());
    $assert_session->elementTextEquals('xpath', "//div[@class='views-element-container']//tbody/tr[1]/td[contains(@class, 'views-field-name')]/a[contains(@href, '/media/{$media->id()}')]", 'Unnamed');
    // Second row of the View contains media created by non-admin user.     $assert_session->elementTextEquals('xpath', '//div[@class="views-element-container"]//tbody/tr[2]/td[contains(@class, "views-field-uid")]/a', $this->nonAdminUser->getDisplayName());
    $assert_session->elementTextEquals('xpath', "//div[@class='views-element-container']//tbody/tr[2]/td[contains(@class, 'views-field-name')]/a[contains(@href, '/media/{$user_media->id()}')]", 'Unnamed');
  }

  

  public function testInterface() {
    // No language added.     // Check status page and Available translation updates page.     $this->drupalGet('admin/reports/status');
    $this->assertSession()->pageTextNotContains('Translation update status');

    $this->drupalGet('admin/reports/translations');
    $this->assertSession()->pageTextContains("No translatable languages available. Add a language first.");
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.configurable_language.collection')->toString());

    // Add German language.     $this->addLanguage('de');

    // Override Drupal core translation status as 'up-to-date'.     $status = locale_translation_get_status();
    $status['drupal']['de']->type = 'current';
    \Drupal::keyValue('locale.translation_status')->set('drupal', $status['drupal']);

    // One language added, all translations up to date.     $this->drupalGet('admin/reports/status');
    
    $theme = 'config_translation_test_theme';

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

    $this->drupalGet('admin/appearance');
    $element = $this->assertSession()->elementExists('xpath', "//a[normalize-space()='Install and set as default' and contains(@href, '{$theme}')]");
    $this->drupalGet($GLOBALS['base_root'] . $element->getAttribute('href')['external' => TRUE]);

    $translation_base_url = 'admin/config/development/performance/translate';
    $this->drupalGet($translation_base_url);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists("$translation_base_url/fr/add");
  }

}

  public function testNoFieldsDisplayOverview() {
    // Create a fresh content type without any fields.     NodeType::create([
      'type' => 'no_fields',
      'name' => 'No fields',
    ])->save();

    $this->drupalGet('admin/structure/types/manage/no_fields/display');
    $this->assertSession()->pageTextContains("There are no fields yet added. You can add new fields on the Manage fields page.");
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.node.field_ui_fields', ['node_type' => 'no_fields'])->toString());
  }

  /** * Tests if display mode local tasks appear in alphabetical order by label. */
  public function testViewModeLocalTasksOrder() {
    $manage_display = 'admin/structure/types/manage/' . $this->type . '/display';

    // Specify the 'rss' mode, check that the field is displayed the same.     $edit = [
      'display_modes_custom[rss]' => TRUE,
      
$this->drupalPlaceBlock('local_actions_block');
  }

  /** * Tests forum functionality through the admin and user interfaces. */
  public function testForum() {
    // Check that the basic forum install creates a default forum topic     $this->drupalGet('/forum');
    // Look for the "General discussion" default forum     $this->assertSession()->linkExists('General discussion');
    $this->assertSession()->linkByHrefExists('/forum/1');
    // Check the presence of expected cache tags.     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:forum.settings');

    $this->drupalGet(Url::fromRoute('forum.page', ['taxonomy_term' => 1]));
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:forum.settings');

    // Do the admin tests.     $this->doAdminTests($this->adminUser);

    // Check display order.     $display = EntityViewDisplay::load('node.forum.default');
    
/** * Enable moderation for a specified content type, using the UI. * * @param string $content_type_id * Machine name. * @param string $workflow_id * The workflow to attach to the bundle. */
  public function enableModerationThroughUi($content_type_id$workflow_id = 'editorial') {
    $this->drupalGet('/admin/config/workflow/workflows');
    $this->assertSession()->linkByHrefExists('admin/config/workflow/workflows/manage/' . $workflow_id);
    $edit['bundles[' . $content_type_id . ']'] = TRUE;
    $this->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/node');
    $this->submitForm($edit, 'Save');
    // Ensure the parent environment is up-to-date.     // @see content_moderation_workflow_insert()     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
    $router_builder = $this->container->get('router.builder');
    $router_builder->rebuildIfNeeded();
  }

  
'cardinality_number' => 6,
    ];
    $this->drupalGet($field_edit_path);
    $this->submitForm($edit, 'Save field settings');
    $this->assertSession()->pageTextContains('Updated field Body field settings.');
    $this->drupalGet($field_edit_path);
    $this->assertSession()->fieldValueEquals('cardinality', 'number');
    $this->assertSession()->fieldValueEquals('cardinality_number', 6);

    // Check that tabs displayed.     $this->assertSession()->linkExists('Edit');
    $this->assertSession()->linkByHrefExists('admin/structure/types/manage/article/fields/node.article.body');
    $this->assertSession()->linkExists('Field settings');
    $this->assertSession()->linkByHrefExists($field_edit_path);

    // Add two entries in the body.     $edit = ['title[0][value]' => 'Cardinality', 'body[0][value]' => 'Body 1', 'body[1][value]' => 'Body 2'];
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, 'Save');

    // Assert that you can't set the cardinality to a lower number than the     // highest delta of this field.     $edit = [
      
    $view1 = [];
    $view1['label'] = $this->randomMachineName(16);
    $view1['id'] = strtolower($this->randomMachineName(16));
    $view1['description'] = $this->randomMachineName(16);
    $view1['page[create]'] = FALSE;
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view1, 'Save and edit');
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet('admin/structure/views');
    $this->assertSession()->pageTextContains($view1['label']);
    $this->assertSession()->pageTextContains($view1['description']);
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.view.edit_form', ['view' => $view1['id']])->toString());
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.view.delete_form', ['view' => $view1['id']])->toString());
    $this->assertSession()->linkByHrefExists(Url::fromRoute('entity.view.duplicate_form', ['view' => $view1['id']])->toString());

    // The view should not have a REST export display.     $this->assertSession()->pageTextNotContains('REST export');

    // This view should not have a block.     $this->drupalGet('admin/structure/block');
    $this->assertSession()->pageTextNotContains($view1['label']);

    // Create two nodes.
// Ensure that dialog titles are not escaped.     $edit_groupby_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
    $this->assertSession()->linkByHrefNotExists($edit_groupby_url, 0, 'No aggregation link found.');

    // Enable aggregation on the view.     $edit = [
      'group_by' => TRUE,
    ];
    $this->drupalGet('/admin/structure/views/nojs/display/test_view/default/group_by');
    $this->submitForm($edit, 'Apply');

    $this->assertSession()->linkByHrefExists($edit_groupby_url, 0, 'Aggregation link found.');

    $edit_handler_url = '/admin/structure/views/ajax/handler-group/test_view/default/field/name';
    $this->drupalGet($edit_handler_url);
    $data = Json::decode($this->getSession()->getPage()->getContent());
    $this->assertEquals('Configure aggregation settings for field Views test: Name', $data[3]['dialogOptions']['title']);
  }

  /** * Tests the field labels. */
  public function testFieldLabel() {
    
$this->assertFalse($source_field->isNew(), 'Source field was saved.');
    /** @var \Drupal\field\FieldStorageConfigInterface $storage */
    $storage = $source_field->getFieldStorageDefinition();
    $this->assertFalse($storage->isNew(), 'Source field storage definition was saved.');
    $this->assertFalse($storage->isLocked(), 'Source field storage definition was not locked.');

    /** @var \Drupal\media\MediaTypeInterface $media_type_storage */
    $media_type_storage = $this->container->get('entity_type.manager')->getStorage('media_type');
    $this->testMediaType = $media_type_storage->load(strtolower($name));

    // Check if all action links exist.     $assert_session->linkByHrefExists('admin/structure/media/add');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id());
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/fields');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/form-display');
    $assert_session->linkByHrefExists('admin/structure/media/manage/' . $this->testMediaType->id() . '/display');

    // Assert that fields have expected values before editing.     $page->clickLink('Edit');
    $assert_session->fieldValueEquals('label', $name);
    $assert_session->fieldValueEquals('description', $description);
    $assert_session->fieldValueEquals('source', 'test');
    $assert_session->fieldValueEquals('label', $name);
    
// Log in with another user and make sure the view is locked and break.     $this->drupalGet('admin/structure/views/nojs/display/test_view/default/title');
    $this->submitForm([], 'Apply');
    $this->drupalLogin($this->adminUser);

    $this->drupalGet('admin/structure/views/view/test_view/edit');
    // Test that save and cancel buttons are not shown.     $this->assertSession()->buttonNotExists('Save');
    $this->assertSession()->buttonNotExists('Cancel');
    // Test we have the break lock link.     $this->assertSession()->linkByHrefExists('admin/structure/views/view/test_view/break-lock');
    // Break the lock.     $this->clickLink('break this lock');
    $this->submitForm([], 'Break lock');
    // Test that save and cancel buttons are shown.     $this->assertSession()->buttonExists('Save');
    $this->assertSession()->buttonExists('Cancel');
    // Test we can save the view.     $this->drupalGet('admin/structure/views/view/test_view/edit');
    $this->submitForm([], 'Save');
    $this->assertSession()->pageTextContains("The view Test view has been saved.");

    
/** * Tests the EntityViewMode user interface. */
  public function testEntityViewModeUI() {
    // Test the listing page.     $this->drupalGet('admin/structure/display-modes/view');
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalLogin($this->drupalCreateUser(['administer display modes']));
    $this->drupalGet('admin/structure/display-modes/view');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Add view mode');
    $this->assertSession()->linkByHrefExists('admin/structure/display-modes/view/add');
    $this->assertSession()->linkByHrefExists('admin/structure/display-modes/view/add/entity_test');

    $this->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
    $this->assertSession()->statusCodeEquals(404);

    $this->drupalGet('admin/structure/display-modes/view/add');
    $this->assertSession()->linkNotExists('Test entity - revisions and data table', 'An entity type with no view builder cannot have view modes.');

    // Test adding a view mode including dots in machine_name.     $this->clickLink('Test entity');
    $edit = [
      

    $untranslatable_vocabulary->save();

    $values = [
      'name' => $this->randomMachineName(),
    ];
    $untranslatable_tid = $this->createEntity($values$this->langcodes[0]$untranslatable_vocabulary->id());

    // Verify translation links.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists('term/' . $translatable_tid . '/translations', 0, 'The translations link exists for a translatable vocabulary.');
    $this->assertSession()->linkByHrefExists('term/' . $translatable_tid . '/edit', 0, 'The edit link exists for a translatable vocabulary.');

    $this->drupalGet('admin/structure/taxonomy/manage/' . $untranslatable_vocabulary->id() . '/overview');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkByHrefExists('term/' . $untranslatable_tid . '/edit');
    $this->assertSession()->linkByHrefNotExists('term/' . $untranslatable_tid . '/translations');
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.