SynonymAnalyzerTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Model;
  7. /**
  8. * @magentoDataFixture Magento/Search/_files/synonym_reader.php
  9. * @magentoDbIsolation disabled
  10. */
  11. class SynonymAnalyzerTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Search\Model\SynonymAnalyzer
  15. */
  16. private $synAnalyzer;
  17. protected function setUp()
  18. {
  19. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  20. $this->synAnalyzer = $objectManager->get(\Magento\Search\Model\SynonymAnalyzer::class);
  21. }
  22. /**
  23. * Data provider for the test
  24. *
  25. * @return array
  26. */
  27. public static function loadGetSynonymsForPhraseDataProvider()
  28. {
  29. return [
  30. 'WithSynonymsFromStoreViewScope' => [
  31. 'phrase' => 'elizabeth is the english queen',
  32. 'expectedResult' => [['elizabeth'],['is'],['the'],['british', 'english'],['queen', 'monarch']]
  33. ],
  34. 'WithSynonymsFromWebsiteScope' => [
  35. 'phrase' => 'orange hill',
  36. 'expectedResult' => [['orange', 'magento'], ['hill', 'mountain', 'peak']]
  37. ],
  38. 'WithSynonymsFromDefaultScope' => [
  39. 'phrase' => 'universe is enormous',
  40. 'expectedResult' => [['universe', 'cosmos'], ['is'], ['big', 'huge', 'large', 'enormous']]
  41. ],
  42. 'WithCaseMismatch' => [
  43. 'phrase' => 'GNU\'s Not Unix',
  44. 'expectedResult' => [['GNU\'s'], ['Not'], ['unix', 'linux'],]
  45. ],
  46. 'WithMultiWordPhrase' => [
  47. 'phrase' => 'Coastline of Great Britain stretches for 11,073 miles',
  48. 'expectedResult' => [
  49. ['Coastline'],
  50. ['of'],
  51. ['Great Britain', 'United Kingdom'],
  52. ['Britain'],
  53. ['stretches'],
  54. ['for'],
  55. ['11,073'],
  56. ['miles']
  57. ]
  58. ],
  59. 'PartialSynonymMatching' => [
  60. 'phrase' => 'Magento Engineering',
  61. 'expectedResult' => [
  62. ['orange', 'magento'],
  63. ['Engineering', 'Technical Staff']
  64. ]
  65. ],
  66. 'noSynonyms' => [
  67. 'phrase' => 'this sentence has no synonyms',
  68. 'expectedResult' => [['this'], ['sentence'], ['has'], ['no'], ['synonyms']]
  69. ],
  70. 'multipleSpaces' => [
  71. 'phrase' => 'GNU\'s Not Unix',
  72. 'expectedResult' => [['GNU\'s'], ['Not'], ['unix', 'linux'],]
  73. ],
  74. 'oneMoreTest' => [
  75. 'phrase' => 'schlicht',
  76. 'expectedResult' => [['schlicht', 'natürlich']]
  77. ],
  78. ];
  79. }
  80. /**
  81. * @param string $phrase
  82. * @param array $expectedResult
  83. * @dataProvider loadGetSynonymsForPhraseDataProvider
  84. */
  85. public function testGetSynonymsForPhrase($phrase, $expectedResult)
  86. {
  87. $synonyms = $this->synAnalyzer->getSynonymsForPhrase($phrase);
  88. $this->assertEquals($expectedResult, $synonyms);
  89. }
  90. }