summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordereine2012-10-22 02:55:24 (GMT)
committerTim Plunkett2012-10-22 02:55:24 (GMT)
commit4942a158b745d30755ab84fb3f57d79bfad5f030 (patch)
treeb16d310b0050b79fc26922947f761233c7c6dc86
parentee4d43cb3f38dfab7b19c2d6884db32d39ef4aa5 (diff)
Issue #1806884 by dawehner: Fixed views_ui_autocomplete_tag().8.x-3.x-rebased
-rw-r--r--lib/Drupal/views/Tests/UI/TagTest.php57
-rw-r--r--views_ui/admin.inc5
2 files changed, 60 insertions, 2 deletions
diff --git a/lib/Drupal/views/Tests/UI/TagTest.php b/lib/Drupal/views/Tests/UI/TagTest.php
new file mode 100644
index 0000000..957f890
--- /dev/null
+++ b/lib/Drupal/views/Tests/UI/TagTest.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\views\tests\UI\TagTest.
+ */
+
+namespace Drupal\views\Tests\UI;
+
+/**
+ * Tests the views ui tagging functionality.
+ */
+class TagTest extends UITestBase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Tag',
+ 'description' => 'Tests the views ui tagging functionality.',
+ 'group' => 'Views UI',
+ );
+ }
+
+ /**
+ * Tests the views_ui_autocomplete_tag function.
+ */
+ public function testViewsUiAutocompleteTag() {
+ module_load_include('inc', 'views_ui', 'admin');
+
+ // Save 15 views with a tag.
+ $tags = array();
+ for ($i = 0; $i < 16; $i++) {
+ $suffix = $i % 2 ? 'odd' : 'even';
+ $tag = 'autocomplete_tag_test_' . $suffix . $this->randomName();
+ $tags[] = $tag;
+ views_create_view(array('tag' => $tag, 'name' => $this->randomName()))->save();
+ }
+
+ // Make sure just ten results are returns.
+ $result = views_ui_autocomplete_tag('autocomplete_tag_test');
+ $matches = (array) json_decode($result->getContent());
+ $this->assertEqual(count($matches), 10, 'Make sure the maximum amount of tag results is 10.');
+
+ // Make sure that matching by a certain prefix works.
+ $result = views_ui_autocomplete_tag('autocomplete_tag_test_even');
+ $matches = (array) json_decode($result->getContent());
+ $this->assertEqual(count($matches), 8, 'Make sure that only a subset is returned.');
+ foreach ($matches as $tag) {
+ $this->assertTrue(array_search($tag, $tags) !== FALSE, format_string('Make sure the returned tag @tag actually exists.'. array('@tag' => $tag)));
+ }
+
+ // Make sure an invalid result doesn't return anything.
+ $result = views_ui_autocomplete_tag($this->randomName());
+ $matches = (array) json_decode($result->getContent());
+ $this->assertEqual(count($matches), 0, "Make sure an invalid tag doesn't return anything.");
+ }
+
+}
diff --git a/views_ui/admin.inc b/views_ui/admin.inc
index b6a9db2..eeadc0e 100644
--- a/views_ui/admin.inc
+++ b/views_ui/admin.inc
@@ -6,6 +6,7 @@
*/
use Drupal\Core\Database\Database;
+use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\views_ui\ViewUI;
use Drupal\views\Analyzer;
use Drupal\views\Plugin\views\wizard\WizardException;
@@ -2483,8 +2484,8 @@ function views_ui_autocomplete_tag($string = '') {
// get matches from default views:
$views = views_get_all_views();
foreach ($views as $view) {
- if (!empty($view->storage->tag) && strpos($view->storage->tag, $string) === 0) {
- $matches[$view->storage->tag] = $view->storage->tag;
+ if (!empty($view->tag) && strpos($view->tag, $string) === 0) {
+ $matches[$view->tag] = $view->tag;
if (count($matches) >= 10) {
break;
}