diff --git a/core/modules/taxonomy/src/Tests/TermAutocompleteTest.php b/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php similarity index 81% rename from core/modules/taxonomy/src/Tests/TermAutocompleteTest.php rename to core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php index ce28b1285d..07610b29f0 100644 --- a/core/modules/taxonomy/src/Tests/TermAutocompleteTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php @@ -1,10 +1,12 @@ drupalLogin($this->adminUser); // Retrieve the autocomplete url. - $this->drupalGet('node/add/article'); + $this->drupalGet(Url::fromRoute('node.add', ['node_type' => 'article'])); $result = $this->xpath('//input[@name="' . $this->fieldName . '[0][target_id]"]'); - $this->autocompleteUrl = $this->getAbsoluteUrl($result[0]['data-autocomplete-path']); + $this->autocompleteUrl = $this->getAbsoluteUrl($result[0]->getAttribute('data-autocomplete-path')); + } + + /** + * Helper function for JSON formatted requests. + * + * @param string|\Drupal\Core\Url $path + * Drupal path or URL to load into Mink controlled browser. + * @param array $options + * (optional) Options to be forwarded to the url generator. + * @param string[] $headers + * (optional) An array containing additional HTTP request headers. + * + * @return string[] + * Array representing decoded JSON response. + */ + protected function drupalGetJson($path, array $options = [], array $headers = []) { + $options = array_merge_recursive(['query' => ['_format' => 'json']], $options); + return Json::decode($this->drupalGet($path, $options, $headers)); } /** @@ -137,21 +164,21 @@ protected function setUp() { */ public function testAutocompleteCountResults() { // Test that no matching term found. - $data = $this->drupalGetJSON( + $data = $this->drupalGetJson( $this->autocompleteUrl, ['query' => ['q' => 'zzz']] ); $this->assertTrue(empty($data), 'Autocomplete returned no results'); // Test that only one matching term found, when only one matches. - $data = $this->drupalGetJSON( + $data = $this->drupalGetJson( $this->autocompleteUrl, ['query' => ['q' => 'aaa 10']] ); $this->assertEqual(1, count($data), 'Autocomplete returned 1 result'); // Test the correct number of matches when multiple are partial matches. - $data = $this->drupalGetJSON( + $data = $this->drupalGetJson( $this->autocompleteUrl, ['query' => ['q' => 'aaa 1']] ); @@ -159,7 +186,7 @@ public function testAutocompleteCountResults() { // Tests that only 10 results are returned, even if there are more than 10 // matches. - $data = $this->drupalGetJSON( + $data = $this->drupalGetJson( $this->autocompleteUrl, ['query' => ['q' => 'aaa']] ); @@ -192,7 +219,7 @@ public function testAutocompleteOrderedResults() { ]; } - $data = $this->drupalGetJSON( + $data = $this->drupalGetJson( $this->autocompleteUrl, ['query' => ['q' => 'bbb']] ); diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php index 574efa073e..cce58da942 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php @@ -7,7 +7,6 @@ use Drupal\field\Entity\FieldConfig; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase; /** * Tests load, save and delete for taxonomy terms.