|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Aimeos\Controller\Jobs\Customer\Email\Watch; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
|
8
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
9
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
|
10
|
|
|
*/ |
|
11
|
|
|
class StandardTest extends \PHPUnit_Framework_TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private $object; |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $aimeos; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Sets up the fixture, for example, opens a network connection. |
|
20
|
|
|
* This method is called before a test is executed. |
|
21
|
|
|
* |
|
22
|
|
|
* @access protected |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->context = \TestHelperJobs::getContext(); |
|
27
|
|
|
$this->aimeos = \TestHelperJobs::getAimeos(); |
|
28
|
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\Controller\Jobs\Customer\Email\Watch\Standard( $this->context, $this->aimeos ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Tears down the fixture, for example, closes a network connection. |
|
35
|
|
|
* This method is called after a test is executed. |
|
36
|
|
|
* |
|
37
|
|
|
* @access protected |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function tearDown() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->object = null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function testGetName() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->assertEquals( 'Product notification e-mails', $this->object->getName() ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
public function testGetDescription() |
|
52
|
|
|
{ |
|
53
|
|
|
$text = 'Sends e-mails for watched products'; |
|
54
|
|
|
$this->assertEquals( $text, $this->object->getDescription() ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function testRun() |
|
59
|
|
|
{ |
|
60
|
|
|
$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' ) |
|
61
|
|
|
->disableOriginalConstructor() |
|
62
|
|
|
->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$mailMsgStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\Message\\None' ) |
|
65
|
|
|
->disableOriginalConstructor() |
|
66
|
|
|
->disableOriginalClone() |
|
67
|
|
|
->getMock(); |
|
68
|
|
|
|
|
69
|
|
|
$mailStub->expects( $this->once() ) |
|
70
|
|
|
->method( 'createMessage' ) |
|
71
|
|
|
->will( $this->returnValue( $mailMsgStub ) ); |
|
72
|
|
|
|
|
73
|
|
|
$mailStub->expects( $this->once() )->method( 'send' ); |
|
74
|
|
|
|
|
75
|
|
|
$this->context->setMail( $mailStub ); |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
$product = $this->getProductItem(); |
|
79
|
|
|
$prices = $product->getRefItems( 'price', 'default', 'default' ); |
|
80
|
|
|
|
|
81
|
|
|
$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' ) |
|
82
|
|
|
->setConstructorArgs( array( $this->context, $this->aimeos ) ) |
|
83
|
|
|
->setMethods( array( 'getListProducts' ) ) |
|
84
|
|
|
->getMock(); |
|
85
|
|
|
|
|
86
|
|
|
$object->expects( $this->once() )->method( 'getListProducts' ) |
|
87
|
|
|
->will( $this->returnValue( array( -1 => array( 'item' => $product, 'price' => reset( $prices ) ) ) ) ); |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$object->run(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
public function testRunException() |
|
95
|
|
|
{ |
|
96
|
|
|
$mailStub = $this->getMockBuilder( '\\Aimeos\\MW\\Mail\\None' ) |
|
97
|
|
|
->disableOriginalConstructor() |
|
98
|
|
|
->getMock(); |
|
99
|
|
|
|
|
100
|
|
|
$mailStub->expects( $this->once() ) |
|
101
|
|
|
->method( 'createMessage' ) |
|
102
|
|
|
->will( $this->throwException( new \Exception() ) ); |
|
103
|
|
|
|
|
104
|
|
|
$this->context->setMail( $mailStub ); |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
$product = $this->getProductItem(); |
|
108
|
|
|
$prices = $product->getRefItems( 'price', 'default', 'default' ); |
|
109
|
|
|
|
|
110
|
|
|
$object = $this->getMockBuilder( '\\Aimeos\\Controller\\Jobs\\Customer\\Email\\Watch\\Standard' ) |
|
111
|
|
|
->setConstructorArgs( array( $this->context, $this->aimeos ) ) |
|
112
|
|
|
->setMethods( array( 'getListProducts' ) ) |
|
113
|
|
|
->getMock(); |
|
114
|
|
|
|
|
115
|
|
|
$object->expects( $this->once() )->method( 'getListProducts' ) |
|
116
|
|
|
->will( $this->returnValue( array( -1 => array( 'item' => $product, 'price' => reset( $prices ) ) ) ) ); |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
$object->run(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
protected function getProductItem() |
|
124
|
|
|
{ |
|
125
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context ); |
|
126
|
|
|
$search = $manager->createSearch(); |
|
127
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', 'CNC' ) ); |
|
128
|
|
|
$items = $manager->searchItems( $search, array( 'media', 'price', 'text' ) ); |
|
129
|
|
|
|
|
130
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
|
131
|
|
|
throw new \Exception( 'No product item with code "CNC" found' ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return $item; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|