waitForButton example

$this->drupalGet($resetURL);

    // Login     $this->submitForm([], 'Log in');

    // Generate file.     $image_file = current($this->drupalGetTestFiles('image'));
    $image_path = \Drupal::service('file_system')->realpath($image_file->uri);

    // Upload file.     $this->getSession()->getPage()->attachFileToField('Picture', $image_path);
    $this->assertSession()->waitForButton('Remove');

    // Change the forgotten password.     $password = \Drupal::service('password_generator')->generate();
    $edit = ['pass[pass1]' => $password, 'pass[pass2]' => $password];
    $this->submitForm($edit, 'Save');

    // Verify that the password reset session has been destroyed.     $this->submitForm($edit, 'Save');
    // Password needed to make profile changes.     $this->assertSession()->pageTextContains("Your current password is missing or incorrect; it's required to change the Password.");
  }

  
$assert_session = $this->assertSession();

    $test_file = current($this->getTestFiles('text'));
    $test_file_path = \Drupal::service('file_system')
      ->realpath($test_file->uri);

    $this->drupalGet("node/add/$type_name");
    foreach ([$field_name2$field_name] as $each_field_name) {
      for ($delta = 0; $delta < 3; $delta++) {
        $page->attachFileToField('files[' . $each_field_name . '_' . $delta . '][]', $test_file_path);
        $this->assertNotNull($assert_session->waitForElementVisible('css', '[name="' . $each_field_name . '_' . $delta . '_remove_button"]'));
        $this->assertNull($assert_session->waitForButton($each_field_name . '_' . $delta . '_upload_button'));
      }
    }

    $num_expected_remove_buttons = 6;

    foreach ([$field_name$field_name2] as $current_field_name) {
      // How many uploaded files for the current field are remaining.       $remaining = 3;
      // Test clicking each "Remove" button. For extra robustness, test them out       // of sequential order. They are 0-indexed, and get renumbered after each       // iteration, so array(1, 1, 0) means:

  protected function assertContextualLinks(): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->clickContextualLink('.block-field-blocknodebundle-for-this-particular-testbody', 'Configure');
    $this->waitForOffCanvasArea();
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertNotEmpty($this->assertSession()->waitForButton('Close'));
    $page->pressButton('Close');
    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
  }

  /** * Asserts that blocks in a given order in the page. * * @param string[] $items * An ordered list of strings that should appear in the blocks. * * @internal */
$page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_SIZE . "]", 'field_string_file_size');
    $page->selectFieldOption("field_map[" . File::METADATA_ATTRIBUTE_MIME . "]", 'field_string_mime_type');
    $page->pressButton('Save');

    $test_filename = $this->randomMachineName() . '.txt';
    $test_filepath = 'public://' . $test_filename;
    file_put_contents($test_filepath$this->randomMachineName());

    // Create a media item.     $this->drupalGet("media/add/{$media_type_id}");
    $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::service('file_system')->realpath($test_filepath));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->pressButton('Save');

    $assert_session->addressEquals('admin/content/media');

    // Get the media entity view URL from the creation message.     $this->drupalGet($this->assertLinkToCreatedMedia());

    // Make sure a link to the file is displayed.     $assert_session->linkExists($test_filename);
    // The thumbnail should not be displayed.
$test_link = $page->findButton('Add link');
    $test_field = $page->findButton('Add field');
    $test_id = $page->findButton('Add ID');
    $test_wait_on_ajax = $page->findButton('Test assertWaitOnAjaxRequest');
    $test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');

    // Test the wait...() methods by first checking the fields aren't available     // and then are available after the wait method.     $result = $page->findButton('Added button');
    $this->assertEmpty($result);
    $test_button->click();
    $result = $assert_session->waitForButton('Added button');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findLink('Added link');
    $this->assertEmpty($result);
    $test_link->click();
    $result = $assert_session->waitForLink('Added link');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findField('added_field');
    
file_put_contents($test_filepath_updatedstr_repeat('u', 10));

    // Check if the name field is properly hidden on the media form.     $this->drupalGet('media/add/audio');
    $assert_session->fieldNotExists('name');

    // Check if the source field is available.     $assert_session->fieldExists("files[{$source_field_id}_0]");

    // Create a media item.     $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::service('file_system')->realpath($test_filepath));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->pressButton('Save');
    $audio_media_id = $this->container
      ->get('entity_type.manager')
      ->getStorage('media')
      ->getQuery()
      ->accessCheck(FALSE)
      ->sort('mid', 'DESC')
      ->execute();
    $audio_media_id = reset($audio_media_id);

    
