findField example

public function testResponsiveImageFormatterUi() {
    $manage = 'admin/structure/types/manage/' . $this->type;
    $add_field = $manage . '/fields/add-field';
    $manage_display = $manage . '/display';
    $assert_session = $this->assertSession();

    // Create a field, and a node with some data for the field.     // Create the field.     $this->drupalGet($add_field);

    $page = $this->getSession()->getPage();
    $storage_type = $page->findField('edit-new-storage-type');
    $storage_type->setValue('image');

    // Set the label.     $label = $page->findField('edit-label');
    $label->setValue('Image');

    // Wait for the machine name.     $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');

    // Save the current page.     $save_button = $page->findButton('Save and continue');
    
'type' => 'timestamp',
    ]);
    $timestamp_field_storage->save();
    $timestamp_field = FieldConfig::create([
      'field_storage' => $timestamp_field_storage,
      'bundle' => 'user',
      'label' => 'Timestamp',
    ]);
    $timestamp_field->save();

    $this->drupalGet('admin/structure/block/add/field_block_test%3Auser%3Auser%3Afield_timestamp/starterkit_theme');
    $this->assertFalse($page->findField('settings[formatter][settings][custom_date_format]')->isVisible(), 'Custom date format is not visible');
    $page->selectFieldOption('settings[formatter][settings][date_format]', 'custom');
    $this->assertTrue($page->findField('settings[formatter][settings][custom_date_format]')->isVisible(), 'Custom date format is visible');
  }

}
$this->assertHtmlEsqueFieldValueEquals('filters[filter_html][settings][allowed_html]', '<br> <p> <h2> <h3> <h4> <h5> <h6> <aside> <strong> <em> <blockquote>');
    $allowed_html_field = $assert_session->fieldExists('filters[filter_html][settings][allowed_html]');
    $this->assertTrue($allowed_html_field->hasAttribute('readonly'));

    // Adding tags to Source Editing's editable tags that are already supported     // by enabled CKEditor 5 plugins must trigger a validation error, and that     // error must be associated with the correct form item.     $source_edit_tags_field->setValue('<aside><strong>');
    $assert_session->waitForText('The following tag(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Bold (<strong>)');
    $this->assertTrue($page->find('css', '[href^="#edit-editor-settings-plugins-ckeditor5-sourceediting"]')->getParent()->hasClass('is-selected'));
    $this->assertSame('true', $page->findField('editor[settings][plugins][ckeditor5_sourceEditing][allowed_tags]')->getAttribute('aria-invalid'));
    $this->assertTrue($allowed_html_field->hasAttribute('readonly'));

    // The same validation error appears when saving the form regardless of the     // immediate AJAX validation error above.     $page->pressButton('Save configuration');
    $assert_session->pageTextContains('The following tag(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Bold (<strong>)');
    $this->assertTrue($page->find('css', '[href^="#edit-editor-settings-plugins-ckeditor5-sourceediting"]')->getParent()->hasClass('is-selected'));
    $this->assertSame('true', $page->findField('editor[settings][plugins][ckeditor5_sourceEditing][allowed_tags]')->getAttribute('aria-invalid'));
    $assert_session->pageTextNotContains('The text format ckeditor5 has been updated');

    // Wait for the "Source editing" vertical tab to appear, remove the already
    // video ID that will not be filtered by the regex, because otherwise the     // message 'No matching provider found.' will be returned.     $page->fillField('Add Type Five via URL', 'https://www.youtube.com/watch?v=PWjcqE3QKBg1');
    $page->pressButton('Add');
    // assertWaitOnAjaxRequest() required for input "id" attributes to     // consistently match their label's "for" attribute.     $assert_session->assertWaitOnAjaxRequest();
    $this->waitForText('Could not retrieve the oEmbed resource.');

    // Select a media item to check if the selection is persisted when adding     // new items.     $checkbox = $page->findField("Select $youtube_title");
    $selected_item_id = $checkbox->getAttribute('value');
    $checkbox->click();
    $assert_session->pageTextContains('1 item selected');
    $assert_session->hiddenFieldValueEquals('current_selection', $selected_item_id);

    // Assert we can add a oEmbed video with a custom name.     $page->fillField('Add Type Five via URL', $youtube_url);
    $page->pressButton('Add');
    // assertWaitOnAjaxRequest() required for input "id" attributes to     // consistently match their label's "for" attribute.     $assert_session->assertWaitOnAjaxRequest();
    
