Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExclusionStrategyTest.php
Go to the documentation of this file.
1 <?php
8 
17 
23 class ExclusionStrategyTest extends \PHPUnit\Framework\TestCase
24 {
28  private $model;
29 
33  private $resourceConnectionMock;
34 
38  private $adapterMock;
39 
43  private $storeManagerMock;
44 
48  private $aliasResolverMock;
49 
50  protected function setUp()
51  {
52  $this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
53  $this->adapterMock = $this->createMock(AdapterInterface::class);
54  $this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
55  $this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
56  $this->aliasResolverMock = $this->createMock(AliasResolver::class);
57 
58  $this->indexScopeResolverMock = $this->createMock(
59  \Magento\Framework\Search\Request\IndexScopeResolverInterface::class
60  );
61  $this->tableResolverMock = $this->createMock(
62  \Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver::class
63  );
64  $this->dimensionMock = $this->createMock(\Magento\Framework\Indexer\Dimension::class);
65  $this->dimensionFactoryMock = $this->createMock(\Magento\Framework\Indexer\DimensionFactory::class);
66  $this->dimensionFactoryMock->method('create')->willReturn($this->dimensionMock);
67  $storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
68  $storeMock->method('getId')->willReturn(1);
69  $storeMock->method('getWebsiteId')->willReturn(1);
70  $this->storeManagerMock->method('getStore')->willReturn($storeMock);
71  $this->indexScopeResolverMock->method('resolve')->willReturn('catalog_product_index_price');
72  $this->httpContextMock = $this->createMock(\Magento\Framework\App\Http\Context::class);
73  $this->httpContextMock->method('getValue')->willReturn(1);
74 
75  $this->model = new ExclusionStrategy(
76  $this->resourceConnectionMock,
77  $this->storeManagerMock,
78  $this->aliasResolverMock,
79  $this->tableResolverMock,
80  $this->dimensionFactoryMock,
81  $this->indexScopeResolverMock,
82  $this->httpContextMock
83  );
84  }
85 
87  {
88  $attributeCode = 'price';
89  $websiteId = 1;
90  $selectMock = $this->createMock(Select::class);
91  $selectMock->expects($this->any())->method('joinInner')->willReturnSelf();
92  $selectMock->expects($this->any())->method('getPart')->willReturn([]);
93 
94  $searchFilterMock = $this->createMock(Term::class);
95  $searchFilterMock->expects($this->any())->method('getField')->willReturn($attributeCode);
96 
97  $websiteMock = $this->createMock(WebsiteInterface::class);
98  $websiteMock->expects($this->any())->method('getId')->willReturn($websiteId);
99  $this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($websiteMock);
100 
101  $this->assertTrue($this->model->apply($searchFilterMock, $selectMock));
102  }
103 }
$attributeCode
Definition: extend.phtml:12