buttonExists example


  protected function setUpProfile() {
    // This step is skipped, because there is a distribution profile.   }

  /** * {@inheritdoc} */
  protected function setUpSettings() {
    // The language should have been automatically detected, all following     // screens should be translated already.     $this->assertSession()->buttonExists('Save and continue de');
    $this->translations['Save and continue'] = 'Save and continue de';

    // Check the language direction.     $direction = $this->getSession()->getPage()->find('xpath', '/@dir')->getText();
    $this->assertEquals('ltr', $direction);

    // Verify that the distribution name appears.     $this->assertSession()->pageTextContains($this->info['distribution']['name']);
    // Verify that the requested theme is used.     $this->assertSession()->responseContains($this->info['distribution']['install']['theme']);
    // Verify that the "Choose profile" step does not appear.
// Create a new latest revision.     if ($entity instanceof RevisionLogInterface) {
      $entity->setRevisionCreationTime($date->modify('+1 hour')->getTimestamp());
    }
    $entity->setNewRevision();
    $entity->save();

    // Reload the entity.     $revision = $storage->loadRevision($revisionId);
    $this->drupalGet($revision->toUrl('revision-delete-form'));
    $this->assertSession()->pageTextContains($expectedQuestion);
    $this->assertSession()->buttonExists('Delete');
    $this->assertSession()->linkExists('Cancel');
  }

  /** * Data provider for testPageTitle. */
  public function providerPageTitle(): array {
    return [
      ['entity_test_rev', 'Are you sure you want to delete the revision?'],
      ['entity_test_revlog', 'Are you sure you want to delete the revision from Sun, 01/11/2009 - 16:00?'],
    ];
  }
