FulltextGridSearchTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Cms\Controller\Adminhtml;
  8. use Magento\TestFramework\TestCase\AbstractBackendController;
  9. /**
  10. * @magentoDataFixture Magento/Cms/Fixtures/page_list.php
  11. */
  12. class FulltextGridSearchTest extends AbstractBackendController
  13. {
  14. /**
  15. * Checks a fulltext grid search by CMS page title.
  16. *
  17. * @param string $query
  18. * @param int $expectedRows
  19. * @param array $expectedTitles
  20. * @dataProvider queryDataProvider
  21. */
  22. public function testSearchByTitle(string $query, int $expectedRows, array $expectedTitles)
  23. {
  24. $url = 'backend/mui/index/render/?namespace=cms_page_listing&search=' . $query;
  25. $this->getRequest()
  26. ->getHeaders()
  27. ->addHeaderLine('Accept', 'application/json');
  28. $this->dispatch($url);
  29. $response = $this->getResponse();
  30. $data = json_decode($response->getBody(), true);
  31. self::assertEquals($expectedRows, $data['totalRecords']);
  32. $titleList = array_column($data['items'], 'title');
  33. self::assertEquals($expectedTitles, $titleList);
  34. }
  35. /**
  36. * Gets list of variations with different search queries.
  37. *
  38. * @return array
  39. */
  40. public function queryDataProvider(): array
  41. {
  42. return [
  43. [
  44. 'query' => 'simple',
  45. 'expectedRows' => 3,
  46. 'expectedTitles' => ['simplePage', 'simplePage01', '01simplePage']
  47. ],
  48. [
  49. 'query' => 'page01',
  50. 'expectedRows' => 1,
  51. 'expectedTitles' => ['simplePage01']
  52. ],
  53. [
  54. 'query' => '01simple',
  55. 'expectedRows' => 1,
  56. 'expectedTitles' => ['01simplePage']
  57. ],
  58. ];
  59. }
  60. }