Пример #1
0
 /**
  * Js configuration array for autocomplete
  *
  * @return array
  */
 public function getJsConfig()
 {
     $config = ["*" => ['Magento_Ui/js/core/app' => ['components' => ['autocompleteInjection' => ['component' => 'Mirasvit_SearchAutocomplete/js/injection', 'config' => []], 'autocomplete' => ['component' => 'Mirasvit_SearchAutocomplete/js/autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['query' => $this->searchHelper->getEscapedQueryText(), 'priceFormat' => $this->localeFormat->getPriceFormat()]], 'autocompleteProvider' => ['component' => 'Mirasvit_SearchAutocomplete/js/provider', 'config' => ['url' => $this->getUrl('searchautocomplete/ajax/suggest', ['_secure' => $this->getRequest()->isSecure()]), 'delay' => $this->config->getDelay(), 'minSearchLength' => $this->config->getMinChars()]], 'autocompleteNavigation' => ['component' => 'Mirasvit_SearchAutocomplete/js/navigation', 'autocomplete' => 'autocomplete']]]]];
     if ($this->config->isShowPopularSearches()) {
         $config['*']['Magento_Ui/js/core/app']['components']['autocompletePopular'] = ['component' => 'Mirasvit_SearchAutocomplete/js/popular', 'autocomplete' => 'autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['enabled' => $this->config->isShowPopularSearches(), 'queries' => $this->config->getPopularSearches()]];
     } else {
         $config['*']['Magento_Ui/js/core/app']['components']['autocompleteRecent'] = ['component' => 'Mirasvit_SearchAutocomplete/js/recent', 'autocomplete' => 'autocomplete', 'provider' => 'autocompleteProvider', 'config' => ['limit' => 5]];
     }
     return $config;
 }
Пример #2
0
 /**
  * @dataProvider queryTextDataProvider
  */
 public function testGetEscapedQueryText($queryText, $maxQueryLength, $expected)
 {
     $this->requestMock->expects($this->once())->method('getParam')->willReturn($queryText);
     $this->stringMock->expects($this->any())->method('cleanString')->willReturnArgument(0);
     $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($maxQueryLength);
     $this->stringMock->expects($this->any())->method('strlen')->will($this->returnCallback(function ($queryText) {
         return strlen($queryText);
     }));
     $this->stringMock->expects($this->any())->method('substr')->with($queryText, 0, $maxQueryLength)->willReturn($expected);
     $this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
     $this->assertEquals($expected, $this->model->getEscapedQueryText());
 }