GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

OrderControllerTest::testRomCancelAction()   B
last analyzed

Complexity

Conditions 9
Paths 1

Size

Total Lines 55
Code Lines 37

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 55
rs 7.2446
cc 9
eloc 37
nc 1
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
require_once 'EbayEnterprise/Order/controllers/OrderController.php';
17
18
class EbayEnterprise_Order_Test_Controller_OrderControllerTest extends EbayEnterprise_Eb2cCore_Test_Base
19
{
20
    const API_CLASS = '\eBayEnterprise\RetailOrderManagement\Api\HttpApi';
21
22
    // @var Mock_EbayEnterprise_Order_GuestController
23
    protected $_controller;
24
    // @var Mock_Mage_Customer_Model_Session
25
    protected $_session;
26
    // @var Mock_Mage_Core_Controller_Request_Http
27
    protected $_request;
28
    /** @var Mock_Zend_Controller_Response_Abstract */
29
    protected $_response;
30
    /** @var Mock_HttpApi */
31
    protected $_api;
32
33
    /**
34
     * mock the request, customer session, and controller instance to test with.
35
     */
36
    public function setUp()
37
    {
38
        $this->_session = $this->getModelMockBuilder('customer/session')
39
            ->disableOriginalConstructor()
40
            ->setMethods(['isLoggedIn'])
41
            ->getMock();
42
43
        $this->_request = $this->getMockBuilder('Mage_Core_Controller_Request_Http')
44
            ->disableOriginalConstructor()
45
            ->setMethods(['getParam'])
46
            ->getMock();
47
48
        $this->_controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
49
            ->disableOriginalConstructor()
50
            ->setMethods(['_loadValidOrder', '_canViewOrder', 'loadLayout', 'renderLayout', 'getRequest', '_redirect', '_getRomReturnPath'])
51
            ->getMock();
52
        $this->_controller->expects($this->any())
53
            ->method('getRequest')
54
            ->will($this->returnValue($this->_request));
55
56
        /** @var Mock_Zend_Controller_Response_Abstract */
57
        $this->_response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...ler_Response_Abstract') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Mock_Zend_Controller_Response_Abstract> of property $_response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
59
        $this->_api = $this->getMockBuilder(static::API_CLASS)
60
            // Disabling the constructor because it requires the IHttpConfig parameter to be passed in.
61
            ->disableOriginalConstructor()
62
            ->getMock();
63
    }
64
    /**
65
     * verify the order and shipment are setup correctly.
66
     * verify the request is handled properly.
67
     */
68 View Code Duplication
    public function testPrintOrderShipmentAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $this->_request->expects($this->any())
71
            ->method('getParam')
72
            ->will($this->returnValue('theid'));
73
        $this->_controller->expects($this->any())
74
            ->method('_loadValidOrder')
75
            ->will($this->returnValue(true));
76
        $this->_controller->expects($this->any())
77
            ->method('_canViewOrder')
78
            ->will($this->returnValue(true));
79
        $this->_controller->expects($this->once())
80
            ->method('loadLayout')
81
            ->with($this->isType('string'))
82
            ->will($this->returnValue($this->getModelMock('core/layout')));
83
        // if all went well, a call to renderLayout should
84
        // be observed.
85
        $this->_controller->expects($this->once())
86
            ->method('renderLayout')
87
            ->will($this->returnSelf());
88
        $this->_controller->printOrderShipmentAction();
89
    }
90
    /**
91
     * provide datasets so the printOrderShipmentAction method does not attempt
92
     * to render any content.
93
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
94
     */
95
    public function providePrintOrderFailData()
96
    {
97
        return [
98
            [false, true, 2, true],
99
            [true, false, '2', false],
100
            [true, true, null, true],
101
        ];
102
    }
103
    /**
104
     * if any of the following is false redirect to either to the order history page or the guest form.
105
     *  - _loadValidOrder
106
     *  - _canViewOrder
107
     *  - no shipment id is given
108
     * @param bool  $loaded   whether the order was loaded or not
109
     * @param bool  $viewable whether the order should be viewable
110
     * @param mixed $shipId   shipment id
111
     * @dataProvider providePrintOrderFailData
112
     */
113
    public function testPrintOrderShipmentActionFailure($loaded, $viewable, $shipId, $isLoggedIn)
114
    {
115
        $this->_session->expects($loaded && !is_null($shipId) ? $this->never() : $this->once())
116
            ->method('isLoggedIn')
117
            ->will($this->returnValue($isLoggedIn));
118
119
        /** @var EbayEnterprise_Order_Helper_Factory */
120
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getCustomerSession']);
121
        $factory->expects($loaded && !is_null($shipId) ? $this->never() : $this->once())
122
            ->method('getCustomerSession')
123
            ->will($this->returnValue($this->_session));
124
125
        $this->_request->expects($this->any())
126
            ->method('getParam')
127
            ->will($this->returnValue($shipId));
128
        $this->_controller->expects($this->any())
129
            ->method('_loadValidOrder')
130
            ->will($this->returnValue($loaded));
131
        $this->_controller->expects($this->any())
132
            ->method('_canViewOrder')
133
            ->will($this->returnValue($viewable));
134
        $this->_controller->expects($loaded && !is_null($shipId) ? $this->never() : $this->once())
135
            ->method('_redirect')
136
            ->with($this->isType('string'));
137
138
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($this->_controller, [
139
            '_orderFactory' => $factory,
140
        ]);
141
        $this->_controller->printOrderShipmentAction();
142
    }
143
144
    /**
145
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
146
     */
147
    public function providerLoadValidOrder()
148
    {
149
        return [
150
            [false, null, true],
151
            [true, Mage::exception('EbayEnterprise_Order_Exception_Order_Detail_Notfound'), false],
152
        ];
153
    }
154
155
    /**
156
     * Test that the controller method EbayEnterprise_Order_OrderController::_loadValidOrder()
157
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::getRequest()
158
     * which will return an instance of an object that extends Zend_Controller_Request_Abstract class.
159
     * Then, the method Zend_Controller_Request_Abstract::getParam() will be invoked, passed in
160
     * the string literal 'order_id' as its parameter and then it will return the order id.
161
     * Then, the method ebayenterprise_order/factory::getNewRomOrderDetailModel() will be invoked and
162
     * return an object of type ebayenterprise_order/detail. Then, the method ebayenterprise_order/detail::requestOrderDetail() will be
163
     * called passing in the return value from calling the method Zend_Controller_Request_Abstract::getParam().
164
     * If no exception is thrown the method EbayEnterprise_Order_OrderController::_handleOrderDetailException().
165
     * Finally, the method EbayEnterprise_Order_OrderController::_loadValidOrder() will return null.
166
     *
167
     * @param bool
168
     * @param EbayEnterprise_Order_Exception_Order_Detail_Notfound_Exception | null
169
     * @param bool
170
     * @dataProvider providerLoadValidOrder
171
     */
172
    public function testLoadValidOrder($isException, $exception, $result)
