SearchIndexNameResolverTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Elasticsearch\Test\Unit\SearchAdapter;
  7. use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver;
  8. use Magento\AdvancedSearch\Model\Client\ClientOptionsInterface;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  10. class SearchIndexNameResolverTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var SearchIndexNameResolver
  14. */
  15. protected $model;
  16. /**
  17. * @var ClientOptionsInterface|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $clientConfig;
  20. /**
  21. * @var ObjectManagerHelper
  22. */
  23. protected $objectManager;
  24. /**
  25. * @var string
  26. */
  27. protected $indexId;
  28. /**
  29. * @var int
  30. */
  31. protected $storeId;
  32. /**
  33. * Setup method
  34. * @return void
  35. */
  36. protected function setUp()
  37. {
  38. $this->clientConfig = $this->getMockBuilder(\Magento\Elasticsearch\Model\Config::class)
  39. ->disableOriginalConstructor()
  40. ->setMethods([
  41. 'getIndexPrefix',
  42. 'getEntityType',
  43. 'getIndexSettings',
  44. ])
  45. ->getMock();
  46. $this->clientConfig->expects($this->any())
  47. ->method('getIndexPrefix')
  48. ->willReturn('indexName');
  49. $this->indexId = 'catalogsearch_fulltext';
  50. $this->storeId = 1;
  51. $objectManager = new ObjectManagerHelper($this);
  52. $this->model = $objectManager->getObject(
  53. \Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver::class,
  54. [
  55. 'clientConfig' => $this->clientConfig,
  56. ]
  57. );
  58. }
  59. /**
  60. * Test getIndexName() indexerId 'catalogsearch_fulltext'
  61. */
  62. public function testGetIndexNameCatalogSearchFullText()
  63. {
  64. $this->assertEquals(
  65. 'indexName_product_1',
  66. $this->model->getIndexName($this->storeId, $this->indexId)
  67. );
  68. }
  69. /**
  70. * Test getIndexName() with any ndex
  71. */
  72. public function testGetIndexName()
  73. {
  74. $this->assertEquals(
  75. 'indexName_else_index_id_1',
  76. $this->model->getIndexName($this->storeId, 'else_index_id')
  77. );
  78. }
  79. }