function ActionFormAjaxTest::testActionConfigurationWithAjax

Same name in other branches
  1. 9 core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php \Drupal\Tests\action\FunctionalJavascript\ActionFormAjaxTest::testActionConfigurationWithAjax()
  2. 8.9.x core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php \Drupal\Tests\action\FunctionalJavascript\ActionFormAjaxTest::testActionConfigurationWithAjax()
  3. 10 core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php \Drupal\Tests\action\FunctionalJavascript\ActionFormAjaxTest::testActionConfigurationWithAjax()

Tests action plugins with AJAX save their configuration.

File

core/modules/action/tests/src/FunctionalJavascript/ActionFormAjaxTest.php, line 40

Class

ActionFormAjaxTest
Tests action plugins using JavaScript.

Namespace

Drupal\Tests\action\FunctionalJavascript

Code

public function testActionConfigurationWithAjax() {
    $url = Url::fromRoute('action.admin_add', [
        'action_id' => 'action_form_ajax_test',
    ]);
    $this->drupalGet($url);
    $page = $this->getSession()
        ->getPage();
    $id = 'test_plugin';
    $this->assertSession()
        ->waitForElementVisible('named', [
        'button',
        'Edit',
    ])
        ->press();
    $this->assertSession()
        ->waitForElementVisible('css', '[name="id"]')
        ->setValue($id);
    $page->find('css', '[name="having_a_party"]')
        ->check();
    $this->assertSession()
        ->waitForElementVisible('css', '[name="party_time"]');
    $party_time = 'Evening';
    $page->find('css', '[name="party_time"]')
        ->setValue($party_time);
    $page->find('css', '[value="Save"]')
        ->click();
    $url = Url::fromRoute('entity.action.collection');
    $this->assertSession()
        ->pageTextContains('The action has been successfully saved.');
    $this->assertSession()
        ->addressEquals($url);
    // Check storage.
    $instance = Action::load($id);
    $configuration = $instance->getPlugin()
        ->getConfiguration();
    $this->assertEquals([
        'party_time' => $party_time,
    ], $configuration);
    // Configuration should be shown in edit form.
    $this->drupalGet($instance->toUrl('edit-form'));
    $this->assertSession()
        ->checkboxChecked('having_a_party');
    $this->assertSession()
        ->fieldValueEquals('party_time', $party_time);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.