173
    {
174
        /** @var string */
175
        $param = 'order_id';
176
        /** @var string */
177
        $orderId = '10000093888341';
178
179
        /** @var Mock_Zend_Controller_Request_Abstract */
180
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract', [], '', true, true, true, ['getParam']);
181
        $request->expects($this->once())
182
            ->method('getParam')
183
            ->with($this->identicalTo($param))
184
            ->will($this->returnValue($orderId));
185
186
        /** @var EbayEnterprise_Order_Model_Detail_Process_Response */
187
        $response = $this->getModelMockBuilder('ebayenterprise_order/detail_process_response')
188
            ->disableOriginalConstructor()
189
            ->getMock();
190
191
        /** @var Mock_EbayEnterprise_Order_Model_Detail */
192
        $orderDetail = $this->getModelMockBuilder('ebayenterprise_order/detail')
193
            ->disableOriginalConstructor()
194
            ->getMock();
195
        $orderDetail->expects($this->once())
196
            ->method('process')
197
            ->will($isException ? $this->throwException($exception) : $this->returnValue($response));
198
199
        /** @var EbayEnterprise_Order_Helper_Factory */
200
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getNewRomOrderDetailModel']);
201
        $factory->expects($this->once())
202
            ->method('getNewRomOrderDetailModel')
203
            ->will($this->returnValue($orderDetail));
204
205
        /** @var Mock_EbayEnterprise_Order_OrderController */
206
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
207
            ->setMethods(['getRequest', '_handleOrderDetailException'])
208
            ->setConstructorArgs([$request, $this->_response])
209
            ->getMock();
210
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($controller, [
211
            '_orderFactory' => $factory,
212
        ]);
213
        $controller->expects($this->once())
214
            ->method('getRequest')
215
            ->will($this->returnValue($request));
216
        $controller->expects($isException ? $this->once() : $this->never())
217
            // Proving that this method will never be called if the method ebayenterprise_order/detail::requestOrderDetail()
218
            // don't throw an exception of type bayEnterprise_Order_Exception_Order_Detail_Notfound.
219
            // However, when exception of type bayEnterprise_Order_Exception_Order_Detail_Notfound is thrown
220
            // the this method expected to be invoked once.
221
            ->method('_handleOrderDetailException')
222
            ->with($this->identicalTo($exception))
223
            ->will($this->returnSelf());
224
225
        $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_loadValidOrder', []));
226
    }
227
228
    /**
229
     * Test that the controller method EbayEnterprise_Order_OrderController::_handleOrderDetailException()
230
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_getCustomerSession(),
231
     * which will return an instance of type customer/session. Then, the method customer/session::addError()
232
     * will be called and passed as its parameter the value from calling the method
233
     * EbayEnterprise_Order_Exception_Order_Detail_Notfound_Exception::getMessage() from the passed in exception object.
234
     * Then, the method EbayEnterprise_Order_OrderController::_redirect() is invoked, and passed in the return
235
     * value from calling the method EbayEnterprise_Order_OrderController::_getRomReturnPath().
236
     * Finally, the controller method EbayEnterprise_Order_OrderController::_handleOrderDetailException() will
237
     * return itself.
238
     */
239
    public function testHandleOrderDetailException()
240
    {
241
        /** @var string */
242
        $path = EbayEnterprise_Order_OrderController::LOGGED_IN_ORDER_HISTORY_PATH;
243
        /** @var string */
244
        $message = 'Exception test message';
245
        /** @var EbayEnterprise_Order_Exception_Order_Detail_Notfound_Exception */
246
        $exception = Mage::exception('EbayEnterprise_Order_Exception_Order_Detail_Notfound', $message);
247
        /** @var Mock_Zend_Controller_Request_Abstract */
248
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
249
        /** @var Mock_Zend_Controller_Response_Abstract */
250
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
251
        /** @var Mock_Mage_Core_Model_Session */
252
        $coreSession = $this->getModelMockBuilder('core/session')
253
            // Disabling the constructor in order to prevent session_start() function from being
254
            // called which causes headers already sent exception from being thrown.
255
            ->disableOriginalConstructor()
256
            ->setMethods(['addError'])
257
            ->getMock();
258
        $coreSession->expects($this->once())
259
            ->method('addError')
260
            ->with($this->identicalTo($message))
261
            ->will($this->returnSelf());
262
263
        /** @var Mock_Mage_Customer_Model_Session */
264
        $customerSession = $this->getModelMockBuilder('customer/session')
265
            // Disabling the constructor in order to prevent session_start() function from being
266
            // called which causes headers already sent exception from being thrown.
267
            ->disableOriginalConstructor()
268
            ->getMock();
269
        /** @var EbayEnterprise_Order_Helper_Factory */
270
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getCustomerSession', 'getCoreSessionModel']);
271
        $factory->expects($this->once())
272
            ->method('getCustomerSession')
273
            ->will($this->returnValue($customerSession));
274
        $factory->expects($this->once())
275
            ->method('getCoreSessionModel')
276
            ->will($this->returnValue($coreSession));
277
278
        /** @var Mock_EbayEnterprise_Order_OrderController */
279
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
280
            ->setMethods(['_getRomReturnPath', '_redirect'])
281
            ->setConstructorArgs([$request, $response])
282
            ->getMock();
283
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($controller, [
284
            '_orderFactory' => $factory,
285
        ]);
286
        $controller->expects($this->once())
287
            ->method('_getRomReturnPath')
288
            ->with($this->identicalTo($customerSession))
289
            ->will($this->returnValue($path));
290
        $controller->expects($this->once())
291
            ->method('_redirect')
292
            ->with($this->identicalTo($path))
293
            ->will($this->returnSelf());
294
295
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_handleOrderDetailException', [$exception]));
296
    }
297
298
    /**
299
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
300
     */
301
    public function providerGetOrderDetailReturnPath()
302
    {
303
        return [
304
            [true, EbayEnterprise_Order_OrderController::LOGGED_IN_ORDER_HISTORY_PATH],
305
            [false, EbayEnterprise_Order_OrderController::GUEST_ORDER_FORM_PATH],
306
        ];
307
    }
308
309
    /**
310
     * Test that the controller method EbayEnterprise_Order_OrderController::_getRomReturnPath()
311
     * is invoked and it will call the method customer/session::isLoggedIn() and if it returns the boolean value
312
     * true then the controller method EbayEnterprise_Order_OrderController::_getRomReturnPath() will
313
     * return the class constant EbayEnterprise_Order_OrderController::LOGGED_IN_ORDER_HISTORY_PATH.
314
     * Otherwise, it will return class constant value EbayEnterprise_Order_OrderController::GUEST_ORDER_FORM_PATH.
315
     *
316
     * @param bool
317
     * @param string
318
     * @dataProvider providerGetOrderDetailReturnPath
319
     */
320
    public function testGetOrderDetailReturnPath($isLoggedIn, $path)