/** * Submits forms with select and checkbox elements via Ajax. */
  public function testSimpleAjaxFormValue() {
    $this->drupalGet('/ajax_forms_test_get_form');

    $assert_session = $this->assertSession();
    $assert_session->responseContains('Test group');
    $assert_session->responseContains('AJAX checkbox in a group');

    $session = $this->getSession();
    $checkbox_original = $session->getPage()->findField('checkbox_in_group');
    $this->assertNotNull($checkbox_original, 'The checkbox_in_group is on the page.');
    $original_id = $checkbox_original->getAttribute('id');

    // Triggers an AJAX request/response.     $checkbox_original->check();

    // The response contains a new nested "test group" form element, similar     // to the one already in the DOM except for a change in the form build id.     $checkbox_new = $assert_session->waitForElement('xpath', "//input[@name='checkbox_in_group' and not(@id='$original_id')]");
    $this->assertNotNull($checkbox_new, 'DOM update: clicking the checkbox refreshed the checkbox_in_group structure');

    

  public function testCheckboxLogic() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $this->drupalGet('admin/structure/types/manage/before/display/default');
    // Both fields are unchecked and allow_custom is disabled and hidden.     $assert_session->checkboxNotChecked('layout[enabled]');
    $assert_session->checkboxNotChecked('layout[allow_custom]');
    $assert_session->fieldDisabled('layout[allow_custom]');
    $this->assertFalse($page->findField('layout[allow_custom]')->isVisible());

    // Checking is_enable will show allow_custom.     $page->checkField('layout[enabled]');
    $assert_session->checkboxNotChecked('layout[allow_custom]');
    $this->assertTrue($page->findField('layout[allow_custom]')->isVisible());
    $page->pressButton('Save');
    $assert_session->checkboxChecked('layout[enabled]');
    $assert_session->checkboxNotChecked('layout[allow_custom]');

    // Check and submit allow_custom.     $page->checkField('layout[allow_custom]');
    
    $page->fillField('Name', 'Dog');
    $page->pressButton('Apply filters');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContains('Dog');
    $assert_session->pageTextNotContains('Crocodile');
    $assert_session->pageTextNotContains('Turtle');
    $page->checkField('Select Dog');
    $assert_session->linkExists('Table');
    $this->switchToMediaLibraryGrid();

    // Assert the exposed filters are persisted when changing display.     $this->assertSame('Dog', $page->findField('Name')->getValue());
    $assert_session->pageTextContains('Dog');
    $assert_session->pageTextNotContains('Crocodile');
    $assert_session->pageTextNotContains('Turtle');
    $assert_session->linkExists('Grid');
    $this->switchToMediaLibraryTable();

    // Select the item.     $this->pressInsertSelected('Added one media item.');
    // Ensure that the selection completed successfully.     $assert_session->pageTextContains('Dog');
    $assert_session->pageTextContains('Bear');
    
/** * Tests the 'Add more' functionality. */
  public function testFieldFormJsAddMore() {
    $this->drupalGet('entity_test/add');

    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $add_more_button = $page->findButton('field_unlimited_add_more');

    // First set a value on the first input field.     $field_0 = $page->findField('field_unlimited[0][value]');
    $field_0->setValue('1');

    // Add another item.     $add_more_button->click();
    $field_1 = $assert_session->waitForField('field_unlimited[1][value]');
    $this->assertNotEmpty($field_1, 'Successfully added another item.');

    // Validate the value of the first field has not changed.     $this->assertEquals('1', $field_0->getValue(), 'Value for the first item has not changed.');

    // Validate the value of the second item is empty.
$this->doNestedTriggerTests();
  }

  /** * Tests states of elements triggered by a checkbox element. */
  protected function doCheckboxTriggerTests() {
    $this->drupalGet('form-test/javascript-states-form');
    $page = $this->getSession()->getPage();

    // Find trigger and target elements.     $trigger = $page->findField('checkbox_trigger');
    $this->assertNotEmpty($trigger);
    $textfield_invisible_element = $page->findField('textfield_invisible_when_checkbox_trigger_checked');
    $this->assertNotEmpty($textfield_invisible_element);
    $textfield_required_element = $page->findField('textfield_required_when_checkbox_trigger_checked');
    $this->assertNotEmpty($textfield_required_element);
    $textfield_readonly_element = $page->findField('textfield_readonly_when_checkbox_trigger_checked');
    $this->assertNotEmpty($textfield_readonly_element);
    $textarea_readonly_element = $page->findField('textarea_readonly_when_checkbox_trigger_checked');
    $this->assertNotEmpty($textarea_readonly_element);
    $details = $this->assertSession()->elementExists('css', '#edit-details-expanded-when-checkbox-trigger-checked');
    $textfield_in_details = $details->findField('textfield_in_details');
    
// Display the "Manage display" screen and check that the expected formatter     // is selected.     $this->drupalGet($manage_display);

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

    // Find commonly used elements in this test.     $button_save = $page->findButton('Save');
    $field_test_format_type = $page->findField('fields[field_test][type]');
    $field_test_drag_handle = $page->find('css', '#field-test .tabledrag-handle');
    $field_test_settings = $page->find('css', 'input[name="field_test_settings_edit"]');
    $weight_toggle = $page->find('css', '.tabledrag-toggle-weight');

    // Assert the format type field is visible and contains the expected     // formatter.     $this->assertTrue($field_test_format_type->isVisible());
    $this->assertEquals($format$field_test_format_type->getValue());
    $assert_session->responseContains("$setting_name: $setting_value");

    // Validate the selectbox.

  protected function addInlineFileBlockToLayout($title, File $file) {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $page->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertNotEmpty($assert_session->waitForLink('Create content block'));
    $this->clickLink('Create content block');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->fieldValueEquals('Title', '');
    $page->findField('Title')->setValue($title);
    $this->attachFileToBlockForm($file);
    $page->pressButton('Add block');
    $this->assertDialogClosedAndTextVisible($file->label()static::INLINE_BLOCK_LOCATOR);
  }

  /** * Creates a private file. * * @param string $file_name * The file name. * * @return \Drupal\Core\Entity\EntityInterface|\Drupal\file\Entity\File * The file entity. */
$this->assertSaveLayout();
    $this->drupalGet('node/1');

    $assert_session->pageTextContains('The DEFAULT block body');

    /** @var \Drupal\node\NodeStorageInterface $node_storage */
    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    $original_revision_id = $node_storage->getLatestRevisionId(1);

    // Create a new revision.     $this->drupalGet('node/1/edit');
    $page->findField('title[0][value]')->setValue('Node updated');
    $page->pressButton('Save');

    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The DEFAULT block body');

    $assert_session->linkExists('Revisions');

    // Update the block.     $this->drupalGet('node/1/layout');
    $this->configureInlineBlock('The DEFAULT block body', 'The NEW block body');
    $this->assertSaveLayout();
    
/** * Tests that filter results announcement has correct pluralization. */
  public function testModuleFilter() {

    // Find the module filter field.     $this->drupalGet('admin/modules');
    $assertSession = $this->assertSession();
    $session = $this->getSession();
    $page = $session->getPage();

    $filter = $page->findField('edit-text');

    // Get all module rows, for assertions later.     $module_rows = $page->findAll('css', '.package-listing tbody tr td.module');

    // Test module filter reduces the number of visible rows.     $filter->setValue('test');
    $session->wait(1000, 'jQuery("#module-node:visible").length == 0');
    $visible_rows = $this->filterVisibleElements($module_rows);
    // Test Drupal.announce() message when multiple matches are expected.     $expected_message = count($visible_rows) . ' modules are available in the modified list.';
    $assertSession->elementTextContains('css', '#drupal-live-announce', $expected_message);
    
$this->drupalGet('admin/content');
    $this->assertSession()->pageTextContains($node_1->getTitle());

    // Create second node now that the admin overview has been rendered.     $node_2 = $this->drupalCreateNode([
      'type' => 'page',
      'title' => 'The second node',
      'changed' => \Drupal::time()->getRequestTime() - 120,
    ]);

    // Select the node deletion action.     $action_select = $this->getSession()->getPage()->findField('edit-action');
    $action_select_name = $action_select->getAttribute('name');
    $this->getSession()->getPage()->selectFieldOption($action_select_name, 'node_delete_action');

    // Now click 'Apply to selected items' and assert the first node is selected     // on the confirm form.     $this->submitForm(['node_bulk_form[0]' => TRUE], 'Apply to selected items');
    $this->assertSession()->pageTextContains($node_1->getTitle());
    $this->assertSession()->pageTextNotContains($node_2->getTitle());

    // Change the pager limit to 2.     $this->config('views.view.content')->set('display.default.display_options.pager.options.items_per_page', 2)->save();

    
/** * Tests creating a View using the wizard. */
  public function testCreateViewWizard() {
    $this->drupalGet('admin/structure/views/add');
    $page = $this->getSession()->getPage();

    // Set a view name, this should be used to prepopulate a number of other     // fields when creating displays.     $label_value = 'test view';
    $search_input = $page->findField('label');
    $search_input->setValue($label_value);

    $page->findField('page[create]')->click();

    // Test if the title and path have been populated.     $this->assertEquals($label_value$page->findField('page[title]')->getValue());
    $this->assertEquals(str_replace(' ', '-', $label_value)$page->findField('page[path]')->getValue());

    // Create a menu item.     $page->findField('page[link]')->click();
    $this->assertEquals($label_value$page->findField('page[link_properties][title]')->getValue());

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