public function testGetListReturnsTheListOfActiveCheckoutAgreements() { $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE, null)->will($this->returnValue(true)); $agreementDataObject = $this->getMock('Magento\\CheckoutAgreements\\Model\\Agreement', [], [], '', false); $storeId = 1; $storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false); $storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId)); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $collectionMock = $this->objectManager->getCollectionMock('Magento\\CheckoutAgreements\\Model\\Resource\\Agreement\\Collection', [$agreementDataObject]); $this->factoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock)); $collectionMock->expects($this->once())->method('addStoreFilter')->with($storeId); $collectionMock->expects($this->once())->method('addFieldToFilter')->with('is_active', 1); $this->assertEquals([$agreementDataObject], $this->model->getList()); }
public function testGetListReturnsTheListOfActiveCheckoutAgreements() { $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE, null)->will($this->returnValue(true)); $agreementData = array('id' => 1, 'name' => 'Checkout Agreement', 'content' => 'Agreement content: <b>HTML</b>', 'content_height' => '100px', 'checkbox_text' => 'Checkout Agreement Checkbox Text', 'active' => true, 'html' => true); $storeId = 1; $storeMock = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false); $storeMock->expects($this->any())->method('getId')->will($this->returnValue($storeId)); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock)); $collectionMock = $this->objectManager->getCollectionMock('Magento\\CheckoutAgreements\\Model\\Resource\\Agreement\\Collection', array($this->getAgreementMock($agreementData))); $this->factoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock)); $collectionMock->expects($this->once())->method('addStoreFilter')->with($storeId); $collectionMock->expects($this->once())->method('addFieldToFilter')->with('is_active', 1); $agreementDataObject = $this->getMock('Magento\\CheckoutAgreements\\Service\\V1\\Data\\Agreement', array(), array(), '', false); $this->agreementBuilderMock->expects($this->once())->method('populateWithArray')->with($agreementData); $this->agreementBuilderMock->expects($this->once())->method('create')->will($this->returnValue($agreementDataObject)); $this->assertEquals(array($agreementDataObject), $this->service->getList()); }
/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testBuildPositive() { //prepare mocks and data samples $instance = $this->getMock('Magento\\Bundle\\Model\\Product\\Type', array('setStoreFilter', 'getOptionsCollection', 'getSelectionsCollection', 'getOptionsIds'), array(), '', false); $option = $this->getMock('Magento\\Bundle\\Model\\Option', array('getSelections', '__wakeup', 'getData'), array(), '', false); $options = array($option); $optionCollection = $this->objectManager->getCollectionMock('Magento\\Bundle\\Model\\Resource\\Option\\Collection', $options); $optionRawData = array(array('required' => true, 'position' => 100, 'type' => 'someType', 'title' => 'title', 'delete' => '')); $selectionRawData = array(array(array('product_id' => 123, 'position' => 500, 'is_default' => false, 'selection_price_type' => 'priceType', 'selection_price_value' => 'priceVal', 'selection_qty' => 21, 'selection_can_change_qty' => 11, 'delete' => ''))); $selection = $this->getMock('Magento\\Bundle\\Model\\Selection', array('getProductId', 'getPosition', 'getIsDefault', 'getSelectionPriceType', 'getSelectionPriceValue', 'getSelectionQty', 'getSelectionCanChangeQty', '__wakeup'), array(), '', false); $selections = array($selection); $selectionCollection = $this->getMock('Magento\\Bundle\\Model\\Resource\\Selection\\Collection', array(), array(), '', false); // method flow $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('bundle')); $this->product->expects($this->any())->method('getTypeInstance')->will($this->returnValue($instance)); $instance->expects($this->once())->method('setStoreFilter')->with(null, $this->product); $instance->expects($this->once())->method('getOptionsCollection')->with($this->product)->will($this->returnValue($optionCollection)); $instance->expects($this->once())->method('getSelectionsCollection')->with(null, $this->product)->will($this->returnValue($selectionCollection)); $optionCollection->expects($this->once())->method('appendSelections')->with($selectionCollection); $option->expects($this->any())->method('getSelections')->will($this->returnValue($selections)); $option->expects($this->at(0))->method('getData')->with('required')->will($this->returnValue(true)); $option->expects($this->at(1))->method('getData')->with('position')->will($this->returnValue(100)); $option->expects($this->at(2))->method('getData')->with('type')->will($this->returnValue('someType')); $option->expects($this->at(3))->method('getData')->with('title')->will($this->returnValue('title')); $option->expects($this->at(4))->method('getData')->with('title')->will($this->returnValue('title')); $selection->expects($this->once())->method('getProductId')->will($this->returnValue(123)); $selection->expects($this->once())->method('getPosition')->will($this->returnValue(500)); $selection->expects($this->once())->method('getIsDefault')->will($this->returnValue(false)); $selection->expects($this->once())->method('getSelectionPriceType')->will($this->returnValue('priceType')); $selection->expects($this->once())->method('getSelectionPriceValue')->will($this->returnValue('priceVal')); $selection->expects($this->once())->method('getSelectionQty')->will($this->returnValue(21)); $selection->expects($this->once())->method('getSelectionCanChangeQty')->will($this->returnValue(11)); $this->duplicate->expects($this->once())->method('setBundleOptionsData')->with($optionRawData); $this->duplicate->expects($this->once())->method('setBundleSelectionsData')->with($selectionRawData); $this->model->build($this->product, $this->duplicate); }
public function testGetListWhenFilterGroupExists() { $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaInterface'); $filterGroupMock = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false); $searchCriteriaMock->expects($this->any())->method('getFilterGroups')->will($this->returnValue([$filterGroupMock])); $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false); $filterGroupMock->expects($this->once())->method('getFilters')->willReturn([$filterMock]); $filterMock->expects($this->exactly(2))->method('getConditionType')->willReturn('like'); $filterMock->expects($this->once())->method('getField')->willReturn('region_name'); $filterMock->expects($this->once())->method('getValue')->willReturn('condition_value'); $objectManager = new ObjectManager($this); $rateMock = $this->getTaxRateMock([]); $items = [$rateMock]; $collectionMock = $objectManager->getCollectionMock('Magento\\Tax\\Model\\Resource\\Calculation\\Rate\\Collection', $items); $collectionMock->expects($this->once())->method('addFieldToFilter')->with(['region_table.code'], [['like' => 'condition_value']]); $sortOrderMock = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false); $searchCriteriaMock->expects($this->any())->method('getSortOrders')->will($this->returnValue([$sortOrderMock])); $sortOrderMock->expects($this->once())->method('getField')->willReturn('field_name'); $sortOrderMock->expects($this->once())->method('getDirection')->willReturn(SearchCriteria::SORT_ASC); $collectionMock->expects($this->once())->method('addOrder')->with('main_table.field_name', 'ASC'); $currentPage = 1; $pageSize = 100; $searchCriteriaMock->expects($this->any())->method('getCurrentPage')->will($this->returnValue($currentPage)); $searchCriteriaMock->expects($this->any())->method('getPageSize')->will($this->returnValue($pageSize)); $rateMock = $this->getTaxRateMock([]); $collectionMock->expects($this->once())->method('joinRegionTable'); $collectionMock->expects($this->once())->method('setCurPage')->with($currentPage); $collectionMock->expects($this->once())->method('setPageSize')->with($pageSize); $collectionMock->expects($this->once())->method('getSize')->will($this->returnValue(count($items))); $this->rateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($rateMock)); $rateMock->expects($this->any())->method('getCollection')->will($this->returnValue($collectionMock)); $this->searchResultBuilder->expects($this->once())->method('setItems')->with($items)->willReturnSelf(); $this->searchResultBuilder->expects($this->once())->method('setTotalCount')->with(count($items))->willReturnSelf(); $this->searchResultBuilder->expects($this->once())->method('setSearchCriteria')->with($searchCriteriaMock)->willReturnSelf(); $this->searchResultBuilder->expects($this->once())->method('create'); $this->model->getList($searchCriteriaMock); }