Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SearchTermManagerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class SearchTermManagerTest extends \PHPUnit\Framework\TestCase
9 {
13  private $searchTermManager;
14 
18  private $totalProductsCount = 150;
19 
23  private $searchTermConfiguration = [
24  [
25  'term' => 'x-wing',
26  'count' => '33'
27  ], [
28  'term' => 'tie-fighter',
29  'count' => '100'
30  ], [
31  'term' => 'n-1 starfighter',
32  'count' => '42'
33  ],
34  ];
35 
39  private $searchTermsUsage = [
40  'x-wing' => [
41  'used' => 0
42  ],
43  'tie-fighter' => [
44  'used' => 0
45  ],
46  'n-1 starfighter' => [
47  'used' => 0
48  ]
49  ];
50 
51  public function setUp()
52  {
53  $this->searchTermManager = new \Magento\Setup\Model\SearchTermManager(
54  $this->searchTermConfiguration,
55  $this->totalProductsCount
56  );
57  }
58 
59  public function testSearchTermApplied()
60  {
61  for ($productIndex=1; $productIndex<=$this->totalProductsCount; $productIndex++) {
62  $description = 'Fleet: ';
63  $this->searchTermManager->applySearchTermsToDescription($description, $productIndex);
64 
65  foreach (array_keys($this->searchTermsUsage) as $searchTerm) {
66  if (preg_match("/\\b$searchTerm\\b/", $description)) {
67  $this->searchTermsUsage[$searchTerm]['used']++;
68  }
69  }
70  }
71 
72  foreach ($this->searchTermConfiguration as $searchTerm) {
73  $this->assertEquals($searchTerm['count'], $this->searchTermsUsage[$searchTerm['term']]['used']);
74  }
75  }
76 }