$this->drupalGet('media/' . $media->id());
    // Verify the name is present, and its text matches what is expected. Now     // there should be markup in the h1.     $assert_session->elementTextContains('xpath', '//h1/div/div[1]', 'Name');
    $assert_session->elementTextContains('xpath', '//h1/div/div[2]', $media->getName());

    // In the standard profile, there are some pre-cooked types. Make sure the     // elements configured on their displays are the expected ones.     $this->drupalGet('media/add/image');
    $image_media_name = 'example_1.jpeg';
    $page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/' . $image_media_name);
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->fillField('field_media_image[0][alt]', 'Image Alt Text 1');
    $page->pressButton('Save');
    $image_media_id = $this->container
      ->get('entity_type.manager')
      ->getStorage('media')
      ->getQuery()
      ->accessCheck(FALSE)
      ->sort('mid', 'DESC')
      ->execute();
    $image_media_id = reset($image_media_id);

    
// Create a media asset.     file_put_contents('public://file.mp3', str_repeat('t', 10));
    $file = File::create([
      'uri' => 'public://file.mp3',
      'filename' => 'file.mp3',
    ]);
    $file->save();

    $this->drupalGet("media/add/$type_name");
    $page->fillField('Name', 'Audio media asset');
    $page->attachFileToField("files[{$field_name}_0]", \Drupal::service('file_system')->realpath('public://file.mp3'));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->pressButton('Save');

    // Verify that there is a creation message and that it contains a link to     // the media entity.     $assert_session->pageTextContains("$type_name Audio media asset has been created.");
    $this->drupalGet($this->assertLinkToCreatedMedia());

    // Verify that the <audio> tag is present on the media entity view.     $assert_session->elementExists('css', "audio > source[type='audio/mpeg']");
  }

  
\Drupal::service('theme_installer')->install([$theme]);

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet("admin/appearance/settings/$theme");

    // Add a new managed file.     $file = current($this->getTestFiles('image'));
    $image_file_path = \Drupal::service('file_system')->realpath($file->uri);
    $page->attachFileToField('files[custom_logo]', $image_file_path);
    $assert_session->waitForButton('custom_logo_remove_button');

    // Assert the new file is uploaded as temporary. This file should not be     // saved as permanent if settings are not submitted.     $image_field = $this->assertSession()->hiddenFieldExists('custom_logo[fids]');
    $file = File::load($image_field->getValue());
    $this->assertFalse($file->isPermanent());

    $page->pressButton('Save configuration');
    \Drupal::entityTypeManager()->getStorage('file')->resetCache();

    // Assert the uploaded file is saved as permanent.
    $opt1_selector = $this->assertSession()->waitForElement('css', "select[data-drupal-selector='edit-test1'] option:contains('Option 1!!!')");
    $this->assertNotEmpty($opt1_selector);
    $this->assertTrue($opt1_selector->isSelected());

    // Confirm option 3 exists.     $page = $session->getPage();
    $opt3_selector = $page->find('xpath', '//select[@data-drupal-selector="edit-test1"]//option[@value="option3"]');
    $this->assertNotEmpty($opt3_selector);

    // Confirm success message appears after a submit.     $page->findButton('edit-submit')->click();
    $this->assertSession()->waitForButton('edit-submit');
    $updated_page = $session->getPage();
    $updated_page->hasContent('Submission successful.');
  }

  /** * Tests AJAX forms on pages with a query string. */
  public function testQueryString() {
    $this->container->get('module_installer')->install(['block']);
    $this->drupalLogin($this->rootUser);

    
// Hide the name field widget to test default name generation.     $this->hideMediaTypeFieldWidget('name', $media_type_id);

    $this->drupalGet("admin/structure/media/manage/{$media_type_id}");
    $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_WIDTH . "]", 'field_string_width');
    $page->selectFieldOption("field_map[" . Image::METADATA_ATTRIBUTE_HEIGHT . "]", 'field_string_height');
    $page->pressButton('Save');

    // Create a media item.     $this->drupalGet("media/add/{$media_type_id}");
    $page->attachFileToField("files[{$source_field_id}_0]", $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1');
    $page->pressButton('Save');

    $assert_session->addressEquals('admin/content/media');

    // Get the media entity view URL from the creation message.     $this->drupalGet($this->assertLinkToCreatedMedia());

    // Assert the image element is present inside the media element and that its     // src attribute uses the large image style, the label is visually hidden,
Home | Imprint | This part of the site doesn't use cookies.