321
    {
322
        /** @var Mock_Mage_Customer_Model_Session */
323
        $session = $this->getModelMockBuilder('customer/session')
324
            // Disabling the constructor in order to prevent session_start() function from being
325
            // called which causes headers already sent exception from being thrown.
326
            ->disableOriginalConstructor()
327
            ->setMethods(['isLoggedIn'])
328
            ->getMock();
329
        $session->expects($this->once())
330
            ->method('isLoggedIn')
331
            ->will($this->returnValue($isLoggedIn));
332
333
        /** @var Mock_Zend_Controller_Request_Abstract */
334
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
335
        /** @var Mock_Zend_Controller_Response_Abstract */
336
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
337
338
        /** @var Mock_EbayEnterprise_Order_OrderController */
339
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
340
            ->setConstructorArgs([$request, $response])
341
            ->getMock();
342
343
        $this->assertSame($path, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_getRomReturnPath', [$session]));
344
    }
345
346
    /**
347
     * Test that the controller method EbayEnterprise_Order_OrderController::romViewAction()
348
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_viewAction().
349
     * Then, the method EbayEnterprise_Order_OrderController::loadLayout() will be invoked. Then,
350
     * the method EbayEnterprise_Order_OrderController::_initLayoutMessages() will be called and passed
351
     * in as parameter the string literal 'catalog/session'. Then, the method EbayEnterprise_Order_OrderController::getLayout()
352
     * will be called and return an instance of the class Mage_Core_Model_Layout. Then,
353
     * the method Mage_Core_Model_Layout::getBlock() will be called and passed in as parameter the string
354
     * literal 'customer_account_navigation' and it will return an instance object that extend the abstract class
355
     * Mage_Core_Block_Abstract. Then, the method Mage_Core_Block_Abstract::setActive() will be called. Then, the method
356
     * EbayEnterprise_Order_OrderController::renderLayout() will be called. Finally, the method
357
     * EbayEnterprise_Order_OrderController::romViewAction() will return null.
358
     */
359 View Code Duplication
    public function testRomViewAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360
    {
361
        /** @var Mock_Zend_Controller_Request_Abstract */
362
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
363
        /** @var Mock_Zend_Controller_Response_Abstract */
364
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
365
366
        /** @var Mock_EbayEnterprise_Order_OrderController */
367
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
368
            ->setMethods(['_viewAction'])
369
            ->setConstructorArgs([$request, $response])
370
            ->getMock();
371
        $controller->expects($this->once())
372
            ->method('_viewAction')
373
            ->will($this->returnValue(null));
374
375
        $this->assertNull($controller->romViewAction());
376
    }
377
378
    /**
379
     * Test that the controller method EbayEnterprise_Order_OrderController::romGuestViewAction()
380
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_viewAction().
381
     * Then, the method EbayEnterprise_Order_OrderController::loadLayout() will be invoked. Then,
382
     * the method EbayEnterprise_Order_OrderController::_initLayoutMessages() will be called and passed
383
     * in as parameter the string literal 'catalog/session'. Then, the method
384
     * EbayEnterprise_Order_OrderController::renderLayout() will be called. Finally, the method
385
     * EbayEnterprise_Order_OrderController::romGuestViewAction() will return null.
386
     */
387 View Code Duplication
    public function testRomGuestViewAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
388
    {
389
        /** @var Mock_Zend_Controller_Request_Abstract */
390
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
391
        /** @var Mock_Zend_Controller_Response_Abstract */
392
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
393
394
        /** @var Mock_EbayEnterprise_Order_OrderController */
395
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
396
            ->setMethods(['_viewAction'])
397
            ->setConstructorArgs([$request, $response])
398
            ->getMock();
399
        $controller->expects($this->once())
400
            ->method('_viewAction')
401
            ->will($this->returnValue(null));
402
403
        $this->assertNull($controller->romGuestViewAction());
404
    }
405
406
    /**
407
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
408
     */
409 View Code Duplication
    public function providerRomCancelAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
410
    {
411
        return [
412
            [true, true, true],
413
            [false, true, true],
414
            [false, false, true],
415
            [false, false, false],
416
        ];
417
    }
418
419
    /**
420
     * Test that the controller method EbayEnterprise_Order_OrderController::romCancelAction()
421
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm()
422
     * and if it returns the boolean value true then these controller methods
423
     * EbayEnterprise_Order_OrderController::_setRefererUrlInSession() and
424
     * EbayEnterprise_Order_OrderController::_showOrderCancelPage() will be called. However,
425
     * the method EbayEnterprise_Order_OrderController::_processOrderCancelAction() will never be called.
426
     * Otherwise, if the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm() return the boolean
427
     * value false, then these controller methods EbayEnterprise_Order_OrderController::_setRefererUrlInSession() and
428
     * EbayEnterprise_Order_OrderController::_showOrderCancelPage() will never be called. However, the method
429
     * EbayEnterprise_Order_OrderController::_processOrderCancelAction() will be called once.
430
     * Finally, the method EbayEnterprise_Order_OrderController::romCancelAction() will return null.
431
     *
432
     * @param bool
433
     * @param bool
434
     * @param bool
435
     * @dataProvider providerRomCancelAction
436
     */
437
    public function testRomCancelAction($canShow, $isValidOperation, $isLoggedIn)
438
    {
439
        $this->_session->expects($isValidOperation ? $this->never() : $this->once())
440
            ->method('isLoggedIn')
441
            ->will($this->returnValue($isLoggedIn));
442
443
        /** @var EbayEnterprise_Order_Helper_Factory */
444
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getCustomerSession']);
445
        $factory->expects($isValidOperation ? $this->never() : $this->once())
446
            ->method('getCustomerSession')
447
            ->will($this->returnValue($this->_session));
448
449
        /** @var Mock_Zend_Controller_Request_Abstract */
450
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
451
        /** @var Mock_Zend_Controller_Response_Abstract */
452
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
453
454
        /** @var Mock_EbayEnterprise_Order_OrderController */
455
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
456
            ->setMethods(['_canShowOrderCancelForm', '_setRefererUrlInSession', '_showOrderCancelPage', '_processOrderCancelAction', '_isValidOperation', '_redirect'])
457
            ->setConstructorArgs([$request, $response])
458
            ->getMock();
459
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($controller, [
460
            '_orderFactory' => $factory,
461
        ]);
462
        $controller->expects($isValidOperation ? $this->once() : $this->never())
463
            ->method('_canShowOrderCancelForm')
464
            ->will($this->returnValue($canShow));
465
        $controller->expects($canShow ? $this->once() : $this->never())
466
            // when the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm() return true
467
            // this method will be invoked once, otherwise it will never be called.
468
            ->method('_setRefererUrlInSession')
469
            ->will($this->returnSelf());
470
        $controller->expects($canShow ? $this->once() : $this->never())
471
            // when the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm() return true
472
            // this method will be invoked once, otherwise it will never be called.
473
            ->method('_showOrderCancelPage')
474
            ->will($this->returnSelf());
475
        $controller->expects($isValidOperation && !$canShow ? $this->once() : $this->never())
476
            // when the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm() return true
477
            // this method will never be invoked, otherwise it will be called once.
478
            ->method('_processOrderCancelAction')
479
            ->will($this->returnSelf());
480
        $controller->expects($this->once())
481
            ->method('_isValidOperation')
482
            ->will($this->returnValue($isValidOperation));
483
        $controller->expects($isValidOperation ? $this->never() : $this->once())
484
            ->method('_redirect')
485
            ->will($this->returnValueMap([
486
                ['*/*/history', [], $controller],
487
                ['sales/guest/form', [], $controller],
488
            ]));
489
490
        $this->assertNull($controller->romCancelAction());
491
    }
492
493
    /**
494
     * Test that the controller method EbayEnterprise_Order_OrderController::romGuestCancelAction()
495
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::romCancelAction().
496
     * Finally, the method EbayEnterprise_Order_OrderController::romGuestCancelAction() will return null.
497
     */
498 View Code Duplication
    public function testromGuestCancelAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
499
    {
500
        /** @var Mock_Zend_Controller_Request_Abstract */
501
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
502
        /** @var Mock_Zend_Controller_Response_Abstract */
503
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
504
505
        /** @var Mock_EbayEnterprise_Order_OrderController */
506
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
507
            ->setMethods(['romCancelAction'])
508
            ->setConstructorArgs([$request, $response])
509
            ->getMock();
510
        $controller->expects($this->once())
511
            ->method('romCancelAction')
512
            ->will($this->returnValue(null));
513
514
        $this->assertNull($controller->romGuestCancelAction());
515
    }
516
517
    /**
518
     * Test that the controller method EbayEnterprise_Order_OrderController::_setRefererUrlInSession()
519
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_getRomCancelSession(),
520
     * which will return an instance of type core/session. Then, the method core/session::setCancelActionRefererUrl()
521
     * will be called and passed as its parameter the return value from calling the method
522
     * EbayEnterprise_Order_OrderController::_getRefererUrl(). finally, the controller method
523
     * EbayEnterprise_Order_OrderController::_setRefererUrlInSession() will return itself.
524
     */
525
    public function testSetRefererUrlInSession()
526
    {
527
        /** @var string */
528
        $path = EbayEnterprise_Order_OrderController::LOGGED_IN_ORDER_HISTORY_PATH;
529
        /** @var Mock_Zend_Controller_Request_Abstract */
530
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
531
        /** @var Mock_Zend_Controller_Response_Abstract */
532
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
533
534
        /** @var Mock_Mage_Core_Model_Session */
535
        $session = $this->getModelMockBuilder('core/session')
536
            // Disabling the constructor in order to prevent session_start() function from being
537
            // called which causes headers already sent exception from being thrown.
538
            ->disableOriginalConstructor()
539
            ->setMethods(['setCancelActionRefererUrl'])
540
            ->getMock();
541
        $session->expects($this->once())
542
            ->method('setCancelActionRefererUrl')
543
            ->will($this->returnSelf());
544
545
        /** @var Mock_EbayEnterprise_Order_OrderController */
546
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
547
            ->setMethods(['_getRomCancelSession', '_getRefererUrl'])
548
            ->setConstructorArgs([$request, $response])
549
            ->getMock();
550
        $controller->expects($this->once())
551
            ->method('_getRomCancelSession')
552
            ->will($this->returnValue($session));
553
        $controller->expects($this->once())
554
            ->method('_getRefererUrl')
555
            ->will($this->returnValue($path));
556
557
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_setRefererUrlInSession', []));
558
    }
559
560
    /**
561
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
562
     */
563
    public function providerProcessOrderCancelAction()
564
    {
565
        return [
566
            [false, false, null],
567
            [true, true, Mage::exception('Mage_Core')],
568
        ];
569
    }
570
571
    /**
572
     * Test that the controller method EbayEnterprise_Order_OrderController::_processOrderCancelAction()
573
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_getRomOrderToBeCanceled(),
574
     * which will return an instance of type sales/order. Then, the method
575
     * EbayEnterprise_Order_OrderController::_getRomOrderCancelModel() will be called and passed as its parameter the
576
     * sales/order object, which in term will return an instance of type ebayenterprise_order/cancel.
577
     * Then, the method EbayEnterprise_Order_OrderController::_getRomCancelSession() will be invoked
578
     * and return an instance of type core/session. Then, the method core/session::getCancelActionRefererUrl()
579
     * will be called and if it return a non-empty string value then, the method EbayEnterprise_Order_OrderController::_getRefererUrl().
580
     * However, if the return value from core/session::getCancelActionRefererUrl() is null, then the method
581
     * EbayEnterprise_Order_OrderController::_getRefererUrl() will be invoked once. Then, the method
582
     * ebayenterprise_order/cancel::process() will be invoked and if it doesn't throw an exception the method
583
     * EbayEnterprise_Order_OrderController::_handleRomCancelResponse() invoked once passed in as first parameter
584
     * a sales/order object, as second parameter core/session object and as turn parameter a string literal representing
585
     * the redirect URL. However, if the method ebayenterprise_order/cancel::process() throw an exception, then the method
586
     * EbayEnterprise_Order_OrderController::_handleRomCancelResponse() will never be invoked, but instead the method
587
     * EbayEnterprise_Order_OrderController::_handleRomCancelException() will be invoked and passed in as first parameter
588
     * and object of type Exception, as second parameter an object of type core/session, and as third parameter string literal
589
     * representing the redirect URL. Finally, the method EbayEnterprise_Order_OrderController::_processOrderCancelAction()
590
     * will return itself.
591
     *
592
     * @param bool
593
     * @param bool
594
     * @param Exception | null
595
     * @dataProvider providerProcessOrderCancelAction
596
     */
597
    public function testProcessOrderCancelAction($isException, $isRedirectSession, $exception)
598
    {
599
        /** @var string */
600
        $redirect = 'http://test.example.com/sales/order/romview/order_id/10008832231/';
601
        /** @var Mage_Sales_Model_Order */
602
        $order = Mage::getModel('sales/order');
603
604
        /** @var EbayEnterprise_Eb2cCore_Helper_Data */
605
        $coreHelper = $this->getHelperMock('eb2ccore/data', ['getSdkApi']);
606
        $coreHelper->expects($this->any())
607
            ->method('getSdkApi')
608
            ->will($this->returnValue($this->_api));
609
610
        /** @var Mock_EbayEnterprise_Order_Model_Cancel */
611
        $cancel = $this->getModelMock('ebayenterprise_order/cancel', ['process'], false, [[
612
            // This key is required
613
            'order' => $order,
614
            // This key is optional
615
            'core_helper' => $coreHelper,
616
        ]]);
617
        $cancel->expects($this->once())
618
            ->method('process')
619
            ->will($isException ? $this->throwException($exception) : $this->returnSelf());
620
621
        /** @var Mock_Zend_Controller_Request_Abstract */
622
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
623
        /** @var Mock_Zend_Controller_Response_Abstract */
624
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
625
626
        /** @var Mock_Mage_Core_Model_Session */
627
        $session = $this->getModelMockBuilder('core/session')
628
            // Disabling the constructor in order to prevent session_start() function from being
629
            // called which causes headers already sent exception from being thrown.
630
            ->disableOriginalConstructor()
631
            ->setMethods(['getCancelActionRefererUrl'])
632
            ->getMock();
633
        $session->expects($this->once())
634
            ->method('getCancelActionRefererUrl')
635
            ->will($this->returnValue($isRedirectSession ? $redirect : null));
636
637
        /** @var Mock_EbayEnterprise_Order_OrderController */
638
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
639
            ->setMethods(['_getRomOrderToBeCanceled', '_getRomOrderCancelModel', '_getRomCancelSession', '_getRefererUrl', '_handleRomCancelException', '_handleRomCancelResponse'])
640
            ->setConstructorArgs([$request, $response])
641
            ->getMock();
642
        $controller->expects($this->once())
643
            ->method('_getRomOrderToBeCanceled')
644
            ->will($this->returnValue($order));
645
        $controller->expects($this->once())
646
            ->method('_getRomOrderCancelModel')
647
            ->with($this->identicalTo($order))
648
            ->will($this->returnValue($cancel));
649
        $controller->expects($this->once())
650
            ->method('_getRomCancelSession')
651
            ->will($this->returnValue($session));
652
        $controller->expects($isRedirectSession? $this->never() : $this->once())
653
            // Proving that this method will never be called when the varien magic method
654
            // core/session::getCancelActionRefererUrl() returns a non-empty string.
655
            // When the method core/session::getCancelActionRefererUrl() return null
656
            // this method will be invoked once.
657
            ->method('_getRefererUrl')
658
            ->will($this->returnValue($redirect));
659
        $controller->expects($isException ? $this->once() : $this->never())
660
            // Proving that this method will never be invoked unless the method
661
            // ebayenterprise_order/cancel::process() thrown an exception, then it will be invoked once.
662
            ->method('_handleRomCancelException')
663
            ->with($this->identicalTo($exception), $this->identicalTo($session), $this->identicalTo($redirect))
664
            ->will($this->returnSelf());
665
        $controller->expects($isException ? $this->never() : $this->once())
666
            // Proving that this method will be invoked once unless the method
667
            // ebayenterprise_order/cancel::process() thrown an exception, then it will never be invoked.
668
            ->method('_handleRomCancelResponse')
669
            ->with($this->identicalTo($order), $this->identicalTo($session), $this->identicalTo($redirect))
670
            ->will($this->returnSelf());
671
672
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_processOrderCancelAction', []));
673
    }
674
675
    /**
676
     * Test that the controller method EbayEnterprise_Order_OrderController::_showOrderCancelPage()
677
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::_viewAction().
678
     * Then, the method EbayEnterprise_Order_OrderController::loadLayout() will be invoked. Then,
679
     * the method EbayEnterprise_Order_OrderController::_initLayoutMessages() will be called and passed
680
     * in as parameter the string literal 'catalog/session'. Then, the method
681
     * EbayEnterprise_Order_OrderController::renderLayout() will be called. Finally, the method
682
     * EbayEnterprise_Order_OrderController::_showOrderCancelPage() will return itself.
683
     */
684 View Code Duplication
    public function testShowOrderCancelPage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
685
    {
686
        /** @var Mock_Zend_Controller_Request_Abstract */
687
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
688
        /** @var Mock_Zend_Controller_Response_Abstract */
689
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
690
691
        /** @var Mock_EbayEnterprise_Order_OrderController */
692
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
693
            ->setMethods(['_viewAction'])
694
            ->setConstructorArgs([$request, $response])
695
            ->getMock();
696
        $controller->expects($this->once())
697
            ->method('_viewAction')
698
            ->will($this->returnValue(null));
699
700
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_showOrderCancelPage', []));
701
    }
702
703
    /**
704
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
705
     */
706 View Code Duplication
    public function providerCanShowOrderCancelForm()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
707
    {
708
        return [
709
            [true, true, false],
710
            [false, true, true],
711
        ];
712
    }
713
714
    /**
715
     * Test that the controller method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm()
716
     * is invoked and when the method ebayenterprise_order/data::hasOrderCancelReason() is called and return true
717
     * and the method EbayEnterprise_Order_OrderController::_isOrderCancelPostAction() and return false will
718
     * the method EbayEnterprise_Order_OrderController::_canShowOrderCancelForm() return true. Otherwise, it
719
     * will return false.
720
     *
721
     * @param bool
722
     * @param bool
723
     * @param string
724
     * @dataProvider providerCanShowOrderCancelForm
725
     */
726 View Code Duplication
    public function testCanShowOrderCancelForm($isPost, $hasReason, $result)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
727
    {
728
        /** @var EbayEnterprise_Order_Helper_Data */
729
        $orderHelper = $this->getHelperMock('ebayenterprise_order/data', ['hasOrderCancelReason']);
730
        $orderHelper->expects($this->once())
731
            ->method('hasOrderCancelReason')
732
            ->will($this->returnValue($hasReason));
733
734
        /** @var Mock_Zend_Controller_Request_Abstract */
735
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
736
        /** @var Mock_Zend_Controller_Response_Abstract */
737
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
738
739
        /** @var Mock_EbayEnterprise_Order_OrderController */
740
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
741
            ->setMethods(['_isOrderCancelPostAction'])
742
            ->setConstructorArgs([$request, $response])
743
            ->getMock();
744
        $controller->expects($this->once())
745
            ->method('_isOrderCancelPostAction')
746
            ->will($this->returnValue($isPost));
747
748
        // Replacing the protected class property EbayEnterprise_Order_OrderController::$_orderHelper with a mock.
749
        EcomDev_Utils_Reflection::setRestrictedPropertyValue($controller, '_orderHelper', $orderHelper);
750
751
        $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_canShowOrderCancelForm', []));
752
    }
753
754
    /**
755
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use boolean[][].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
756
     */
757 View Code Duplication
    public function providerIsOrderCancelPostAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
758
    {
759
        return [
760
            [true, true, true],
761
            [true, false, false],
762
            [false, true, false],
763
            [false, false, false],
764
        ];
765
    }
766
767
    /**
768
     * Test that the controller method EbayEnterprise_Order_OrderController::_isOrderCancelPostAction()
769
     * is invoked and the method EbayEnterprise_Order_OrderController::getRequest() will be called and return
770
     * an instance object that extend the class Zend_Controller_Request_Abstract. Then, the controller method
771
     * EbayEnterprise_Order_OrderController::_isOrderCancelPostAction() will only return true when both
772
     * Zend_Controller_Request_Abstract::isPost() and Zend_Controller_Request_Abstract::getPost() passing in a string
773
     * literal 'cancel_action' return boolean true. Otherwise, the EbayEnterprise_Order_OrderController::_isOrderCancelPostAction()
774
     * method will always return false. Also, when the method Zend_Controller_Request_Abstract::isPost() return false
775
     * the method Zend_Controller_Request_Abstract::getPost() will never be called.
776
     *
777
     * @param bool
778
     * @param bool
779
     * @param bool
780
     * @dataProvider providerIsOrderCancelPostAction
781
     */
782
    public function testIsOrderCancelPostAction($isPost, $cancelAction, $result)
783
    {
784
        /** @var string */
785
        $param = 'cancel_action';
786
787
        /** @var Mock_Zend_Controller_Request_Abstract */
788
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract', [], '', true, true, true, ['isPost', 'getPost']);
789
        $request->expects($this->once())
790
            ->method('isPost')
791
            ->will($this->returnValue($isPost));
792
        $request->expects($isPost? $this->once() : $this->never())
793
            // Proving that once the method Zend_Controller_Request_Abstract::isPost() return
794
            // false the method Zend_Controller_Request_Abstract::getPost() will never be invoked
795
            // since we are using logical AND operation for the condition.
796
            ->method('getPost')
797
            ->with($this->identicalTo($param))
798
            ->will($this->returnValue($cancelAction));
799
800
        /** @var Mock_Zend_Controller_Response_Abstract */
801
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
802
803
        /** @var Mock_EbayEnterprise_Order_OrderController */
804
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
805
            ->setMethods(['getRequest'])
806
            ->setConstructorArgs([$request, $response])
807
            ->getMock();
808
        $controller->expects($this->once())
809
            ->method('getRequest')
810
            ->will($this->returnValue($request));
811
812
        $this->assertSame($result, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_isOrderCancelPostAction', []));
813
    }
814
815
    /**
816
     * Test that the controller method EbayEnterprise_Order_OrderController::_getRomOrderToBeCanceled()
817
     * is invoked and the method EbayEnterprise_Order_OrderController::getRequest() will be called and return
818
     * an instance object that extend the class Zend_Controller_Request_Abstract. Then, an instance of type sales/order
819
     * will be instantiated. Then, the method Zend_Controller_Request_Abstract::getParam() will be called, passed in the string literal 'order_id'
820
     * and return the order id. This order id will be passed in sales/order::loadByIncrementId() method. Then, the method
821
     * Zend_Controller_Request_Abstract::getParam() will be called, passed in string the literal 'cancel_reason'
822
     * to the method sales/order::setCancelReasonCode(). Finally, the method EbayEnterprise_Order_OrderController::_getRomOrderToBeCanceled()
823
     * will return the sales/order object.
824
     */
825
    public function testGetRomOrderToBeCanceled()
826
    {
827
        /** @var null */
828
        $default = null;
829
        /** @var string */
830
        $orderId = '1000000083787831';
831
        /** @var string */
832
        $cancelReason = 'reason_code_001';
833
834
        /** @var Mock_Zend_Controller_Request_Abstract */
835
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract', [], '', true, true, true, ['getParam']);
836
        $request->expects($this->exactly(2))
837
            ->method('getParam')
838
            ->will($this->returnValueMap([
839
                ['order_id', $default, $orderId],
840
                ['cancel_reason', $default, $cancelReason],
841
            ]));
842
843
        /** @var Mock_Zend_Controller_Response_Abstract */
844
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
845
846
        /** @var Mock_Mage_Sales_Model_Order */
847
        $order = $this->getModelMock('sales/order', ['loadByIncrementId', 'setCancelReasonCode']);
848
        $order->expects($this->once())
849
            ->method('loadByIncrementId')
850
            ->with($this->identicalTo($orderId))
851
            ->will($this->returnSelf());
852
        $order->expects($this->once())
853
            ->method('setCancelReasonCode')
854
            ->with($this->identicalTo($cancelReason))
855
            ->will($this->returnSelf());
856
        $this->replaceByMock('model', 'sales/order', $order);
857
858
        /** @var Mock_EbayEnterprise_Order_OrderController */
859
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
860
            ->setMethods(['getRequest'])
861
            ->setConstructorArgs([$request, $response])
862
            ->getMock();
863
        $controller->expects($this->once())
864
            ->method('getRequest')
865
            ->will($this->returnValue($request));
866
867
        $this->assertSame($order, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_getRomOrderToBeCanceled', []));
868
    }
869
870
    /**
871
     * Test that the controller method EbayEnterprise_Order_OrderController::_getRomOrderCancelModel()
872
     * is invoked, it will be passed an instance of type sales/order and it will instantiate an instance of
873
     * type ebayenterprise_order/cancel, passed in the required array with key 'order' mapped to a sales/order
874
     * object to the constructor method and then return the ebayenterprise_order/cancel object.
875
     */
876
    public function testGetRomOrderCancelModel()
877
    {
878
        /** @var Mage_Sales_Model_Order */
879
        $order = Mage::getModel('sales/order');
880
        /** @var Mock_Zend_Controller_Request_Abstract */
881
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
882
        /** @var Mock_Zend_Controller_Response_Abstract */
883
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
884
885
        /** @var Mock_EbayEnterprise_Order_Model_Cancel */
886
        $cancel = $this->getModelMock('ebayenterprise_order/cancel', [], false, [[
887
            // This key is required
888
            'order' => $order,
889
        ]]);
890
        $this->replaceByMock('model', 'ebayenterprise_order/cancel', $cancel);
891
892
        /** @var Mock_EbayEnterprise_Order_OrderController */
893
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
894
            ->setConstructorArgs([$request, $response])
895
            ->getMock();
896
897
        $this->assertSame($cancel, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_getRomOrderCancelModel', [$order]));
898
    }
899
900
    /**
901
     * Test that the controller method EbayEnterprise_Order_OrderController::_getRomCancelSession()
902
     * is invoked, it will instantiate an instance of type core/session and then return the core/session object.
903
     */
904
    public function testGetRomCancelSession()
905
    {
906
        /** @var Mock_Zend_Controller_Request_Abstract */
907
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
908
        /** @var Mock_Zend_Controller_Response_Abstract */
909
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
910
911
        /** @var Mock_Mage_Core_Model_Session */
912
        $session = $this->getModelMockBuilder('core/session')
913
            // Disabling the constructor in order to prevent session_start() function from being
914
            // called which causes headers already sent exception from being thrown.
915
            ->disableOriginalConstructor()
916
            ->getMock();
917
        $this->replaceByMock('singleton', 'core/session', $session);
918
919
        /** @var Mock_EbayEnterprise_Order_OrderController */
920
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
921
            ->setConstructorArgs([$request, $response])
922
            ->getMock();
923
924
        $this->assertSame($session, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_getRomCancelSession', []));
925
    }
926
927
    /**
928
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
929
     */
930
    public function providerHandleRomCancelResponse()
931
    {
932
        return [
933
            [Mage_Sales_Model_Order::STATE_CANCELED],
934
            [null],
935
        ];
936
    }
937
938
    /**
939
     * Test that the controller method EbayEnterprise_Order_OrderController::_handleRomCancelResponse()
940
     * is invoked, it will be passed as first parameter a sales/order object, as second parameter core/session
941
     * object, and as third parameter a string literal representing the redirect URL. Then, it will check if the
942
     * sales/order:getState() matched the class constant Mage_Sales_Model_Order::STATE_CANCELED, if it does, then
943
     * the method core/session::addSuccess() will be called passing in the translated and sprintf return value from
944
     * calling the method ebayenterprise_order/data::__() with class constant EbayEnterprise_Order_OrderController::CANCEL_SUCCESS_MESSAGE
945
     * pass its parameter. However, if the method sales/order:getState() doesn't matched the class constant
946
     * Mage_Sales_Model_Order::STATE_CANCELED, then, the method core/session::addError() will be called and passed in the translated
947
     * and sprintf return value from calling the method ebayenterprise_order/data::__() with class constant
948
     * EbayEnterprise_Order_OrderController::CANCEL_FAIL_MESSAGE. Then, the method
949
     * EbayEnterprise_Order_OrderController::_redirectUrl() will be invoked and passed in the parameter string
950
     * literal representing the redirect URL. Finally, the method EbayEnterprise_Order_OrderController::_handleRomCancelResponse()
951
     * will return itself.
952
     *
953
     *
954
     * @param string | null
955
     * @dataProvider providerHandleRomCancelResponse
956
     */
957
    public function testHandleRomCancelResponse($state)
958
    {
959
        /** @var bool */
960
        $isSuccess = !is_null($state);
961
        /** @var string */
962
        $incrementId = '11999383838111991';
963
        /** @var string */
964
        $translatedSuccessMessage = EbayEnterprise_Order_OrderController::CANCEL_SUCCESS_MESSAGE;
965
        /** @var string */
966
        $succesMessage = sprintf($translatedSuccessMessage, $incrementId);
967
        /** @var string */
968
        $translatedFailMessage = EbayEnterprise_Order_OrderController::CANCEL_FAIL_MESSAGE;
969
        /** @var string */
970
        $failMessage = sprintf($translatedFailMessage, $incrementId);
971
        /** @var string */
972
        $redirectUrl = "http://test.example.com/sales/order/order_id/{$incrementId}";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $incrementId instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
973
        /** @var Mage_Sales_Model_Order */
974
        $order = Mage::getModel('sales/order', [
975
            'increment_id' => $incrementId,
976
            'state' => $state,
977
        ]);
978
        /** @var Mock_Zend_Controller_Request_Abstract */
979
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
980
        /** @var Mock_Zend_Controller_Response_Abstract */
981
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
982
983
        /** @var EbayEnterprise_Order_Helper_Data */
984
        $orderHelper = $this->getHelperMock('ebayenterprise_order/data', ['__']);
985
        $orderHelper->expects($this->once())
986
            ->method('__')
987
            ->will($this->returnValueMap([
988
                [EbayEnterprise_Order_OrderController::CANCEL_SUCCESS_MESSAGE, $translatedSuccessMessage],
989
                [EbayEnterprise_Order_OrderController::CANCEL_FAIL_MESSAGE, $translatedFailMessage]
990
            ]));
991
992
        /** @var Mock_Mage_Core_Model_Session */
993
        $session = $this->getModelMockBuilder('core/session')
994
            // Disabling the constructor in order to prevent session_start() function from being
995
            // called which causes headers already sent exception from being thrown.
996
            ->disableOriginalConstructor()
997
            ->setMethods(['addSuccess', 'addError'])
998
            ->getMock();
999
        $session->expects($isSuccess ? $this->once() : $this->never())
1000
            ->method('addSuccess')
1001
            ->with($this->identicalTo($succesMessage))
1002
            ->will($this->returnSelf());
1003
        $session->expects($isSuccess ? $this->never() : $this->once())
1004
            ->method('addError')
1005
            ->with($this->identicalTo($failMessage))
1006
            ->will($this->returnSelf());
1007
1008
        /** @var Mock_EbayEnterprise_Order_OrderController */
1009
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
1010
            ->setMethods(['_redirectUrl'])
1011
            ->setConstructorArgs([$request, $response])
1012
            ->getMock();
1013
        $controller->expects($this->once())
1014
            ->method('_redirectUrl')
1015
            ->with($this->identicalTo($redirectUrl))
1016
            ->will($this->returnSelf());
1017
        // Replacing the protected class property EbayEnterprise_Order_OrderController::$_orderHelper with a mock.
1018
        EcomDev_Utils_Reflection::setRestrictedPropertyValue($controller, '_orderHelper', $orderHelper);
1019
1020
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_handleRomCancelResponse', [$order, $session, $redirectUrl]));
1021
    }
1022
1023
    /**
1024
     * Test that the controller method EbayEnterprise_Order_OrderController::_handleRomCancelException()
1025
     * is invoked, it will be passed as first parameter an object of type Exception, as second parameter core/session
1026
     * object, and as third parameter a string literal representing the redirect URL. Then, the method core/session::addError()
1027
     * will be invoked and passed in as its parameter a return value from calling the method
1028
     * ebayenterprise_order/data::__(), this method will be passed in the return value from calling the Exception::getMessage()
1029
     * method. Then, the method EbayEnterprise_Order_OrderController::_redirectUrl() will be invoked and passed in the
1030
     * parameter string literal representing the redirect URL. Finally, the method EbayEnterprise_Order_OrderController::_handleRomCancelResponse()
1031
     * will return itself.
1032
     */
1033
    public function testHandleRomCancelException()
1034
    {
1035
        /** @var string */
1036
        $message = 'Exception test message.';
1037
        /** @var string */
1038
        $translatedMessage = $message;
1039
        /** @var Mage_Core_Exception */
1040
        $exception = Mage::exception('Mage_Core', $message);
1041
        /** @var string */
1042
        $redirectUrl = "http://test.example.com/sales/order/order_id/1000001";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal http://test.example.com/.../order/order_id/1000001 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
1043
        /** @var Mock_Zend_Controller_Request_Abstract */
1044
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
1045
        /** @var Mock_Zend_Controller_Response_Abstract */
1046
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
1047
1048
        /** @var EbayEnterprise_Order_Helper_Data */
1049
        $orderHelper = $this->getHelperMock('ebayenterprise_order/data', ['__']);
1050
        $orderHelper->expects($this->once())
1051
            ->method('__')
1052
            ->with($this->identicalTo($message))
1053
            ->will($this->returnValue($translatedMessage));
1054
1055
        /** @var Mock_Mage_Core_Model_Session */
1056
        $session = $this->getModelMockBuilder('core/session')
1057
            // Disabling the constructor in order to prevent session_start() function from being
1058
            // called which causes headers already sent exception from being thrown.
1059
            ->disableOriginalConstructor()
1060
            ->setMethods(['addError'])
1061
            ->getMock();
1062
        $session->expects($this->once())
1063
            ->method('addError')
1064
            ->with($this->identicalTo($translatedMessage))
1065
            ->will($this->returnSelf());
1066
1067
        /** @var Mock_EbayEnterprise_Order_OrderController */
1068
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
1069
            ->setMethods(['_redirectUrl'])
1070
            ->setConstructorArgs([$request, $response])
1071
            ->getMock();
1072
        $controller->expects($this->once())
1073
            ->method('_redirectUrl')
1074
            ->with($this->identicalTo($redirectUrl))
1075
            ->will($this->returnSelf());
1076
        // Replacing the protected class property EbayEnterprise_Order_OrderController::$_orderHelper with a mock.
1077
        EcomDev_Utils_Reflection::setRestrictedPropertyValue($controller, '_orderHelper', $orderHelper);
1078
1079
        $this->assertSame($controller, EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_handleRomCancelException', [$exception, $session, $redirectUrl]));
1080
    }
1081
1082
    /**
1083
     * Test that the controller method EbayEnterprise_Order_OrderController::_displayPage()
1084
     * is invoked and it will call the method EbayEnterprise_Order_OrderController::loadLayout() will be invoked. Then,
1085
     * the method EbayEnterprise_Order_OrderController::_initLayoutMessages() will be called and passed
1086
     * in as parameter the string literal 'catalog/session'. Then, the method EbayEnterprise_Order_OrderController::getLayout()
1087
     * will be called and return an instance of the class Mage_Core_Model_Layout. Then,
1088
     * the method Mage_Core_Model_Layout::getBlock() will be called and passed in as parameter the string
1089
     * literal 'customer_account_navigation' and it will return an instance object that extend the abstract class
1090
     * Mage_Core_Block_Abstract. Then, the method Mage_Core_Block_Abstract::setActive() will be called. Then, the method
1091
     * EbayEnterprise_Order_OrderController::renderLayout() will be called. Finally, the method
1092
     * EbayEnterprise_Order_OrderController::romViewAction() will return null.
1093
     */
1094
    public function testDisplayPage()
1095
    {
1096
        /** @var bool */
1097
        $isLoggedIn = true;
1098
        /** @var string */
1099
        $messages = 'catalog/session';
1100
        /** @var string */
1101
        $blockName = 'customer_account_navigation';
1102
        /** @var string */
1103
        $path = 'sales/order/history';
1104
1105
        $this->_session->expects($this->once())
1106
            ->method('isLoggedIn')
1107
            ->will($this->returnValue($isLoggedIn));
1108
1109
        /** @var EbayEnterprise_Order_Helper_Factory */
1110
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getCustomerSession']);
1111
        $factory->expects($this->once())
1112
            ->method('getCustomerSession')
1113
            ->will($this->returnValue($this->_session));
1114
1115
        /** @var Mage_Core_Block_Abstract */
1116
        $block = $this->getMockForAbstractClass('Mage_Core_Block_Abstract', [], '', true, true, true, ['setActive']);
1117
        $block->expects($this->once())
1118
            ->method('setActive')
1119
            ->with($this->identicalTo($path))
1120
            ->will($this->returnSelf());
1121
1122
        /** @var Mage_Core_Model_Layout */
1123
        $layout = $this->getModelMock('core/layout', ['getBlock']);
1124
        $layout->expects($this->once())
1125
            ->method('getBlock')
1126
            ->with($this->identicalTo($blockName))
1127
            ->will($this->returnValue($block));
1128
1129
        /** @var Mock_Zend_Controller_Request_Abstract */
1130
        $request = $this->getMockForAbstractClass('Zend_Controller_Request_Abstract');
1131
        /** @var Mock_Zend_Controller_Response_Abstract */
1132
        $response = $this->getMockForAbstractClass('Zend_Controller_Response_Abstract');
1133
1134
        /** @var Mock_EbayEnterprise_Order_OrderController */
1135
        $controller = $this->getMockBuilder('EbayEnterprise_Order_OrderController')
1136
            ->setMethods(['loadLayout', '_initLayoutMessages', 'getLayout', 'renderLayout'])
1137
            ->setConstructorArgs([$request, $response])
1138
            ->getMock();
1139
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($controller, [
1140
            '_orderFactory' => $factory,
1141
        ]);
1142
        $controller->expects($this->once())
1143
            ->method('loadLayout')
1144
            ->will($this->returnSelf());
1145
        $controller->expects($this->once())
1146
            ->method('_initLayoutMessages')
1147
            ->with($this->identicalTo($messages))
1148
            ->will($this->returnSelf());
1149
        $controller->expects($this->once())
1150
            ->method('getLayout')
1151
            ->will($this->returnValue($layout));
1152
        $controller->expects($this->once())
1153
            ->method('renderLayout')
1154
            ->will($this->returnSelf());
1155
1156
        $this->assertNull(EcomDev_Utils_Reflection::invokeRestrictedMethod($controller, '_displayPage', []));
1157
    }
1158
1159
    /**
1160
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1161
     */
1162
    public function providerIsValidOperation()
1163
    {
1164
        return [
1165
            [null, false],
1166
            ['10000938382811', true],
1167
        ];
1168
    }
1169
1170
    /**
1171
     * @param string | null
1172
     * @param bool
1173
     * @dataProvider providerIsValidOperation
1174
     */
1175
    public function testIsValidOperation($orderId, $isValid)
1176
    {
1177
        $this->_request->expects($this->any())
1178
            ->method('getParam')
1179
            ->with($this->identicalTo('order_id'))
1180
            ->will($this->returnValue($orderId));
1181
        $this->assertSame($isValid, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_controller, '_isValidOperation', []));
1182
    }
1183
1184
    /**
1185
     * Scenario: Display shipment tracking information
1186
     * Given ROM order id
1187
     * And shipment id
1188
     * And tracking number
1189
     * When displaying shipment tracking information
1190
     * Then get ROM order detail in the registry
1191
     * And store a ebayenterprise_order/tracking instance in the registry
1192
     * And load and render the layout.
1193
     */
1194
    public function testRomtrackingpopupAction()
1195
    {
1196
        /** @var string */
1197
        $shipmentId = 's0-000399399991111';
1198
        /** @var string */
1199
        $trackingNumber = '993999222';
1200
        /** @var Mage_Sales_Model_Order */
1201
        $order = Mage::getModel('sales/order');
1202
        Mage::unregister('rom_order');
1203
        Mage::register('rom_order', $order);
1204
        /** @var EbayEnterprise_Order_Model_Tracking */
1205
        $trackingModel = $this->getModelMockBuilder('ebayenterprise_order/tracking')
1206
            ->disableOriginalConstructor()
1207
            ->getMock();
1208
1209
        /** @var EbayEnterprise_Order_Helper_Factory */
1210
        $factory = $this->getHelperMock('ebayenterprise_order/factory', ['getNewTrackingModel']);
1211
        $factory->expects($this->once())
1212
            ->method('getNewTrackingModel')
1213
            ->with($this->identicalTo($order), $this->identicalTo($shipmentId), $this->identicalTo($trackingNumber))
1214
            ->will($this->returnValue($trackingModel));
1215
1216
        $this->_request->expects($this->exactly(2))
1217
            ->method('getParam')
1218
            ->will($this->returnValueMap([
1219
                ['shipment_id', null, $shipmentId],
1220
                ['tracking_number', null, $trackingNumber],
1221
            ]));
1222
        $this->_controller->expects($this->once())
1223
            ->method('_loadValidOrder')
1224
            ->will($this->returnValue(true));
1225
        $this->_controller->expects($this->once())
1226
            ->method('loadLayout')
1227
            ->will($this->returnValue($this->getModelMock('core/layout')));
1228
        $this->_controller->expects($this->once())
1229
            ->method('renderLayout')
1230
            ->will($this->returnSelf());
1231
        EcomDev_Utils_Reflection::setRestrictedPropertyValues($this->_controller, [
1232
            '_orderFactory' => $factory,
1233
        ]);
1234
1235
        $this->assertNull($this->_controller->romtrackingpopupAction());
1236
    }
1237
}
1238