示例#1
0
 public function testCreateEmptyCartAnonymous()
 {
     $storeId = 345;
     $quoteId = 2311;
     $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quoteRepositoryMock->expects($this->once())->method('create')->willReturn($quoteMock);
     $quoteMock->expects($this->any())->method('setStoreId')->with($storeId);
     $this->quoteRepositoryMock->expects($this->once())->method('save')->with($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturnSelf();
     $this->storeManagerMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
     $this->assertEquals($quoteId, $this->model->createEmptyCart());
 }
 /**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  */
 public function testCreateEmptyCartLoggedInUserException()
 {
     $storeId = 345;
     $userId = 567;
     $quoteMock = $this->getMock('\\Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->userContextMock->expects($this->once())->method('getUserType')->willReturn(\Magento\Authorization\Model\UserContextInterface::USER_TYPE_CUSTOMER);
     $this->userContextMock->expects($this->atLeastOnce())->method('getUserId')->willReturn($userId);
     $customerMock = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($userId)->willReturn($customerMock);
     $this->quoteRepositoryMock->expects($this->once())->method('getActiveForCustomer')->with($userId);
     $this->quoteRepositoryMock->expects($this->never())->method('create')->willReturn($quoteMock);
     $this->quoteRepositoryMock->expects($this->never())->method('save')->with($quoteMock);
     $this->model->createEmptyCart($storeId);
 }