Commit 95273b80 authored by catch's avatar catch
Browse files

Issue #3269085 by alexpott, larowlan, danflanagan8, Matroskeen: [random test...

Issue #3269085 by alexpott, larowlan, danflanagan8, Matroskeen: [random test failure] Random test fail in EntityAutocompleteTest
parent b26aa84f
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -80,8 +80,7 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha
    // Get the typed string from the URL, if it exists.
    if ($input = $request->query->get('q')) {
      $tag_list = Tags::explode($input);
      if (!empty($tag_list)) {
        $typed_string = mb_strtolower(array_pop($tag_list));
      $typed_string = !empty($tag_list) ? mb_strtolower(array_pop($tag_list)) : '';

      // Selection settings are passed in as a hashed key of a serialized array
      // stored in the key/value store.
@@ -102,7 +101,6 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha

      $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string);
    }
    }

    return new JsonResponse($matches);
  }
+15 −1
Original line number Diff line number Diff line
@@ -89,9 +89,23 @@ public function testEntityReferenceAutocompletion() {
    ];
    $this->assertSame($target, reset($data), 'Autocomplete returns an entity label containing a comma and a slash.');

    $input = '';
    $data = $this->getAutocompleteResult($input);
    $this->assertSame([], $data, 'Autocomplete of empty string returns empty result');

    $input = ',';
    $data = $this->getAutocompleteResult($input);
    $this->assertSame(Html::escape($entity_1->name->value), $data[0]['label'], 'Autocomplete returned the first matching entity');
    $this->assertSame(Html::escape($entity_2->name->value), $data[1]['label'], 'Autocomplete returned the second matching entity');
    $this->assertSame(Html::escape($entity_3->name->value), $data[2]['label'], 'Autocomplete returned the third matching entity');

    // Strange input that is mangled by
    // \Drupal\Component\Utility\Tags::explode().
    $input = '"l!J>&Tw';
    $data = $this->getAutocompleteResult($input);
    $this->assertSame([], $data, 'Autocomplete of invalid string returns empty result');
    $this->assertSame(Html::escape($entity_1->name->value), $data[0]['label'], 'Autocomplete returned the first matching entity');
    $this->assertSame(Html::escape($entity_2->name->value), $data[1]['label'], 'Autocomplete returned the second matching entity');
    $this->assertSame(Html::escape($entity_3->name->value), $data[2]['label'], 'Autocomplete returned the third matching entity');
  }

  /**