|
16 | 16 |
|
17 | 17 | /**
|
18 | 18 | * Unit test for \Magento\Quote\Model\ChangeQuoteControl
|
19 |
| - * |
20 |
| - * Class \Magento\Quote\Test\Unit\Model\ChangeQuoteControlTest |
21 | 19 | */
|
22 | 20 | class ChangeQuoteControlTest extends TestCase
|
23 | 21 | {
|
24 |
| - /** |
25 |
| - * @var ObjectManager |
26 |
| - */ |
27 |
| - protected $objectManager; |
28 |
| - |
29 | 22 | /**
|
30 | 23 | * @var ChangeQuoteControl
|
31 | 24 | */
|
32 | 25 | protected $model;
|
33 | 26 |
|
34 | 27 | /**
|
35 |
| - * @var MockObject |
| 28 | + * @var MockObject|UserContextInterface |
36 | 29 | */
|
37 | 30 | protected $userContextMock;
|
38 | 31 |
|
39 | 32 | /**
|
40 |
| - * @var MockObject |
| 33 | + * @var MockObject|CartInterface |
41 | 34 | */
|
42 | 35 | protected $quoteMock;
|
43 | 36 |
|
44 | 37 | protected function setUp(): void
|
45 | 38 | {
|
46 |
| - $this->objectManager = new ObjectManager($this); |
47 | 39 | $this->userContextMock = $this->getMockForAbstractClass(UserContextInterface::class);
|
48 | 40 |
|
49 |
| - $this->model = $this->objectManager->getObject( |
50 |
| - ChangeQuoteControl::class, |
51 |
| - [ |
52 |
| - 'userContext' => $this->userContextMock |
53 |
| - ] |
54 |
| - ); |
55 |
| - |
56 |
| - $this->quoteMock = $this->getMockForAbstractClass( |
57 |
| - CartInterface::class, |
58 |
| - [], |
59 |
| - '', |
60 |
| - false, |
61 |
| - true, |
62 |
| - true, |
63 |
| - ['getCustomerId'] |
64 |
| - ); |
| 41 | + $this->model = new ChangeQuoteControl($this->userContextMock); |
| 42 | + |
| 43 | + $this->quoteMock = $this->getMockBuilder(CartInterface::class) |
| 44 | + ->disableOriginalConstructor() |
| 45 | + ->addMethods(['getCustomerId']) |
| 46 | + ->getMockForAbstractClass(); |
65 | 47 | }
|
66 | 48 |
|
67 |
| - /** |
68 |
| - * Test if the quote is belonged to customer |
69 |
| - */ |
70 | 49 | public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
|
71 | 50 | {
|
72 | 51 | $quoteCustomerId = 1;
|
73 |
| - $this->quoteMock->expects($this->any())->method('getCustomerId') |
| 52 | + $this->quoteMock->method('getCustomerId') |
74 | 53 | ->willReturn($quoteCustomerId);
|
75 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 54 | + $this->userContextMock->method('getUserType') |
76 | 55 | ->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
|
77 |
| - $this->userContextMock->expects($this->any())->method('getUserId') |
| 56 | + $this->userContextMock->method('getUserId') |
78 | 57 | ->willReturn($quoteCustomerId);
|
79 | 58 |
|
80 | 59 | $this->assertTrue($this->model->isAllowed($this->quoteMock));
|
81 | 60 | }
|
82 | 61 |
|
83 |
| - /** |
84 |
| - * Test if the quote is not belonged to customer |
85 |
| - */ |
86 | 62 | public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
|
87 | 63 | {
|
88 | 64 | $currentCustomerId = 1;
|
89 | 65 | $quoteCustomerId = 2;
|
90 | 66 |
|
91 |
| - $this->quoteMock->expects($this->any())->method('getCustomerId') |
| 67 | + $this->quoteMock->method('getCustomerId') |
92 | 68 | ->willReturn($quoteCustomerId);
|
93 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 69 | + $this->userContextMock->method('getUserType') |
94 | 70 | ->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
|
95 |
| - $this->userContextMock->expects($this->any())->method('getUserId') |
| 71 | + $this->userContextMock->method('getUserId') |
96 | 72 | ->willReturn($currentCustomerId);
|
97 | 73 |
|
98 | 74 | $this->assertFalse($this->model->isAllowed($this->quoteMock));
|
99 | 75 | }
|
100 | 76 |
|
101 |
| - /** |
102 |
| - * Test if the quote is belonged to guest and the context is guest |
103 |
| - */ |
104 | 77 | public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
|
105 | 78 | {
|
106 | 79 | $quoteCustomerId = null;
|
107 |
| - $this->quoteMock->expects($this->any())->method('getCustomerId') |
| 80 | + $this->quoteMock->method('getCustomerId') |
108 | 81 | ->willReturn($quoteCustomerId);
|
109 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 82 | + $this->userContextMock->method('getUserType') |
110 | 83 | ->willReturn(UserContextInterface::USER_TYPE_GUEST);
|
111 | 84 | $this->assertTrue($this->model->isAllowed($this->quoteMock));
|
112 | 85 | }
|
113 | 86 |
|
114 |
| - /** |
115 |
| - * Test if the quote is belonged to customer and the context is guest |
116 |
| - */ |
117 | 87 | public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
|
118 | 88 | {
|
119 | 89 | $quoteCustomerId = 1;
|
120 |
| - $this->quoteMock->expects($this->any())->method('getCustomerId') |
| 90 | + $this->quoteMock->method('getCustomerId') |
121 | 91 | ->willReturn($quoteCustomerId);
|
122 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 92 | + $this->userContextMock->method('getUserType') |
123 | 93 | ->willReturn(UserContextInterface::USER_TYPE_GUEST);
|
124 | 94 | $this->assertFalse($this->model->isAllowed($this->quoteMock));
|
125 | 95 | }
|
126 | 96 |
|
127 |
| - /** |
128 |
| - * Test if the context is admin |
129 |
| - */ |
130 | 97 | public function testIsAllowedIfContextIsAdmin()
|
131 | 98 | {
|
132 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 99 | + $this->userContextMock->method('getUserType') |
133 | 100 | ->willReturn(UserContextInterface::USER_TYPE_ADMIN);
|
134 | 101 | $this->assertTrue($this->model->isAllowed($this->quoteMock));
|
135 | 102 | }
|
136 | 103 |
|
137 |
| - /** |
138 |
| - * Test if the context is integration |
139 |
| - */ |
140 | 104 | public function testIsAllowedIfContextIsIntegration()
|
141 | 105 | {
|
142 |
| - $this->userContextMock->expects($this->any())->method('getUserType') |
| 106 | + $this->userContextMock->method('getUserType') |
143 | 107 | ->willReturn(UserContextInterface::USER_TYPE_INTEGRATION);
|
144 | 108 | $this->assertTrue($this->model->isAllowed($this->quoteMock));
|
145 | 109 | }
|
|
0 commit comments