Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OrderStatusTest.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class OrderStatusTest extends \PHPUnit\Framework\TestCase
16 {
20  protected $model;
21 
26 
30  protected $objectManager;
31 
35  protected $urlInterface;
36 
40  protected $requestInterface;
41 
46 
50  protected $timezoneInterface;
51 
55  protected $orderFactory;
56 
61 
65  protected $order;
66 
70  protected $feedData = [
71  'title' => 'Order # 100000001 Notification(s)',
72  'link' => 'http://magento.com/sales/order/view/order_id/1',
73  'description' => 'Order # 100000001 Notification(s)',
74  'charset' => 'UTF-8',
75  'entries' => [
76  [
77  'title' => 'Details for Order #100000001',
78  'link' => 'http://magento.com/sales/order/view/order_id/1',
79  'description' => '<p>Notified Date: <br/>Comment: Some comment<br/></p>',
80  ],
81  [
82  'title' => 'Order #100000001 created at ',
83  'link' => 'http://magento.com/sales/order/view/order_id/1',
84  'description' => '<p>Current Status: Pending<br/>Total: 15.00<br/></p>'
85  ],
86  ],
87  ];
88 
89  protected function setUp()
90  {
91  $this->objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
92  $this->urlInterface = $this->createMock(\Magento\Framework\UrlInterface::class);
93  $this->requestInterface = $this->createMock(\Magento\Framework\App\RequestInterface::class);
94  $this->orderStatusFactory =
95  $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\Rss\OrderStatusFactory::class)
96  ->setMethods(['create'])
97  ->disableOriginalConstructor()
98  ->getMock();
99  $this->timezoneInterface = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
100  $this->orderFactory = $this->createPartialMock(\Magento\Sales\Model\OrderFactory::class, ['create']);
101  $this->scopeConfigInterface = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
102 
103  $this->order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
104  ->setMethods([
105  '__sleep',
106  '__wakeup',
107  'getIncrementId',
108  'getId',
109  'getCustomerId',
110  'load',
111  'getStatusLabel',
112  'formatPrice',
113  'getGrandTotal',
114  ])->disableOriginalConstructor()->getMock();
115  $this->order->expects($this->any())->method('getId')->will($this->returnValue(1));
116  $this->order->expects($this->any())->method('getIncrementId')->will($this->returnValue('100000001'));
117  $this->order->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
118  $this->order->expects($this->any())->method('getStatusLabel')->will($this->returnValue('Pending'));
119  $this->order->expects($this->any())->method('formatPrice')->will($this->returnValue('15.00'));
120  $this->order->expects($this->any())->method('getGrandTotal')->will($this->returnValue(15));
121  $this->order->expects($this->any())->method('load')->with(1)->will($this->returnSelf());
122 
123  $this->objectManagerHelper = new ObjectManagerHelper($this);
124  $this->model = $this->objectManagerHelper->getObject(
125  \Magento\Sales\Model\Rss\OrderStatus::class,
126  [
127  'objectManager' => $this->objectManager,
128  'urlBuilder' => $this->urlInterface,
129  'request' => $this->requestInterface,
130  'orderResourceFactory' => $this->orderStatusFactory,
131  'localeDate' => $this->timezoneInterface,
132  'orderFactory' => $this->orderFactory,
133  'scopeConfig' => $this->scopeConfigInterface
134  ]
135  );
136  }
137 
138  public function testGetRssData()
139  {
140  $this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
141  $requestData = base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}');
142 
143  $this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);
144 
145  $resource = $this->getMockBuilder(\Magento\Sales\Model\ResourceModel\Order\Rss\OrderStatus::class)
146  ->setMethods(['getAllCommentCollection'])
147  ->disableOriginalConstructor()
148  ->getMock();
149  $comment = [
150  'entity_type_code' => 'order',
151  'increment_id' => '100000001',
152  'created_at' => '2014-10-09 18:25:50',
153  'comment' => 'Some comment',
154  ];
155  $resource->expects($this->once())->method('getAllCommentCollection')->willReturn([$comment]);
156  $this->orderStatusFactory->expects($this->once())->method('create')->willReturn($resource);
157  $this->urlInterface->expects($this->any())->method('getUrl')
158  ->with('sales/order/view', ['order_id' => 1])
159  ->will($this->returnValue('http://magento.com/sales/order/view/order_id/1'));
160 
161  $this->assertEquals($this->feedData, $this->model->getRssData());
162  }
163 
168  public function testGetRssDataWithError()
169  {
170  $this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
171 
172  $requestData = base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}');
173 
174  $this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);
175 
176  $this->orderStatusFactory->expects($this->never())->method('create');
177 
178  $this->urlInterface->expects($this->never())->method('getUrl');
179 
180  $this->assertEquals($this->feedData, $this->model->getRssData());
181  }
182 
183  public function testIsAllowed()
184  {
185  $this->scopeConfigInterface->expects($this->once())->method('getValue')
186  ->with('rss/order/status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
187  ->will($this->returnValue(true));
188  $this->assertTrue($this->model->isAllowed());
189  }
190 
197  {
198  $this->requestInterface->expects($this->any())->method('getParam')
199  ->with('data')
200  ->will($this->returnValue($requestData));
201  $this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
202  $this->assertEquals('rss_order_status_data_' . $result, $this->model->getCacheKey());
203  }
204 
208  public function getCacheKeyDataProvider()
209  {
210  return [
211  [base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}'), md5('11000000011')],
212  [base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}'), '']
213  ];
214  }
215 
216  public function testGetCacheLifetime()
217  {
218  $this->assertEquals(600, $this->model->getCacheLifetime());
219  }
220 }
$resource
Definition: bulk.php:12