/** * @expectedException \Exception * @expectedExceptionMessage Cart contains virtual product(s) only. Shipping address is not applicable */ public function testGetAddressOfQuoteWithVirtualProducts() { $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false); $this->quoteLoaderMock->expects($this->once())->method('load')->with('cartId', '123')->will($this->returnValue($quoteMock)); $quoteMock->expects($this->any())->method('isVirtual')->will($this->returnValue(true)); $quoteMock->expects($this->never())->method('getShippingAddress'); $this->service->getAddress('cartId'); }
public function testGetAddress() { $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('get')->with('cartId')->will($this->returnValue($quoteMock)); $addressMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', [], [], '', false); $quoteMock->expects($this->any())->method('getBillingAddress')->will($this->returnValue($addressMock)); $this->converterMock->expects($this->once())->method('convertModelToDataObject')->with($addressMock)->will($this->returnValue('BillingAddress')); $this->assertEquals('BillingAddress', $this->service->getAddress('cartId')); }
public function testGetItemMessage() { $messageId = 123; $itemId = 2; $this->quoteMock->expects($this->once())->method('getItemById')->with($itemId)->will($this->returnValue($this->quoteItemMock)); $this->quoteItemMock->expects($this->once())->method('getGiftMessageId')->will($this->returnValue($messageId)); $this->messageFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->messageMock)); $this->messageMock->expects($this->once())->method('load')->with($messageId)->will($this->returnValue($this->messageMock)); $this->messageMapperMock->expects($this->once())->method('extractDto')->with($this->messageMock)->will($this->returnValue(['Expected value'])); $this->assertEquals(['Expected value'], $this->service->getItemMessage($this->cardId, $itemId)); }
public function testGetList() { $cartId = 10; $quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', [], [], '', false); $this->quoteRepositoryMock->expects($this->once())->method('get')->with($cartId)->will($this->returnValue($quoteMock)); $methodList = [$this->getMock('\\Magento\\Payment\\Model\\MethodInterface'), $this->getMock('\\Magento\\Payment\\Model\\MethodInterface')]; $this->methodListMock->expects($this->once())->method('getAvailableMethods')->with($quoteMock)->will($this->returnValue($methodList)); $paymentMethodMock = $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\PaymentMethod', [], [], '', false); $this->paymentMethodConverterMock->expects($this->atLeastOnce())->method('toDataObject')->will($this->returnValue($paymentMethodMock)); $expectedResult = [$this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\PaymentMethod', [], [], '', false), $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\PaymentMethod', [], [], '', false)]; $this->assertEquals($expectedResult, $this->service->getList($cartId)); }
public function testGetList() { $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false); $this->productRepositoryMock->expects($this->once())->method('get')->with('product_sku')->will($this->returnValue($productMock)); $value = ['price_type' => 'fixed', 'sku' => 'sku1', 'max_characters' => 10]; $options[] = [Data\Option::OPTION_ID => 10, Data\Option::TITLE => 'Some title', Data\Option::TYPE => 'text', Data\Option::IS_REQUIRE => true, Data\Option::SORT_ORDER => 10, Data\Option::METADATA => $value]; $methods = array('getId', 'getTitle', 'getType', 'getIsRequire', 'getSortOrder', '__wakeup'); $optionMock = $this->getMock('\\Magento\\Catalog\\Model\\Product\\Option', $methods, [], '', false); $optionData = $this->getMock('Magento\\Catalog\\Service\\V1\\Product\\CustomOptions\\Data\\Option', [], [], '', false); $productMock->expects($this->once())->method('getOptions')->will($this->returnValue(array($optionMock))); $optionMock->expects($this->once())->method('getId')->will($this->returnValue(10)); $optionMock->expects($this->once())->method('getTitle')->will($this->returnValue('Some title')); $optionMock->expects($this->once())->method('getType')->will($this->returnValue('text')); $optionMock->expects($this->once())->method('getIsRequire')->will($this->returnValue(true)); $optionMock->expects($this->once())->method('getSortOrder')->will($this->returnValue(10)); $this->optionMetadataReaderMock->expects($this->once())->method('read')->with($optionMock)->will($this->returnValue($value)); $this->optionBuilderMock->expects($this->once())->method('populateWithArray')->with($options[0])->will($this->returnSelf()); $this->optionBuilderMock->expects($this->once())->method('create')->will($this->returnValue($optionData)); $this->assertEquals(array($optionData), $this->service->getList('product_sku')); }