EngineResolverTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Test\Unit\Model;
  7. use Magento\Search\Model\EngineResolver;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Psr\Log\LoggerInterface;
  10. class EngineResolverTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Search\Model\EngineResolver
  14. */
  15. private $model;
  16. /**
  17. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $scopeConfig;
  20. /**
  21. * @var string|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. private $path;
  24. /**
  25. * @var string|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $scopeType;
  28. /**
  29. * @var null|string|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $scopeCode;
  32. /**
  33. * @var string[]
  34. */
  35. private $engines = [];
  36. /**
  37. * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
  38. */
  39. private $loggerMock;
  40. /**
  41. * Setup
  42. *
  43. * @return void
  44. */
  45. protected function setUp()
  46. {
  47. $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
  48. ->disableOriginalConstructor()
  49. ->getMock();
  50. $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
  51. ->getMockForAbstractClass();
  52. $this->path = 'catalog/search/engine';
  53. $this->scopeType = 'default';
  54. $this->scopeCode = null;
  55. $this->engines = [EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, 'anotherengine'];
  56. $this->model = new EngineResolver(
  57. $this->scopeConfig,
  58. $this->engines,
  59. $this->loggerMock,
  60. $this->path,
  61. $this->scopeType,
  62. $this->scopeCode
  63. );
  64. }
  65. /**
  66. * Test getCurrentSearchEngine
  67. */
  68. public function testGetCurrentSearchEngine()
  69. {
  70. $engine = 'anotherengine';
  71. $this->scopeConfig->expects($this->any())
  72. ->method('getValue')
  73. ->willReturn($engine);
  74. $this->assertEquals($engine, $this->model->getCurrentSearchEngine());
  75. }
  76. /**
  77. * Test getCurrentSearchEngine
  78. */
  79. public function testGetCurrentSearchEngineWithoutEngine()
  80. {
  81. $engine = 'nonexistentengine';
  82. $this->scopeConfig->expects($this->any())
  83. ->method('getValue')
  84. ->willReturn($engine);
  85. $this->loggerMock->expects($this->any())
  86. ->method('error')
  87. ->with(
  88. $engine . ' search engine doesn\'t exists. Falling back to '
  89. . EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE
  90. );
  91. $this->assertEquals(EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, $this->model->getCurrentSearchEngine());
  92. }
  93. }