diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index 82ba8ad..c89b346 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php @@ -11,7 +11,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests edit autocomplete. + * Tests using in-place editing for an autocomplete entity reference widget. */ class EditAutocompleteTermTest extends WebTestBase { @@ -25,24 +25,38 @@ class EditAutocompleteTermTest extends WebTestBase { /** * Stores the node used for the tests. * - * @var \Drupal\node\Entity\Node + * @var \Drupal\node\NodeInterface */ protected $node; /** + * Stores the vocabulary used in the tests. + * + * @var \Drupal\taxonomy\VocabularyInterface + */ + protected $vocabulary; + + /** * Stores the first term used in the tests. * - * @var \Drupal\taxonomy\Term + * @var \Drupal\taxonomy\TermInterface */ protected $term1; /** * Stores the second term used in the tests. * - * @var \Drupal\taxonomy\Term + * @var \Drupal\taxonomy\TermInterface */ protected $term2; + /** + * Stores the field name for the autocomplete field. + * + * @var string + */ + protected $field_name; + public static function getInfo() { return array( 'name' => 'In-place editing of autocomplete tags', @@ -111,8 +125,8 @@ function setUp() { $node = array(); $node['type'] = 'article'; - $node['field_edit_testing_tags'][]['target_id'] = $this->term1->id(); - $node['field_edit_testing_tags'][]['target_id'] = $this->term2->id(); + $node[$this->field_name][]['target_id'] = $this->term1->id(); + $node[$this->field_name][]['target_id'] = $this->term2->id(); $this->node = $this->drupalCreateNode($node); $this->editor_user = $this->drupalCreateUser(array('access content', 'create article content', 'edit any article content', 'access in-place editing')); @@ -147,20 +161,24 @@ public function testAutocompleteEdit() { $response = $this->drupalPost($edit_uri, 'application/vnd.drupal-ajax', $post); $this->assertResponse(200); $ajax_commands = drupal_json_decode($response); - $this->assertTrue(strpos($ajax_commands[0]['data'], '>' . $this->term1->label() . '<'), 'Existing term 1 in rendered output.'); - $this->assertTrue(strpos($ajax_commands[0]['data'], '>' . $this->term2->label() . '<'), 'Existing term 2 in rendered output.'); - $this->assertTrue(strpos($ajax_commands[0]['data'], 'new term'), 'New term in rendered output.'); + $this->drupalSetContent($ajax_commands[0]['data']); + $this->assertLink($this->term1->label()); + $this->assertLink($this->term2->label()); + $this->assertText('new term'); + $this->assertNoLink('new term'); - // Load the form again, which should now get it back from tempstore. + // Load the form again, which should now get it back from TempStore. $edit_uri = 'edit/form/node/'. $this->node->id() . '/' . $this->field_name . '/und/full'; $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $response = $this->drupalPost($edit_uri, 'application/vnd.drupal-ajax', $post); $ajax_commands = drupal_json_decode($response); - // Response should still contain the tags. - $this->assertTrue(strpos($ajax_commands[0]['data'], $this->term1->label()), 'Existing term 1 in reloaded form.'); - $this->assertTrue(strpos($ajax_commands[0]['data'], $this->term2->label()), 'Existing term 2 in reloaded form.'); - $this->assertTrue(strpos($ajax_commands[0]['data'], 'new term'), 'New term in reloaded form.'); + // The AjaxResponse's first command is an InsertCommand which contains + // the form to edit the taxonomy term field, it should contain all three + // taxonomy terms, including the one that has just been newly created and + // which is not yet stored. + $this->drupalSetContent($ajax_commands[0]['data']); + $this->assertFieldByName($this->field_name, implode(', ', array($this->term1->label(), 'new term', $this->term2->label()))); // Save the entity. $post = array('nocssjs' => 'true'); @@ -178,9 +196,9 @@ public function testAutocompleteEdit() { /** - * Returns a new term with random properties in vocabulary $vid. + * Returns a new term with random name and description in $this->vocabulary. * - * @return \Drupal\taxonomy\Term + * @return \Drupal\taxonomy\TermInterface * The created taxonomy term. */ protected function createTerm() {