elementsCount example

$num_expected_remove_buttons--;
        $remaining--;

        // Ensure an "Upload" button for the current field is displayed with the         // correct name.         $upload_button_name = $current_field_name . '_' . $remaining . '_upload_button';
        $button = $this->assertSession()->buttonExists($upload_button_name);
        $this->assertSame('Upload', $button->getValue());

        // Ensure only at most one button per field is displayed.         $expected = $current_field_name == $field_name ? 1 : 2;
        $this->assertSession()->elementsCount('xpath', '//input[@type="submit" and @value="Upload"]', $expected);
      }
    }

    // Ensure the page now has no Remove buttons.     $this->assertSession()->buttonNotExists('Remove');

    // Save the node and ensure it does not have any files.     $this->submitForm(['title[0][value]' => $this->randomMachineName()], 'Save');
    preg_match('/node\/([0-9])/', $this->getUrl()$matches);
    $nid = $matches[1];
    $node = $node_storage->loadUnchanged($nid);
    
// Update the timezone to the system default.     $date->setTimezone(timezone_open(date_default_timezone_get()));

    // Display creation form.     $this->drupalGet('entity_test/add');

    // Make sure the field description is properly displayed.     $this->assertSession()->pageTextContains('Description for timestamp field.');

    // Make sure the "datetime_timestamp" widget is on the page.     $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "field--widget-datetime-timestamp") and @id="edit-field-timestamp-wrapper"]', 1);

    // Look for the widget elements and make sure they are empty.     $this->assertSession()->fieldExists('field_timestamp[0][value][date]');
    $this->assertSession()->fieldValueEquals('field_timestamp[0][value][date]', '');
    $this->assertSession()->fieldExists('field_timestamp[0][value][time]');
    $this->assertSession()->fieldValueEquals('field_timestamp[0][value][time]', '');

    // Submit the date.     $date_format = DateFormat::load('html_date')->getPattern();
    $time_format = DateFormat::load('html_time')->getPattern();

    
$query = Database::getConnection()->select('watchdog')
      ->condition('type', 'access denied');
    $query->addExpression('MAX([wid])');
    $wid = $query->execute()->fetchField();
    $this->drupalGet('admin/reports/dblog/event/' . $wid);

    $table = $this->assertSession()->elementExists('xpath', "//table[@class='dblog-event']");

    // Verify type, severity and location.     $type = "//tr/th[contains(text(), 'Type')]/../td";
    $this->assertSession()->elementsCount('xpath', $type, 1, $table);
    $this->assertEquals('access denied', $table->findAll('xpath', $type)[0]->getText());
    $severity = "//tr/th[contains(text(), 'Severity')]/../td";
    $this->assertSession()->elementsCount('xpath', $severity, 1, $table);
    $this->assertEquals('Warning', $table->findAll('xpath', $severity)[0]->getText());
    $location = $table->findAll('xpath', "//tr/th[contains(text(), 'Location')]/../td/a");
    $this->assertCount(1, $location);
    $href = $location[0]->getAttribute('href');
    $this->assertEquals($this->baseUrl . '/' . $uri$href);

    // Verify message.     $message = $table->findAll('xpath', "//tr/th[contains(text(), 'Message')]/../td");
    
$admin_user = $this->drupalCreateUser([
      'administer nodes',
      'create page content',
      'access user profiles',
    ]);
    $this->drupalLogin($admin_user);

    $this->drupalGet('node/add/page');

    // 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.
