Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ParamOverriderCartIdTest.php
Go to the documentation of this file.
1 <?php
8 
14 
18 class ParamOverriderCartIdTest extends \PHPUnit\Framework\TestCase
19 {
23  private $model;
24 
28  private $userContext;
29 
30  protected function setUp()
31  {
32  $this->userContext = $this->getMockBuilder(\Magento\Authorization\Model\UserContextInterface::class)
33  ->getMockForAbstractClass();
34  $this->cartManagement = $this->getMockBuilder(\Magento\Quote\Api\CartManagementInterface::class)
35  ->getMockForAbstractClass();
36  $this->model = (new ObjectManager($this))->getObject(
37  \Magento\Quote\Model\Webapi\ParamOverriderCartId::class,
38  [
39  'userContext' => $this->userContext,
40  'cartManagement' => $this->cartManagement,
41  ]
42  );
43  }
44 
46  {
47  $retValue = 'retValue';
48  $customerId = 1;
49 
50  $this->userContext->expects($this->once())
51  ->method('getUserType')
52  ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER));
53  $this->userContext->expects($this->once())
54  ->method('getUserId')
55  ->will($this->returnValue($customerId));
56 
57  $cart = $this->getMockBuilder(\Magento\Quote\Api\Data\CartInterface::class)
58  ->getMockForAbstractClass();
59  $this->cartManagement->expects($this->once())
60  ->method('getCartForCustomer')
61  ->with($customerId)
62  ->will($this->returnValue($cart));
63  $cart->expects($this->once())
64  ->method('getId')
65  ->will($this->returnValue($retValue));
66 
67  $this->assertSame($retValue, $this->model->getOverriddenValue());
68  }
69 
74  {
75  $customerId = 1;
76 
77  $this->userContext->expects($this->once())
78  ->method('getUserType')
79  ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER));
80  $this->userContext->expects($this->once())
81  ->method('getUserId')
82  ->will($this->returnValue($customerId));
83 
84  $this->cartManagement->expects($this->once())
85  ->method('getCartForCustomer')
86  ->with($customerId)
87  ->will($this->throwException(new NoSuchEntityException()));
88 
89  $this->model->getOverriddenValue();
90  }
91 
93  {
94  $customerId = 1;
95 
96  $this->userContext->expects($this->once())
97  ->method('getUserType')
98  ->will($this->returnValue(UserContextInterface::USER_TYPE_CUSTOMER));
99  $this->userContext->expects($this->once())
100  ->method('getUserId')
101  ->will($this->returnValue($customerId));
102 
103  $this->cartManagement->expects($this->once())
104  ->method('getCartForCustomer')
105  ->with($customerId)
106  ->will($this->returnValue(null));
107 
108  $this->assertNull($this->model->getOverriddenValue());
109  }
110 
112  {
113  $this->userContext->expects($this->once())
114  ->method('getUserType')
115  ->will($this->returnValue(UserContextInterface::USER_TYPE_ADMIN));
116 
117  $this->assertNull($this->model->getOverriddenValue());
118  }
119 }