diff --git a/src/Tests/DynamicEntityReferenceBaseTest.php b/tests/src/Functional/DynamicEntityReferenceBaseTest.php similarity index 93% rename from src/Tests/DynamicEntityReferenceBaseTest.php rename to tests/src/Functional/DynamicEntityReferenceBaseTest.php index 29d9ea0..2b58e2b 100644 --- a/src/Tests/DynamicEntityReferenceBaseTest.php +++ b/tests/src/Functional/DynamicEntityReferenceBaseTest.php @@ -1,20 +1,20 @@ drupalGet('entity_test/add'); - $this->assertField('dynamic_references[0][target_id]', 'Found foobar field target id'); - $this->assertField('dynamic_references[0][target_type]', 'Found foobar field target type'); + $this->assertSession()->fieldExists('dynamic_references[0][target_id]'); + $this->assertSession()->fieldExists('dynamic_references[0][target_type]'); // Ensure that the autocomplete path is correct. $input = $this->xpath('//input[@name=:name]', array(':name' => 'dynamic_references[0][target_id]'))[0]; @@ -85,7 +85,7 @@ class DynamicEntityReferenceBaseTest extends WebTestBase { 'selection_handler' => $settings['entity_test']['handler'], 'selection_settings_key' => $selection_settings_key, ))->toString(); - $this->assertTrue(strpos((string) $input['data-autocomplete-path'], $expected_autocomplete_path) !== FALSE); + $this->assertTrue(strpos($input->getAttribute('data-autocomplete-path'), $expected_autocomplete_path) !== FALSE); $edit = array( // Ensure that an exact match on a unique label is accepted. @@ -219,8 +219,8 @@ class DynamicEntityReferenceBaseTest extends WebTestBase { // Test the new entity commenting inherits default. $this->drupalGet('entity_test/add'); - $this->assertField('dynamic_references[0][target_id]', 'Found foobar field target id'); - $this->assertField('dynamic_references[0][target_type]', 'Found foobar field target type'); + $this->assertSession()->fieldExists('dynamic_references[0][target_id]'); + $this->assertSession()->fieldExists('dynamic_references[0][target_type]'); // Ensure that the autocomplete path is correct. $input = $this->xpath('//input[@name=:name]', array(':name' => 'dynamic_references[0][target_id]'))[0]; @@ -234,10 +234,10 @@ class DynamicEntityReferenceBaseTest extends WebTestBase { 'selection_handler' => $settings['entity_test']['handler'], 'selection_settings_key' => $selection_settings_key, ))->toString(); - $this->assertTrue(strpos((string) $input['data-autocomplete-path'], $expected_autocomplete_path) !== FALSE); + $this->assertTrue(strpos($input->getAttribute('data-autocomplete-path'), $expected_autocomplete_path) !== FALSE); // Add some extra dynamic entity reference fields. - $this->drupalPostAjaxForm(NULL, array(), array('dynamic_references_add_more' => t('Add another item')), NULL, array(), array(), 'entity-test-entity-test-form'); + $this->getSession()->getPage()->findButton('field_foobar_add_more')->click(); $edit = array( // Ensure that an exact match on a unique label is accepted. diff --git a/src/Tests/DynamicEntityReferenceFieldDefaultValueTest.php b/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php similarity index 90% rename from src/Tests/DynamicEntityReferenceFieldDefaultValueTest.php rename to tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php index 1b2eff7..82a2899 100644 --- a/src/Tests/DynamicEntityReferenceFieldDefaultValueTest.php +++ b/tests/src/Functional/DynamicEntityReferenceFieldDefaultValueTest.php @@ -1,13 +1,13 @@ drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $field_name); - $this->assertFieldByXPath(CssSelector::toXPath('select[name="default_value_input[' . $field_name . '][0][target_type]"] > option[value=' . $referenced_node->getEntityTypeId() . ']'), 'Content', 'The default target type value is selected in instance settings page'); - $this->assertRaw('name="default_value_input[' . $field_name . '][0][target_id]" value="' . $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')', 'The default value is selected in instance settings page'); + $this->assertSession()->optionExists("default_value_input[$field_name][0][target_type]", $referenced_node->getEntityTypeId()); + $this->assertRaw('name="default_value_input[' . $field_name . '][0][target_id]" value="' . $referenced_node->getTitle() . ' (' . $referenced_node->id() . ')'); // Check if the ID has been converted to UUID in config entity. $config_entity = $this->config('field.field.node.reference_content.' . $field_name)->get(); diff --git a/src/Tests/DynamicEntityReferenceLocaleTest.php b/tests/src/Functional/DynamicEntityReferenceLocaleTest.php similarity index 93% rename from src/Tests/DynamicEntityReferenceLocaleTest.php rename to tests/src/Functional/DynamicEntityReferenceLocaleTest.php index 34139b4..5893f5f 100644 --- a/src/Tests/DynamicEntityReferenceLocaleTest.php +++ b/tests/src/Functional/DynamicEntityReferenceLocaleTest.php @@ -1,6 +1,6 @@ 'user', ), t('Save field settings')); $this->assertFieldByName('default_value_input[field_foobar][0][target_type]'); - $this->assertFieldByXPath(CssSelector::toXPath('select[name="default_value_input[field_foobar][0][target_type]"] > option[value=entity_test]'), 'entity_test'); - $this->assertNoFieldByXPath(CssSelector::toXPath('select[name="default_value_input[field_foobar][0][target_type]"] > option[value=user]'), 'user'); + $this->assertSession()->optionExists('default_value_input[field_foobar][0][target_type]', 'entity_test'); + $this->assertSession()->optionNotExists('default_value_input[field_foobar][0][target_type]', 'user'); $edit = array( 'settings[entity_test_label][handler_settings][target_bundles][entity_test_label]' => TRUE, 'settings[entity_test_view_builder][handler_settings][target_bundles][entity_test_view_builder]' => TRUE, @@ -142,8 +142,8 @@ class DynamicEntityReferenceTest extends WebTestBase { ), t('Save field settings')); $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.field_foobar'); $this->assertFieldByName('default_value_input[field_foobar][0][target_type]'); - $this->assertFieldByXPath(CssSelector::toXPath('select[name="default_value_input[field_foobar][0][target_type]"] > option[value=user]'), 'user'); - $this->assertNoFieldByXPath(CssSelector::toXPath('select[name="default_value_input[field_foobar][0][target_type]"] > option[value=entity_test]'), 'entity_test'); + $this->assertSession()->optionNotExists('default_value_input[field_foobar][0][target_type]', 'entity_test'); + $this->assertSession()->optionExists('default_value_input[field_foobar][0][target_type]', 'user'); $this->drupalPostForm(NULL, array(), t('Save settings')); $this->assertRaw(t('Saved %name configuration', array('%name' => 'Foobar'))); $excluded_entity_type_ids = FieldStorageConfig::loadByName('entity_test', 'field_foobar') @@ -231,8 +231,8 @@ class DynamicEntityReferenceTest extends WebTestBase { // Test the new entity commenting inherits default. $this->drupalGet('entity_test/add'); - $this->assertField('field_foobar[0][target_id]', 'Found foobar field target id'); - $this->assertField('field_foobar[0][target_type]', 'Found foobar field target type'); + $this->assertSession()->fieldExists('field_foobar[0][target_id]'); + $this->assertSession()->fieldExists('field_foobar[0][target_type]'); // Ensure that the autocomplete path is correct. $input = $this->xpath('//input[@name=:name]', array(':name' => 'field_foobar[0][target_id]'))[0]; @@ -245,11 +245,11 @@ class DynamicEntityReferenceTest extends WebTestBase { 'selection_handler' => $settings['entity_test_label']['handler'], 'selection_settings_key' => $selection_settings_key, ))->toString(); - $this->assertTrue(strpos((string) $input['data-autocomplete-path'], $expected_autocomplete_path) !== FALSE); + $this->assertTrue(strpos($input->getAttribute('data-autocomplete-path'), $expected_autocomplete_path) !== FALSE); // Add some extra dynamic entity reference fields. - $this->drupalPostAjaxForm(NULL, array(), array('field_foobar_add_more' => t('Add another item')), NULL, array(), array(), 'entity-test-entity-test-form'); - $this->drupalPostAjaxForm(NULL, array(), array('field_foobar_add_more' => t('Add another item')), NULL, array(), array(), 'entity-test-entity-test-form'); + $this->getSession()->getPage()->findButton('field_foobar_add_more')->click(); + $this->getSession()->getPage()->findButton('field_foobar_add_more')->click(); $edit = array( 'field_foobar[0][target_id]' => $this->anotherUser->label() . ' (' . $this->anotherUser->id() . ')', @@ -293,7 +293,7 @@ class DynamicEntityReferenceTest extends WebTestBase { 'selection_handler' => $settings[$expected_entity_type]['handler'], 'selection_settings_key' => $selection_settings_key, ))->toString(); - $this->assertTrue(strpos((string) $input['data-autocomplete-path'], $expected_autocomplete_path) !== FALSE); + $this->assertTrue(strpos($input->getAttribute('data-autocomplete-path'), $expected_autocomplete_path) !== FALSE); } $edit = array( @@ -425,8 +425,8 @@ class DynamicEntityReferenceTest extends WebTestBase { $this->drupalGet('entity_test/add'); // Add some extra dynamic entity reference fields. - $this->drupalPostAjaxForm(NULL, array(), array('field_foobar_add_more' => t('Add another item')), NULL, array(), array(), 'entity-test-entity-test-form'); - $this->drupalPostAjaxForm(NULL, array(), array('field_foobar_add_more' => t('Add another item')), NULL, array(), array(), 'entity-test-entity-test-form'); + $this->getSession()->getPage()->findButton('field_foobar_add_more')->click(); + $this->getSession()->getPage()->findButton('field_foobar_add_more')->click(); $edit = array( 'field_foobar[0][target_id]' => $this->adminUser->label() . ' (' . $this->adminUser->id() . ')', 'field_foobar[0][target_type]' => 'user', @@ -511,8 +511,8 @@ class DynamicEntityReferenceTest extends WebTestBase { // Test the node preview for existing term. $this->drupalGet('node/add/article'); - $this->assertField('field_der[0][target_id]', 'Found field_der field target id'); - $this->assertField('field_der[0][target_type]', 'Found field_der field target type'); + $this->assertSession()->fieldExists('field_der[0][target_id]'); + $this->assertSession()->fieldExists('field_der[0][target_type]'); $title = $this->randomMachineName(); $edit = array( 'field_der[0][target_id]' => $term->label() . ' (' . $term->id() . ')', @@ -530,8 +530,8 @@ class DynamicEntityReferenceTest extends WebTestBase { // Test the node preview for new term. $this->drupalGet('node/add/article'); - $this->assertField('field_der[0][target_id]', 'Found field_der field target id'); - $this->assertField('field_der[0][target_type]', 'Found field_der field target type'); + $this->assertSession()->fieldExists('field_der[0][target_id]'); + $this->assertSession()->fieldExists('field_der[0][target_type]'); $new_term = $this->randomMachineName(); $edit = array( diff --git a/src/Tests/DynamicEntityReferenceWidgetTest.php b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php similarity index 97% rename from src/Tests/DynamicEntityReferenceWidgetTest.php rename to tests/src/Functional/DynamicEntityReferenceWidgetTest.php index 6b82266..a85a0da 100644 --- a/src/Tests/DynamicEntityReferenceWidgetTest.php +++ b/tests/src/Functional/DynamicEntityReferenceWidgetTest.php @@ -1,19 +1,19 @@