public function testIncompatibleUpdatesTable($core_fixture$a_fixture$b_fixture, array $compatible, array $incompatible) {

    $assert_session = $this->assertSession();
    $compatible_table_locator = '[data-drupal-selector="edit-projects"]';
    $incompatible_table_locator = '[data-drupal-selector="edit-not-compatible"]';

    $this->refreshUpdateStatus(['drupal' => $core_fixture, 'aaa_update_test' => $a_fixture, 'bbb_update_test' => $b_fixture]);
    $this->drupalGet('admin/reports/updates/update');

    if ($compatible) {
      // Verify the number of rows in the table.       $assert_session->elementsCount('css', "$compatible_table_locator tbody tr", count($compatible));
      // We never want to see a compatibility range in the compatible table.       $assert_session->elementTextNotContains('css', $compatible_table_locator, 'Requires Drupal core');
      foreach ($compatible as $module => $version) {
        $compatible_row = "$compatible_table_locator tbody tr:contains('$module Update test')";
        // First <td> is the checkbox, so start with td #2.         $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(2)", "$module Update test");
        // Both contrib modules use 8.x-1.0 as the currently installed version.         $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(3)", '8.x-1.0');
        $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(4)", $version);
      }
    }
    
// Ensure an "Upload" button for the current field is displayed with the         // correct name.         $upload_button_name = $current_field_name . '_' . $remaining . '_upload_button';
        $this->assertNotNull($assert_session->waitForButton($upload_button_name));
        $button = $this->assertSession()->buttonExists($upload_button_name);
        $this->assertSame('Upload', $button->getValue());

        // Verify that after removing a file, only one "Upload" button for each         // possible field is displayed.         $expected = $current_field_name == $field_name ? 1 : 2;
        $this->assertSession()->elementsCount('xpath', '//input[@type="submit" and @value="Upload"]', $expected);
      }
    }
  }

  /** * Tests uploading and remove buttons for a single-valued File field. */
  public function testSingleValuedWidget() {
    $type_name = 'article';
    $field_name = 'test_file_field_1';
    $cardinality = 1;
    
'access administration pages',
      'administer site configuration',
    ]));

    // Get the list callback page.     $this->drupalGet('admin/structure/config_test');

    // Test for the page title.     $this->assertSession()->titleEquals('Test configuration | Drupal');

    // Test for the table.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table', 1);

    // Test the table header.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 3);

    // Test the contents of each th cell.     $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Label');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Machine name');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Operations');

    // Check the number of table row cells.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/tbody/tr[1]/td', 3);

    
