hiddenFieldValueEquals example

$this->assertSession()->statusCodeEquals(200);

    // Ensure the form and text field exist.     $this->assertSession()->elementExists('css', 'form#form-test-form-test-object');
    $this->assertSession()->fieldExists('bananas');

    // Check that the hidden field exists and has a specific value.     $this->assertSession()->hiddenFieldExists('strawberry');
    $this->assertSession()->hiddenFieldExists('red');
    $this->assertSession()->hiddenFieldExists('redstrawberryhiddenfield');
    $this->assertSession()->hiddenFieldValueNotEquals('strawberry', 'brown');
    $this->assertSession()->hiddenFieldValueEquals('strawberry', 'red');

    // Check that a hidden field does not exist.     $this->assertSession()->hiddenFieldNotExists('bananas');
    $this->assertSession()->hiddenFieldNotExists('pineapple');

    $edit = ['bananas' => 'green'];
    $this->submitForm($edit, 'Save', 'form-test-form-test-object');

    $config_factory = $this->container->get('config.factory');
    $value = $config_factory->get('form_test.object')->get('bananas');
    $this->assertSame('green', $value);

    
// 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();
    $this->waitForText('The media item has been created but has not yet been saved.');
    $page->fillField('Name', 'Custom video title');
    // The non-advanced ui should not show the Additional selected media.     $assert_session->pageTextNotContains('Additional selected media');
    
$entity_1 = $storage->create();
    $entity_1->save();

    $entity_2 = $storage->create();
    $entity_2->save();

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

    // Display the 'combined form'.     $this->drupalGet("test-entity-constraints/nested/{$entity_1->id()}/{$entity_2->id()}");
    $assert_session->hiddenFieldValueEquals('entity_2[changed]', REQUEST_TIME);

    // Submit the form and check that the entities are updated accordingly.     $assert_session->hiddenFieldExists('entity_2[changed]')
      ->setValue(REQUEST_TIME - 86400);
    $page->pressButton('Save');

    $elements = $this->cssSelect('.entity-2.error');
    $this->assertCount(1, $elements, 'The whole nested entity form has been correctly flagged with an error class.');
  }

}
$display_repository->getFormDisplay('node', 'page')
      ->setComponent($field_name$widget_settings)
      ->save();
    $display_repository->getViewDisplay('node', 'page')
      ->setComponent($field_name)
      ->save();

    // Confirm the defaults are present on the article field storage settings     // form.     $field_id = $field->id();
    $this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage']->id());
    // Confirm the defaults are present on the article field edit form.     $this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field']->id());

    // Confirm the defaults are present on the page field storage settings form.     $this->drupalGet("admin/structure/types/manage/page/fields/$field_id/storage");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage']->id());
    // Confirm the defaults are present on the page field edit form.     $field2_id = $field2->id();
    $this->drupalGet("admin/structure/types/manage/page/fields/$field2_id");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field2']->id());

    

  protected function assertTableRow(NodeElement $row, string $id, int $weight, string $parent = '', int $indentation = 0, ?bool $changed = FALSE, bool $skip_missing = FALSE): void {
    // Assert that the row position is correct by checking that the id     // corresponds.     $id_name = "table[$id][id]";
    if (!$skip_missing || $row->find('hidden_field_selector', ['hidden_field', $id_name])) {
      $this->assertSession()->hiddenFieldValueEquals($id_name$id$row);
    }
    $parent_name = "table[$id][parent]";
    if (!$skip_missing || $row->find('hidden_field_selector', ['hidden_field', $parent_name])) {
      $this->assertSession()->hiddenFieldValueEquals($parent_name$parent$row);
    }
    $this->assertSession()->fieldValueEquals("table[$id][weight]", $weight$row);
    $this->assertSession()->elementsCount('xpath', static::$indentationXpathSelector$indentation$row);
    // A row is marked as changed when the related markup is present.     if ($changed !== NULL) {
      $this->assertSession()->elementsCount('xpath', static::$tabledragChangedXpathSelector(int) $changed$row);
    }
  }
$this->selectMediaItem(0);
    $this->pressInsertSelected('Added one media item.');

    // Assert that the media type menu is not available when only 1 type is     // configured for the field.     $this->openMediaLibraryForField('field_single_media_type', '#media-library-wrapper');
    $this->waitForElementTextContains('.media-library-selected-count', '0 of 1 item selected');

    // Select a media item, assert the hidden selection field contains the ID of     // the selected item.     $this->selectMediaItem(0);
    $assert_session->hiddenFieldValueEquals('media-library-modal-selection', '4');
    $this->assertSelectedMediaCount('1 of 1 item selected');
    $assert_session->elementNotExists('css', '.js-media-library-menu');
    $assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();

    // Assert the menu links can be sorted through the widget configuration.     $this->openMediaLibraryForField('field_twin_media');
    $links = $this->getTypesMenu()->findAll('css', 'a');
    $link_titles = [];
    foreach ($links as $link) {
      $link_titles[] = $link->getText();
    }
    
// Load the created media item.     $media_items = Media::loadMultiple();
    $added_media = array_pop($media_items);
    // Ensure the media item was saved to the library and automatically     // selected. The added media items should be in the first position of the     // add form.     $assert_session->pageTextContains('Add or select media');
    $assert_session->pageTextContains($png_image->filename);
    $assert_session->fieldValueEquals('media_library_select_form[0]', $added_media->id());
    $assert_session->checkboxChecked('media_library_select_form[0]');
    $assert_session->pageTextContains('1 of 2 items selected');
    $assert_session->hiddenFieldValueEquals('current_selection', $added_media->id());
    // Ensure the created item is added in the widget.     $this->pressInsertSelected('Added one media item.');
    $this->waitForText($png_image->filename);

    // Remove the item.     $assert_session->elementTextContains('css', '.field--name-field-twin-media', $png_image->filename);
    $assert_session->elementExists('css', '.field--name-field-twin-media')->pressButton('Remove');
    $this->waitForElementTextContains('#drupal-live-announce', $png_image->filename . ' has been removed');
    $assert_session->elementTextNotContains('css', '.field--name-field-twin-media', $png_image->filename);

    $this->openMediaLibraryForField('field_twin_media');
    
// Ensure the hidden 'form_build_id' field is unique.     $this->assertSession()->elementsCount('xpath', '//input[@name="form_build_id"]', 1);

    // Retrieve the new build-id.     $buildId = (string) $this->assertSession()->hiddenFieldExists('form_build_id')->getValue();

    // Trigger validation error by again submitting an empty title.     $edit = ['title' => ''];
    $this->submitForm($edit, 'Continue submit');

    // Verify that the build-id does not change the second time.     $this->assertSession()->hiddenFieldValueEquals('form_build_id', $buildId);
  }

  /** * Verify that existing contrib code cannot overwrite immutable form state. */
  public function testImmutableFormLegacyProtection() {
    $this->drupalGet('form_test/form-storage', ['query' => ['cache' => 1, 'immutable' => 1]]);
    // Ensure the hidden 'form_build_id' field is unique.     $this->assertSession()->elementsCount('xpath', '//input[@name="form_build_id"]', 1);
    $build_id = $this->assertSession()->hiddenFieldExists('form_build_id')->getValue();

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