Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AccessChangeQuoteControlTest.php
Go to the documentation of this file.
1 <?php
8 
15 use \PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
17 class AccessChangeQuoteControlTest extends \PHPUnit\Framework\TestCase
18 {
22  private $accessChangeQuoteControl;
23 
27  private $userContextMock;
28 
32  private $quoteMock;
33 
37  private $quoteRepositoryMock;
38 
42  private $changeQuoteControlMock;
43 
44  protected function setUp()
45  {
46  $this->userContextMock = $this->getMockBuilder(UserContextInterface::class)
47  ->getMockForAbstractClass();
48  $this->userContextMock->method('getUserId')
49  ->willReturn(1);
50 
51  $this->quoteMock = $this->getMockBuilder(Quote::class)
52  ->disableOriginalConstructor()
53  ->setMethods(['getCustomerId'])
54  ->getMock();
55 
56  $this->quoteRepositoryMock = $this->getMockBuilder(QuoteRepository::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59 
60  $this->changeQuoteControlMock = $this->getMockBuilder(ChangeQuoteControl::class)
61  ->disableOriginalConstructor()
62  ->getMock();
63 
64  $objectManagerHelper = new ObjectManager($this);
65  $this->accessChangeQuoteControl = $objectManagerHelper->getObject(
66  AccessChangeQuoteControl::class,
67  ['changeQuoteControl' => $this->changeQuoteControlMock]
68  );
69  }
70 
74  public function testBeforeSaveForCustomer()
75  {
76  $this->quoteMock->method('getCustomerId')
77  ->willReturn(1);
78 
79  $this->userContextMock->method('getUserType')
81 
82  $this->changeQuoteControlMock->method('isAllowed')
83  ->willReturn(true);
84 
85  $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
86 
87  $this->assertNull($result);
88  }
89 
96  public function testBeforeSaveException()
97  {
98  $this->quoteMock->method('getCustomerId')
99  ->willReturn(2);
100 
101  $this->userContextMock->method('getUserType')
103 
104  $this->changeQuoteControlMock->method('isAllowed')
105  ->willReturn(false);
106 
107  $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
108  }
109 
113  public function testBeforeSaveForAdmin()
114  {
115  $this->quoteMock->method('getCustomerId')
116  ->willReturn(2);
117 
118  $this->userContextMock->method('getUserType')
120 
121  $this->changeQuoteControlMock->method('isAllowed')
122  ->willReturn(true);
123 
124  $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
125 
126  $this->assertNull($result);
127  }
128 
132  public function testBeforeSaveForGuest()
133  {
134  $this->quoteMock->method('getCustomerId')
135  ->willReturn(null);
136 
137  $this->userContextMock->method('getUserType')
139 
140  $this->changeQuoteControlMock->method('isAllowed')
141  ->willReturn(true);
142 
143  $result = $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
144 
145  $this->assertNull($result);
146  }
147 
155  {
156  $this->quoteMock->method('getCustomerId')
157  ->willReturn(1);
158 
159  $this->userContextMock->method('getUserType')
161 
162  $this->changeQuoteControlMock->method('isAllowed')
163  ->willReturn(false);
164 
165  $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
166  }
167 
175  {
176  $this->quoteMock->method('getCustomerId')
177  ->willReturn(2);
178 
179  $this->userContextMock->method('getUserType')
180  ->willReturn(10);
181 
182  $this->changeQuoteControlMock->method('isAllowed')
183  ->willReturn(false);
184 
185  $this->accessChangeQuoteControl->beforeSave($this->quoteRepositoryMock, $this->quoteMock);
186  }
187 }