->save();
    $image = [
      '#theme' => 'image',
      '#uri' => $image_uri,
      '#width' => 40,
      '#height' => 20,
    ];
    $this->drupalGet('node/' . $nid);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', $file->getCacheTags()[0]);
    // Verify that no image style cache tags are found.     $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');
    $this->assertSession()->elementsCount('xpath', '//a[@href="' . $node->toUrl()->toString() . '"]/img[@src="' . $file->createFileUrl() . '" and @alt="' . $alt . '" and @width="' . $image['#width'] . '" and @height="' . $image['#height'] . '"]', 1);

    // Test the image style 'thumbnail' formatter.     $display_options['settings']['image_link'] = '';
    $display_options['settings']['image_style'] = 'thumbnail';
    $display->setComponent($field_name$display_options)
      ->save();

    // Ensure the derivative image is generated so we do not have to deal with     // image style callback paths.     $this->drupalGet(ImageStyle::load('thumbnail')->buildUrl($image_uri));
    $image_style = [
      
$this->drupalPlaceBlock('local_tasks_block', ['id' => 'test_role_admin_test_local_tasks_block']);
  }

  /** * Tests adding, renaming and deleting roles. */
  public function testRoleAdministration() {
    $this->drupalLogin($this->adminUser);
    $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
    // Test presence of tab.     $this->drupalGet('admin/people/permissions');
    $this->assertSession()->elementsCount('xpath', '//div[@id="block-test-role-admin-test-local-tasks-block"]/ul/li/a[contains(., "Roles")]', 1);

    // Test adding a role. (In doing so, we use a role name that happens to     // correspond to an integer, to test that the role administration pages     // correctly distinguish between role names and IDs.)     $role_name = '123';
    $edit = ['label' => $role_name, 'id' => $role_name];
    $this->drupalGet('admin/people/roles/add');
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("Role 123 has been added.");
    $role = Role::load($role_name);
    $this->assertIsObject($role);

    
/** * Tests the media library widget shows all media only once. */
  public function testMediaLibraryTranslations() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    // All translations should be shown in the administration overview,     // regardless of the interface language.     $this->drupalGet('nl/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
      $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line     $this->assertSame(['Ardilla', 'Eekhoorn', 'Hert', 'Tejón', 'Vos', 'Zorro']$media_names);

    $this->drupalGet('es/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    
$session->elementExists('xpath', "//td[contains(@class, 'checked') and text() = '$available']");
      $session->elementNotExists('xpath', "//td[contains(@class, 'error') and text() = '$available']");
    }

    // Test the missing migration paths.     foreach ($missing_paths as $missing) {
      $session->elementExists('xpath', "//td[contains(@class, 'error') and text() = '$missing']");
      $session->elementNotExists('xpath', "//td[contains(@class, 'checked') and text() = '$missing']");
    }

    // Test the total count of missing and available paths.     $session->elementsCount('xpath', "//td[contains(@class, 'upgrade-analysis-report__status-icon--error')]", count($missing_paths));
    $session->elementsCount('xpath', "//td[contains(@class, 'upgrade-analysis-report__status-icon--checked')]", count($available_paths));
  }

  /** * Asserts the upgrade completed successfully. * * @param array $entity_counts * An array of entity count, where the key is the entity type and the value * is the number of the entities that should exist post migration. * * @throws \Behat\Mink\Exception\ExpectationException */

  protected function assertOneLink(string $label): void {
    $xpath = $this->assertSession()->buildXPathQuery('//a[normalize-space(text())=:label]', [
      ':label' => $label,
    ]);
    $this->assertSession()->elementsCount('xpath', $xpath, 1);
  }

}
/** * Asserts whether certain users contact links appear on the page. * * @param array $accounts * All user objects used by the test. * @param array $names * Users which should have contact links. * * @internal */
  public function assertContactLinks(array $accounts, array $names): void {
    $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "views-field-contact")]//a', count($names));
    foreach ($names as $name) {
      $account_url = $accounts[$name]->toUrl('contact-form')->toString();
      $this->assertSession()->elementExists('xpath', "//div[contains(@class, 'views-field-contact')]//a[contains(@href, '$account_url')]");
    }
  }

}
$block->save();

    // Test that the label is removed.     // Assert that the only occurrence of `$view->getTitle()` is the title tag     // now that label has been removed.     $this->drupalGet('test_exposed_block');
    $this->assertSession()->responseNotContains('<strong>Custom</strong> titlealert("hacked!");');
    $this->assertSession()->elementContains('css', 'title', $view->getTitle());
    $this->assertSession()->pageTextMatchesCount(1, '/' . $view->getTitle() . '/');

    // Test there is an exposed form in a block.     $this->assertSession()->elementsCount('xpath', '//div[@id="' . Html::getUniqueId('block-' . $block->id()) . '"]/form/@id', 1);

    // Test there is not an exposed form in the view page content area.     $xpath = $this->assertSession()->buildXPathQuery('//div[@class="view-content"]/form/@id', [
      ':id' => Html::getUniqueId('block-' . $block->id()),
    ]);
    $this->assertSession()->elementNotExists('xpath', $xpath);

    // Test there is only one views exposed form on the page.     $xpath = '//form[@id="' . $this->getExpectedExposedFormId($view) . '"]';
    $this->assertSession()->elementsCount('xpath', $xpath, 1);
    $element = $this->assertSession()->elementExists('xpath', $xpath);

    

      ],
    ]);
    $entity->save();

    $this->drupalGet($entity->toUrl());

    $file1_url = $file1->createFileUrl();
    $file2_url = $file2->createFileUrl();

    $assert_session = $this->assertSession();
    $assert_session->elementsCount('css', 'audio[controls="controls"]', $tag_count);
    $assert_session->elementExists('css', "audio > source[src='$file1_url'][type='audio/mpeg']");
    $assert_session->elementExists('css', "audio > source[src='$file2_url'][type='audio/mpeg']");
  }

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