SearchTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Api\Search;
  7. use Magento\TestFramework\TestCase\WebapiAbstract;
  8. class SearchTest extends WebapiAbstract
  9. {
  10. const SERVICE_NAME = 'searchV1';
  11. const SERVICE_VERSION = 'V1';
  12. const RESOURCE_PATH = '/V1/search';
  13. /**
  14. * @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
  15. * @covers \Magento\Framework\Search\Search::search
  16. */
  17. public function testCatalogSearch()
  18. {
  19. $searchCriteria = [
  20. 'searchCriteria' => [
  21. 'request_name' => 'quick_search_container',
  22. 'filter_groups' => [
  23. [
  24. 'filters' => [
  25. [
  26. 'field' => 'search_term',
  27. 'value' => 'simple',
  28. 'condition_type' => 'eq'
  29. ],
  30. [
  31. 'field' => 'price_dynamic_algorithm',
  32. 'value' => 'auto',
  33. 'condition_type' => 'eq'
  34. ]
  35. ]
  36. ]
  37. ],
  38. 'page_size' => 20000000000000,
  39. 'current_page' => 0,
  40. ],
  41. ];
  42. $serviceInfo = [
  43. 'rest' => [
  44. 'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
  45. 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
  46. ],
  47. 'soap' => [
  48. 'service' => self::SERVICE_NAME,
  49. 'serviceVersion' => self::SERVICE_VERSION,
  50. 'operation' => self::SERVICE_NAME . 'Search',
  51. ],
  52. ];
  53. $response = $this->_webApiCall($serviceInfo, $searchCriteria);
  54. $this->assertArrayHasKey('search_criteria', $response);
  55. $this->assertArrayHasKey('total_count', $response);
  56. $this->assertArrayHasKey('items', $response);
  57. $this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
  58. $this->assertTrue($response['total_count'] > 0);
  59. $this->assertTrue(count($response['items']) > 0);
  60. $this->assertNotNull($response['items'][0]['id']);
  61. $this->assertEquals('score', $response['items'][0]['custom_attributes'][0]['attribute_code']);
  62. $this->assertTrue($response['items'][0]['custom_attributes'][0]['value'] > 0);
  63. }
  64. }