// Check that the title and body fields are displayed with the correct values.     $this->assertSession()->fieldValueEquals('subject[0][value]', $edit['subject[0][value]']);
    $this->assertSession()->fieldValueEquals('comment_body[0][value]', $edit['comment_body[0][value]']);

    // Store the content of this page.     $this->submitForm([], 'Save');
    $this->assertSession()->pageTextContains('Your comment has been posted.');
    $this->assertSession()->elementsCount('xpath', '//section[contains(@class, "comments")]/article', 1);

    // Go back and re-submit the form.     $this->getSession()->getDriver()->back();
    $submit_button = $this->assertSession()->buttonExists('Save');
    $submit_button->click();
    $this->assertSession()->pageTextContains('Your comment has been posted.');
    $this->assertSession()->elementsCount('xpath', '//section[contains(@class, "comments")]/article', 2);
  }

  /** * Tests comment edit, preview, and save. */
  public function testCommentEditPreviewSave() {
    $web_user = $this->drupalCreateUser([
      'access comments',
      

  public function testRemoveDisplay() {
    $view = $this->randomView();
    $path_prefix = 'admin/structure/views/view/' . $view['id'] . '/edit';

    // Make sure there is no delete button on the default display.     $this->drupalGet($path_prefix . '/default');
    $this->assertSession()->buttonNotExists('edit-displays-settings-settings-content-tab-content-details-top-actions-delete');

    $this->drupalGet($path_prefix . '/page_1');
    $this->assertSession()->buttonExists('edit-displays-settings-settings-content-tab-content-details-top-actions-delete');

    // Delete the page, so we can test the undo process.     $this->drupalGet($path_prefix . '/page_1');
    $this->submitForm([], 'Delete Page');
    $this->assertSession()->buttonExists('edit-displays-settings-settings-content-tab-content-details-top-actions-undo-delete');
    // Test that the display link is marked as to be deleted.     $this->assertSession()->elementExists('xpath', "//a[contains(@href, '{$path_prefix}/page_1') and contains(@class, 'views-display-deleted-link')]");

    // Undo the deleting of the display.     $this->drupalGet($path_prefix . '/page_1');
    $this->submitForm([], 'Undo delete of Page');
    
// Test that text areas can contain new lines.     $this->assertSession()->fieldValueEquals('edit-test-textarea-with-newline', "Test text with\nnewline");
  }

  /** * Tests legacy field asserts for button field type. */
  public function testFieldAssertsForButton() {
    $this->drupalGet('test-field-xpath');

    // Verify if the test passes with button ID.     $this->assertSession()->buttonExists('edit-save');
    // Verify if the test passes with button Value.     $this->assertSession()->buttonExists('Save');
    // Verify if the test passes with button Name.     $this->assertSession()->buttonExists('op');

    // Verify if the test passes with button ID.     $this->assertSession()->buttonNotExists('i-do-not-exist');
    // Verify if the test passes with button Value.     $this->assertSession()->buttonNotExists('I do not exist');
    // Verify if the test passes with button Name.     $this->assertSession()->buttonNotExists('no');

    
    $entity
      ->setRevisionCreationTime((new \DateTimeImmutable('11 January 2009 5pm'))->getTimestamp())
      ->setRevisionTranslationAffected(TRUE)
      ->setNewRevision();
    $entity->save();

    // Reload the entity.     $revision = \Drupal::entityTypeManager()->getStorage('block_content')
      ->loadRevision($revisionId);
    $this->drupalGet($revision->toUrl('revision-delete-form'));
    $this->assertSession()->pageTextContains('Are you sure you want to delete the revision from Sun, 01/11/2009 - 16:00?');
    $this->assertSession()->buttonExists('Delete');
    $this->assertSession()->linkExists('Cancel');

    $countRevisions = static function D): int {
      return (int) \Drupal::entityTypeManager()->getStorage('block_content')
        ->getQuery()
        ->accessCheck(FALSE)
        ->allRevisions()
        ->count()
        ->execute();
    };

    
protected function visitInstaller() {
    // Place a custom local translation in the translations directory.     mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
    file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));

    // The unrouted URL assembler does not exist at this point, so we build the     // URL ourselves.     $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=' . $this->langcode);

    // The language should have been automatically detected, all following     // screens should be translated already.     $this->assertSession()->buttonExists('Save and continue de');
    $this->translations['Save and continue'] = 'Save and continue de';

    // Check the language direction.     $this->assertSession()->elementTextEquals('xpath', '/@dir', 'ltr');
  }

  /** * {@inheritdoc} */
  protected function setUpLanguage() {
    // The language was preset by passing a query parameter in the URL, so no
// Search for "Page One".     $session->getPage()->fillField('title', 'Page One');
    $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
    $this->assertSession()->assertWaitOnAjaxRequest();

    // Verify that only the "Page One" Node is present.     $html = $session->getPage()->getHtml();
    $this->assertStringContainsString('Page One', $html);
    $this->assertStringNotContainsString('Page Two', $html);

    // Close and re-open the modal.     $assert->buttonExists('Close', $dialog)->press();
    $assert->elementExists('named', ['link', 'Administer content'])->click();
    $assert->waitForElementVisible('css', '.views-test-modal');

    // Ensure that the Content we're testing for is present.     $html = $session->getPage()->getHtml();
    $this->assertStringContainsString('Page One', $html);
    $this->assertStringContainsString('Page Two', $html);

    // Search for "Page One".     $session->getPage()->fillField('title', 'Page One');
    $assert->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Filter');
    
// Set the state system to record installations and uninstallations.     \Drupal::state()->set('ConfigImportUITest.core.extension.modules_installed', []);
    \Drupal::state()->set('ConfigImportUITest.core.extension.modules_uninstalled', []);

    // Verify that both appear as ready to import.     $this->drupalGet('admin/config/development/configuration');
    $this->assertSession()->responseContains('<td>' . $name);
    $this->assertSession()->responseContains('<td>' . $dynamic_name);
    $this->assertSession()->responseContains('<td>core.extension');
    $this->assertSession()->responseContains('<td>system.theme');
    $this->assertSession()->responseContains('<td>automated_cron.settings');
    $this->assertSession()->buttonExists('Import all');

    // Import and verify that both do not appear anymore.     $this->submitForm([], 'Import all');
    $this->assertSession()->responseNotContains('<td>' . $name);
    $this->assertSession()->responseNotContains('<td>' . $dynamic_name);
    $this->assertSession()->responseNotContains('<td>core.extension');
    $this->assertSession()->responseNotContains('<td>system.theme');
    $this->assertSession()->responseNotContains('<td>automated_cron.settings');

    $this->assertSession()->buttonNotExists('Import all');

    

  protected function switchToWorkspace(WorkspaceInterface $workspace) {
    $this->assertTrue($this->switcherBlockConfigured, 'This test was not written correctly: you must call setupWorkspaceSwitcherBlock() before switchToWorkspace()');
    /** @var \Drupal\Tests\WebAssert $session */
    $session = $this->assertSession();
    $session->buttonExists('Activate');
    $this->submitForm(['workspace_id' => $workspace->id()], 'Activate');
    $session->pageTextContains($workspace->label() . ' is now the active workspace.');
    // Keep the test runner in sync with the system under test.     \Drupal::service('workspaces.manager')->setActiveWorkspace($workspace);
  }

  /** * Switches to the live version of the site for subsequent requests. * * This assumes that the switcher block has already been setup by calling * setupWorkspaceSwitcherBlock(). */
if ($contact !== NULL && is_array($contact)) {
      $edit += $contact;
    }
    switch ($preview_mode) {
      case DRUPAL_REQUIRED:
        // Preview required so no save button should be found.         $this->assertSession()->buttonNotExists('Save');
        $this->submitForm($edit, 'Preview');
        // Don't break here so that we can test post-preview field presence and         // function below.       case DRUPAL_OPTIONAL:
        $this->assertSession()->buttonExists('Preview');
        $this->assertSession()->buttonExists('Save');
        $this->submitForm($edit, 'Save');
        break;

      case DRUPAL_DISABLED:
        $this->assertSession()->buttonNotExists('Preview');
        $this->assertSession()->buttonExists('Save');
        $this->submitForm($edit, 'Save');
        break;
    }
    $match = [];
    
/** * Tests the media type creation form with only the mandatory options. */
  public function testMediaTypeCreationForm() {
    $machine_name = mb_strtolower($this->randomMachineName());

    $this->drupalGet('/admin/structure/media/add');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldExists('label')->setValue($this->randomString());
    $this->assertSession()->fieldExists('id')->setValue($machine_name);
    $this->assertSession()->selectExists('source')->selectOption('test');
    $this->assertSession()->buttonExists('Save')->press();
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldValueEquals('Test config value', 'This is default value.');
    $this->assertSession()->buttonExists('Save')->press();
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('admin/structure/media');

    $this->assertInstanceOf(MediaType::class, MediaType::load($machine_name));
  }

}
$media_type = MediaType::load($media_type_id);

    // Assert that the default display of the media type only shows the source     // field.     $this->drupalGet("/admin/structure/media/manage/$media_type_id/display");
    // There should be only one field with editable settings, and it should be     // the source field.     $assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
    $source_field_name = $media_type->getSource()
      ->getSourceFieldDefinition($media_type)
      ->getName();
    $assert_session->buttonExists("{$source_field_name}_settings_edit");
    // Ensure the source field label is configured as expected.     $assert_session->fieldValueEquals("fields[$source_field_name][label]", $source_label_visibility);

    // Bundle definitions are statically cached in the context of the test, we     // need to make sure we have updated information before proceeding with the     // actions on the UI.     \Drupal::service('entity_type.bundle.info')->clearCachedBundles();

    return $media_type;
  }

}
$this->submitForm([
      'body[0][value]' => 'Third version of the content.',
      'moderation_state[0][state]' => 'draft',
    ], 'Save (this translation)');

    $this->drupalGet($latest_version_path['language' => $french]);
    $this->assertSession()->elementExists('xpath', '//ul[@class="entity-moderation-form"]');

    $this->drupalGet($edit_path);
    $this->clickLink('Delete');
    $this->assertSession()->buttonExists('Delete');

    $this->drupalGet($latest_version_path);
    $this->assertSession()->elementNotExists('xpath', '//ul[@class="entity-moderation-form"]');

    // Publish the french pending revision (revision 4).     $this->drupalGet($edit_path['language' => $french]);
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
    $this->assertSession()->optionNotExists('moderation_state[0][state]', 'archived');
    $this->submitForm([
      'body[0][value]' => 'Fifth version of the content.',
      
$this->assertSession()->linkByHrefExists($file->createFileUrl());
      $this->assertSession()->linkByHrefExists('admin/content/files/usage/' . $file->id());
      $this->assertSession()->linkByHrefExists($file->toUrl('delete-form')->toString());
    }
    // Load the page in a definite order.     $this->drupalGet('admin/content/files', ['query' => ['order' => 'filename', 'sort' => 'asc']]);
    $this->clickLink('Delete');
    $file_uri = File::load(1)->getFileUri();
    $this->assertSession()->addressMatches('#file/1/delete$#');
    $this->assertSession()->pageTextContains('Are you sure you want to delete the file druplicon.txt?');
    $this->assertFileExists($file_uri);
    $this->assertSession()->buttonExists('Delete')->press();
    $this->assertSession()->pageTextContains('The file druplicon.txt has been deleted.');
    $this->assertFileDoesNotExist($file_uri);
  }

  /** * Tests file listing usage page for entities with no canonical link template. */
  public function testFileListingUsageNoLink() {
    // Login with user with right permissions and test listing.     $this->drupalLogin($this->adminUser);

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