You are here

public function EmbedButtonAdminTest::testButtonValidation in Embed 8

File

tests/src/FunctionalJavascript/EmbedButtonAdminTest.php, line 147

Class

EmbedButtonAdminTest
Tests the administrative UI.

Namespace

Drupal\Tests\embed\FunctionalJavascript

Code

public function testButtonValidation() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/config/content/embed/button/add');
  $button_label = $this
    ->randomMachineName();
  $button_id = strtolower($button_label);
  $page
    ->fillField('label', $button_label);
  $this
    ->assertNotEmpty($assert_session
    ->waitForText("Machine name: {$button_id}"));
  $page
    ->selectFieldOption('type_id', 'embed_test_aircraft');
  $aircraft_type = $assert_session
    ->waitForField('type_settings[aircraft_type]');
  $this
    ->assertNotEmpty($aircraft_type);
  $this
    ->assertSame('fixed-wing', $aircraft_type
    ->getValue());
  $edit['type_settings[aircraft_type]'] = 'invalid';
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $assert_session
    ->pageTextContains('Cannot select invalid aircraft type.');
  $edit['type_settings[aircraft_type]'] = 'helicopters';
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $assert_session
    ->pageTextContains('Helicopters are just rotorcraft.');
  $this
    ->drupalGet('admin/config/content/embed/button/manage/' . $button_id);
  $this
    ->assertFieldByName('type_settings[aircraft_type]', 'rotorcraft');
}