public function SingleItemTest::testForm in Media Library Form API Element 8
Same name and namespace in other branches
- 2.x tests/src/FunctionalJavascript/SingleItemTest.php \Drupal\Tests\media_library_form_element\FunctionalJavascript\SingleItemTest::testForm()
Tests the setting form.
File
- tests/
src/ FunctionalJavascript/ SingleItemTest.php, line 78
Class
- SingleItemTest
- Test using the media library element with cardinality 1.
Namespace
Drupal\Tests\media_library_form_element\FunctionalJavascriptCode
public function testForm() {
$assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalGet('media-library-form-element-test-form');
// The form element correctly displays description text.
$assert
->elementContains('css', '#media-media-library-wrapper--description', 'Upload or select your profile image');
// Cardinality is limited to 1, and no item is populated by default.
$assert
->elementContains('css', '#media-media-library-wrapper--description', 'One media item remaining');
// Enter the media library.
$page
->pressButton('Add media');
$assert
->assertWaitOnAjaxRequest();
// Only allowed media types as defined by the form element
// are displayed in the Media Library menu.
$assert
->elementContains('css', '.media-library-menu a', 'Type One');
$assert
->pageTextContains('Type Two');
$assert
->pageTextNotContains('Type Three');
// This form element provides access to 'type_one' media.
$assert
->pageTextContains('Horse');
$assert
->pageTextContains('Bear');
$page
->find('css', 'input[name="media_library_select_form[0]"]')
->setValue('1');
$assert
->assertWaitOnAjaxRequest();
$assert
->checkboxChecked('media_library_select_form[0]');
$assert
->elementExists('css', '.ui-dialog-buttonset')
->pressButton('Insert selected');
$assert
->assertWaitOnAjaxRequest();
// The item displays in the form element preview.
$assert
->elementContains('css', '.media-library-item__name', 'Dog');
// Cardinality of 1 is reflected.
$assert
->elementContains('css', '#media-media-library-wrapper--description', 'The maximum number of media items have been selected.');
$page
->pressButton('Save configuration');
// Verify the selection is saved in configuration
// and loads as the default value.
$assert
->pageTextContains('Dog');
$assert
->elementContains('css', '.media-library-item__name', 'Dog');
// Remove the item.
$page
->pressButton('Remove');
$this
->waitForNoText('Dog');
$page
->pressButton('Save configuration');
$assert
->pageTextNotContains('Dog');
$assert
->elementContains('css', '#media-media-library-wrapper--description', 'One media item remaining');
}