Commit f2c5cfdd authored by catch's avatar catch
Browse files

Issue #2809491 by ApacheEx, dawehner, Lendude: Convert AJAX part of...

Issue #2809491 by ApacheEx, dawehner, Lendude: Convert AJAX part of \Drupal\field\Tests\Boolean\BooleanFieldTest::testBooleanField to JavascriptTestBase
parent dc03979e
<?php <?php
namespace Drupal\field\Tests\Boolean; namespace Drupal\Tests\field\Functional\Boolean;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest; use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase; use Drupal\Tests\BrowserTestBase;
/** /**
* Tests boolean field functionality. * Tests boolean field functionality.
* *
* @group field * @group field
*/ */
class BooleanFieldTest extends WebTestBase { class BooleanFieldTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
...@@ -108,15 +108,13 @@ public function testBooleanField() { ...@@ -108,15 +108,13 @@ public function testBooleanField() {
"{$field_name}[value]" => 1, "{$field_name}[value]" => 1,
]; ];
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match); preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1]; $id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
// Verify that boolean value is displayed. // Verify that boolean value is displayed.
$entity = EntityTest::load($id); $entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full'); $this->drupalGet($entity->toUrl());
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw('<div class="field__item">' . $on . '</div>'); $this->assertRaw('<div class="field__item">' . $on . '</div>');
// Test with "On" label option. // Test with "On" label option.
...@@ -150,7 +148,7 @@ public function testBooleanField() { ...@@ -150,7 +148,7 @@ public function testBooleanField() {
$this->drupalGet($fieldEditUrl); $this->drupalGet($fieldEditUrl);
// Click on the widget settings button to open the widget settings form. // Click on the widget settings button to open the widget settings form.
$this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); $this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
$this->assertText( $this->assertText(
'Use field label instead of the "On" label as the label.', 'Use field label instead of the "On" label as the label.',
...@@ -159,7 +157,7 @@ public function testBooleanField() { ...@@ -159,7 +157,7 @@ public function testBooleanField() {
// Enable setting. // Enable setting.
$edit = ['fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1]; $edit = ['fields[' . $field_name . '][settings_edit_form][settings][display_label]' => 1];
$this->drupalPostAjaxForm(NULL, $edit, $field_name . "_plugin_settings_update"); $this->drupalPostForm(NULL, $edit, $field_name . "_plugin_settings_update");
$this->drupalPostForm(NULL, NULL, 'Save'); $this->drupalPostForm(NULL, NULL, 'Save');
// Go again to the form display page and check if the setting // Go again to the form display page and check if the setting
...@@ -167,16 +165,12 @@ public function testBooleanField() { ...@@ -167,16 +165,12 @@ public function testBooleanField() {
$this->drupalGet($fieldEditUrl); $this->drupalGet($fieldEditUrl);
$this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.'); $this->assertText('Use field label: Yes', 'Checking the display settings checkbox updated the value.');
$this->drupalPostAjaxForm(NULL, [], $field_name . "_settings_edit"); $this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
$this->assertText( $this->assertText(
'Use field label instead of the "On" label as the label.', 'Use field label instead of the "On" label as the label.',
t('Display setting checkbox is available') t('Display setting checkbox is available')
); );
$this->assertFieldByXPath( $this->getSession()->getPage()->hasCheckedField('fields[' . $field_name . '][settings_edit_form][settings][display_label]');
'*//input[starts-with(@id, "edit-fields-' . $field_name . '-settings-edit-form-settings-display-label") and @value="1"]',
TRUE,
t('Display label changes label of the checkbox')
);
// Test the boolean field settings. // Test the boolean field settings.
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
...@@ -230,7 +224,7 @@ public function testFormAccess() { ...@@ -230,7 +224,7 @@ public function testFormAccess() {
// Should be posted OK. // Should be posted OK.
$this->drupalPostForm(NULL, [], t('Save')); $this->drupalPostForm(NULL, [], t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match); preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1]; $id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
...@@ -241,7 +235,7 @@ public function testFormAccess() { ...@@ -241,7 +235,7 @@ public function testFormAccess() {
$this->assertNoFieldByName("{$field_name}[value]"); $this->assertNoFieldByName("{$field_name}[value]");
// Should still be able to post the form. // Should still be able to post the form.
$this->drupalPostForm(NULL, [], t('Save')); $this->drupalPostForm(NULL, [], t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match); preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
$id = $match[1]; $id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id])); $this->assertText(t('entity_test @id has been created.', ['@id' => $id]));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment