diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php index 45844ce..4884282 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Component\Utility\Json; use Drupal\entity_reference\EntityReferenceController; use Drupal\system\Tests\Entity\EntityUnitTestBase; @@ -79,21 +80,24 @@ function testEntityReferenceAutocompletion() { // We should get both entities in a JSON encoded string. $input = '10/'; $data = $this->getAutocompleteResult('single', $input); - $this->assertIdentical($data[$entity_1->name->value . ' (1)'], check_plain($entity_1->name->value), 'Autocomplete returned the first matching entity'); - $this->assertIdentical($data[$entity_2->name->value . ' (2)'], check_plain($entity_2->name->value), 'Autocomplete returned the second matching entity'); + $this->assertIdentical($data[0]['label'], check_plain($entity_1->name->value), 'Autocomplete returned the first matching entity'); + $this->assertIdentical($data[1]['label'], check_plain($entity_2->name->value), 'Autocomplete returned the second matching entity'); // Try to autocomplete a entity label that matches the first entity. // We should only get the first entity in a JSON encoded string. $input = '10/16'; $data = $this->getAutocompleteResult('single', $input); - $target = array($entity_1->name->value . ' (1)' => check_plain($entity_1->name->value)); - $this->assertIdentical($data, $target, 'Autocomplete returns only the expected matching entity.'); + $target = array( + 'value' => $entity_1->name->value . ' (1)', + 'label' => check_plain($entity_1->name->value), + ); + $this->assertIdentical(reset($data), $target, 'Autocomplete returns only the expected matching entity.'); // Try to autocomplete a entity label that matches the second entity, and // the first entity is already typed in the autocomplete (tags) widget. $input = $entity_1->name->value . ' (1), 10/17'; $data = $this->getAutocompleteResult('tags', $input); - $this->assertIdentical($data[$entity_1->name->value . ' (1), ' . $entity_2->name->value . ' (2)'], check_plain($entity_2->name->value), 'Autocomplete returned the second matching entity'); + $this->assertIdentical($data[0]['label'], check_plain($entity_2->name->value), 'Autocomplete returned the second matching entity'); // Try to autocomplete a entity label with both a comma and a slash. $input = '"label with, and / t'; @@ -103,8 +107,11 @@ function testEntityReferenceAutocompletion() { if (strpos($entity_3->name->value, ',') !== FALSE || strpos($entity_3->name->value, '"') !== FALSE) { $n = '"' . str_replace('"', '""', $entity_3->name->value) . ' (3)"'; } - $target = array($n => check_plain($entity_3->name->value)); - $this->assertIdentical($data, $target, 'Autocomplete returns an entity label containing a comma and a slash.'); + $target = array( + 'value' => $n, + 'label' => check_plain($entity_3->name->value), + ); + $this->assertIdentical(reset($data), $target, 'Autocomplete returns an entity label containing a comma and a slash.'); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index d11eefe..345821a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -218,13 +218,13 @@ function testNodeTermCreationAndDeletion() { // The term will be quoted, and the " will be encoded in unicode (\u0022). $input = substr($term_objects['term3']->label(), 0, 3); $json = $this->drupalGet('taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input))); - $this->assertEqual($json, '{"\u0022' . $term_objects['term3']->label() . '\u0022":"' . $term_objects['term3']->label() . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->label()))); + $this->assertEqual($json, '[{"value":"\u0022' . $term_objects['term3']->label() . '\u0022","label":"' . $term_objects['term3']->label() . '"}]', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term3']->label()))); // Test autocomplete on term 4 - it is alphanumeric only, so no extra // quoting. $input = substr($term_objects['term4']->label(), 0, 3); $this->drupalGet('taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id(), array('query' => array('q' => $input))); - $this->assertRaw('{"' . $term_objects['term4']->label() . '":"' . $term_objects['term4']->label() . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->label()))); + $this->assertRaw('[{"value":"' . $term_objects['term4']->label() . '","label":"' . $term_objects['term4']->label() . '"}', format_string('Autocomplete returns term %term_name after typing the first 3 letters.', array('%term_name' => $term_objects['term4']->label()))); // Test taxonomy autocomplete with a nonexistent field. $field_name = $this->randomName(); @@ -259,15 +259,18 @@ function testTermAutocompletion() { // The result order is not guaranteed, so check each term separately. $result = $this->drupalGet($path, array('query' => array('q' => $input))); $data = drupal_json_decode($result); - $this->assertEqual($data[$first_term->label()], check_plain($first_term->label()), 'Autocomplete returned the first matching term'); - $this->assertEqual($data[$second_term->label()], check_plain($second_term->label()), 'Autocomplete returned the second matching term'); + $this->assertEqual($data[0]['label'], check_plain($first_term->label()), 'Autocomplete returned the first matching term'); + $this->assertEqual($data[1]['label'], check_plain($second_term->label()), 'Autocomplete returned the second matching term'); // Try to autocomplete a term name that matches first term. // We should only get the first term in a json encoded string. $input = '10/16'; $path = 'taxonomy/autocomplete/node/taxonomy_' . $this->vocabulary->id(); $this->drupalGet($path, array('query' => array('q' => $input))); - $target = array($first_term->label() => check_plain($first_term->label())); + $target = array(array( + 'value' => check_plain($first_term->label()), + 'label' => $first_term->label(), + )); $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns only the expected matching term.'); // Try to autocomplete a term name with both a comma and a slash. @@ -279,7 +282,10 @@ function testTermAutocompletion() { if (strpos($third_term->label(), ',') !== FALSE || strpos($third_term->label(), '"') !== FALSE) { $n = '"' . str_replace('"', '""', $third_term->label()) . '"'; } - $target = array($n => check_plain($third_term->label())); + $target = array(array( + 'value' => $n, + 'label' => check_plain($third_term->label()), + )); $this->assertRaw(drupal_json_encode($target), 'Autocomplete returns a term containing a comma and a slash.'); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php index e6fad9a..de8062e 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAutocompleteTest.php @@ -53,8 +53,8 @@ function testUserAutocomplete() { // Test that anonymous username is in the result when requested and escaped // with check_plain(). $users = $this->drupalGetJSON('user/autocomplete/anonymous', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4)))); - $this->assertTrue(in_array(check_plain($anonymous_name), $users), 'The anonymous name found in autocompletion results.'); + $this->assertEqual(check_plain($anonymous_name), $users[0]['label'], 'The anonymous name found in autocompletion results.'); $users = $this->drupalGetJSON('user/autocomplete', array('query' => array('q' => drupal_substr($anonymous_name, 0, 4)))); - $this->assertFalse(isset($users[$anonymous_name]), 'The anonymous name not found in autocompletion results without enabling anonymous username.'); + $this->assertTrue(empty($users), 'The anonymous name not found in autocompletion results without enabling anonymous username.'); } } diff --git a/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php index ef5f98d..df73f40 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewsTaxonomyAutocompleteTest.php @@ -8,7 +8,6 @@ namespace Drupal\views\Tests; use Drupal\views\Tests\ViewTestBase; -use Drupal\Component\Utility\MapArray; use Drupal\Core\Language\Language; /** @@ -81,7 +80,10 @@ public function testTaxonomyAutocomplete() { // Test a with whole name term. $label = $this->term1->label(); - $expected = MapArray::copyValuesToKeys((array) $label); + $expected = array(array( + 'value' => $label, + 'label' => check_plain($label), + )); $this->assertIdentical($expected, $this->drupalGetJSON($base_autocomplete_path, array('query' => array('q' => $label)))); // Test a term by partial name. $partial = substr($label, 0, 2);