/** * Run test getAllOptions method * * @param bool $isEmpty * @param array $expected * @dataProvider dataProviderGetAllOptions */ public function testGetAllOptions($isEmpty, array $expected) { $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false); $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']); $taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true); $this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER)->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock); $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilter')->with([$filterMock])->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock); $this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock); if (!$isEmpty) { $taxClassMock->expects($this->once())->method('getClassId')->willReturn(10); $taxClassMock->expects($this->once())->method('getClassName')->willReturn('class-name'); $items = [$taxClassMock]; $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items); // checking of a lack of re-initialization for ($i = 10; --$i;) { $result = $this->customer->getAllOptions(); $this->assertEquals($expected, $result); } } else { $items = []; $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items); // checking exception $this->assertEmpty($this->customer->getAllOptions()); } }
/** * Run test getAllOptions method for names integrity * * @param array $value * @dataProvider dataProviderGetAllOptionsNameIntegrity */ public function testGetAllOptionsNameIntegrity(array $value) { $filterMock = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false); $searchCriteriaMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false); $searchResultsMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassSearchResultsInterface', [], '', false, true, true, ['getItems']); $taxClassMock = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', ['getClassId', 'getClassName'], '', false, true, true); $this->filterBuilderMock->expects($this->once())->method('setField')->with(\Magento\Tax\Model\ClassModel::KEY_TYPE)->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('setValue')->with(\Magento\Tax\Api\TaxClassManagementInterface::TYPE_PRODUCT)->willReturnSelf(); $this->filterBuilderMock->expects($this->once())->method('create')->willReturn($filterMock); $this->searchCriteriaBuilderMock->expects($this->once())->method('addFilters')->with([$filterMock])->willReturnSelf(); $this->searchCriteriaBuilderMock->expects($this->once())->method('create')->willReturn($searchCriteriaMock); $this->taxClassRepositoryMock->expects($this->once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultsMock); $taxClassMock->expects($this->once())->method('getClassId')->willReturn($value['value']); $taxClassMock->expects($this->once())->method('getClassName')->willReturn($value['label']); $items = [$taxClassMock]; $searchResultsMock->expects($this->once())->method('getItems')->willReturn($items); $result = $this->product->getAllOptions(false); $expected = $value; $this->assertEquals([$expected], $result); }
/** * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException */ public function testSaveWithException() { $taxClass = $this->getMockForAbstractClass('Magento\\Tax\\Api\\Data\\TaxClassInterface', [], '', false); $this->groupFactory->expects($this->once())->method('create')->willReturn($this->groupModel); $this->group->expects($this->atLeastOnce())->method('getCode')->willReturn('Code'); $this->group->expects($this->atLeastOnce())->method('getId')->willReturn(false); $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(234); $this->group->expects($this->atLeastOnce())->method('getTaxClassId')->willReturn(17); $this->groupModel->expects($this->once())->method('setCode')->with('Code'); $this->groupModel->expects($this->once())->method('setTaxClassId')->with(234); $this->taxClassRepository->expects($this->once())->method('get')->with(234)->willReturn($taxClass); $taxClass->expects($this->once())->method('getClassType')->willReturn('CUSTOMER'); $this->groupResourceModel->expects($this->once())->method('save')->with($this->groupModel)->willThrowException(new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Customer Group already exists.'))); $this->model->save($this->group); }