agreementCollFactoryMock = $this->createPartialMock( \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\CollectionFactory::class, ['create'] ); $this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); $this->model = $objectManager->getObject( \Magento\CheckoutAgreements\Model\AgreementsProvider::class, [ 'agreementCollectionFactory' => $this->agreementCollFactoryMock, 'storeManager' => $this->storeManagerMock, 'scopeConfig' => $this->scopeConfigMock ] ); } public function testGetRequiredAgreementIdsIfAgreementsEnabled() { $storeId = 100; $expectedResult = [1, 2, 3, 4, 5]; $this->scopeConfigMock->expects($this->once()) ->method('isSetFlag') ->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE) ->willReturn(true); $agreementCollection = $this->createMock( \Magento\CheckoutAgreements\Model\ResourceModel\Agreement\Collection::class ); $this->agreementCollFactoryMock->expects($this->once())->method('create')->willReturn($agreementCollection); $storeMock = $this->createMock(\Magento\Store\Model\Store::class); $storeMock->expects($this->once())->method('getId')->willReturn($storeId); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); $agreementCollection->expects($this->once())->method('addStoreFilter')->with($storeId)->willReturnSelf(); $agreementCollection->expects($this->at(1)) ->method('addFieldToFilter') ->with('is_active', 1) ->willReturnSelf(); $agreementCollection->expects($this->at(2)) ->method('addFieldToFilter') ->with('mode', AgreementModeOptions::MODE_MANUAL) ->willReturnSelf(); $agreementCollection->expects($this->once())->method('getAllIds')->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds()); } public function testGetRequiredAgreementIdsIfAgreementsDisabled() { $expectedResult = []; $this->scopeConfigMock->expects($this->once()) ->method('isSetFlag') ->with(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE) ->willReturn(false); $this->assertEquals($expectedResult, $this->model->getRequiredAgreementIds()); } }