Completed
Push — master ( d9c87d...d2fca1 )
by Aimeos
06:49
created

StandardTest::testGetHeaderException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\Client\Html\Account\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
16
17
	protected function setUp()
18
	{
19
		$this->context = \TestHelperHtml::getContext();
20
21
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
22
		$this->object = new \Aimeos\Client\Html\Account\Watch\Standard( $this->context, $paths );
23
		$this->object->setView( \TestHelperHtml::getView() );
24
	}
25
26
27
	protected function tearDown()
28
	{
29
		unset( $this->object );
30
	}
31
32
33
	public function testGetHeader()
34
	{
35
		$output = $this->object->getHeader();
36
		$this->assertNotNull( $output );
37
	}
38
39
40
	public function testGetHeaderException()
41
	{
42
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Watch\Standard' )
43
			->setConstructorArgs( array( $this->context, array() ) )
44
			->setMethods( array( 'setViewParams' ) )
45
			->getMock();
46
47
		$object->expects( $this->once() )->method( 'setViewParams' )
48
			->will( $this->throwException( new \Exception() ) );
49
50
		$object->setView( \TestHelperHtml::getView() );
51
52
		$this->assertEquals( null, $object->getHeader() );
53
	}
54
55
56
	public function testGetBody()
57
	{
58
		$output = $this->object->getBody();
59
		$this->assertStringStartsWith( '<section class="aimeos account-watch">', $output );
60
	}
61
62
63
	public function testGetBodyHtmlException()
64
	{
65
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Watch\Standard' )
66
			->setConstructorArgs( array( $this->context, array() ) )
67
			->setMethods( array( 'setViewParams' ) )
68
			->getMock();
69
70
		$object->expects( $this->once() )->method( 'setViewParams' )
71
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
72
73
		$object->setView( \TestHelperHtml::getView() );
74
75
		$this->assertContains( 'test exception', $object->getBody() );
76
	}
77
78
79
	public function testGetBodyFrontendException()
80
	{
81
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Watch\Standard' )
82
			->setConstructorArgs( array( $this->context, array() ) )
83
			->setMethods( array( 'setViewParams' ) )
84
			->getMock();
85
86
		$object->expects( $this->once() )->method( 'setViewParams' )
87
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
88
89
		$object->setView( \TestHelperHtml::getView() );
90
91
		$this->assertContains( 'test exception', $object->getBody() );
92
	}
93
94
95
	public function testGetBodyMShopException()
96
	{
97
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Account\Watch\Standard' )
98
			->setConstructorArgs( array( $this->context, array() ) )
99
			->setMethods( array( 'setViewParams' ) )
100
			->getMock();
101
102
		$object->expects( $this->once() )->method( 'setViewParams' )
103
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
104
105
		$object->setView( \TestHelperHtml::getView() );
106
107
		$this->assertContains( 'test exception', $object->getBody() );
108
	}
109
110
111
	public function testGetSubClientInvalid()
112
	{
113
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
114
		$this->object->getSubClient( 'invalid', 'invalid' );
115
	}
116
117
118
	public function testGetSubClientInvalidName()
119
	{
120
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
121
		$this->object->getSubClient( '$$$', '$$$' );
122
	}
123
124
125
	public function testProcess()
126
	{
127
		$this->object->process();
128
	}
129
130
131
	public function testProcessAddItem()
132
	{
133
		$this->context->setUserId( '123' );
134
135
		$view = $this->object->getView();
136
		$param = array(
137
			'wat_action' => 'add',
138
			'wat_id' => 321,
139
		);
140
141
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
142
		$view->addHelper( 'param', $helper );
143
144
145
146
		$listManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Lists\\Standard' )
147
			->setMethods( array( 'saveItem', 'moveItem' ) )
148
			->setConstructorArgs( array( $this->context ) )
149
			->getMock();
150
151
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' )
152
			->setMethods( array( 'getSubManager' ) )
153
			->setConstructorArgs( array( $this->context ) )
154
			->getMock();
155
156
		$name = 'ClientHtmlAccountWatchDefaultProcess';
157
		$this->context->getConfig()->set( 'mshop/customer/manager/name', $name );
158
159
		\Aimeos\MShop\Customer\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Customer\\Manager\\' . $name, $managerStub );
160
161
162
		$managerStub->expects( $this->atLeastOnce() )->method( 'getSubManager' )
163
			->will( $this->returnValue( $listManagerStub ) );
164
165
		$listManagerStub->expects( $this->once() )->method( 'saveItem' );
166
		$listManagerStub->expects( $this->once() )->method( 'moveItem' );
167
168
169
		$this->object->process();
170
	}
171
172
173
	public function testProcessEditItem()
174
	{
175
		$this->context->setUserId( '123' );
176
177
		$view = $this->object->getView();
178
		$param = array(
179
			'wat_action' => 'edit',
180
			'wat_id' => 321,
181
		);
182
183
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
184
		$view->addHelper( 'param', $helper );
185
186
187
		$listManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Lists\\Standard' )
188
			->setMethods( array( 'saveItem', 'searchItems' ) )
189
			->setConstructorArgs( array( $this->context ) )
190
			->getMock();
191
192
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' )
193
			->setMethods( array( 'getSubManager' ) )
194
			->setConstructorArgs( array( $this->context ) )
195
			->getMock();
196
197
		$name = 'ClientHtmlAccountWatchDefaultProcess';
198
		$this->context->getConfig()->set( 'mshop/customer/manager/name', $name );
199
200
		\Aimeos\MShop\Customer\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Customer\\Manager\\' . $name, $managerStub );
201
202
203
		$item = $listManagerStub->createItem();
204
		$item->setRefId( 321 );
205
206
		$managerStub->expects( $this->atLeastOnce() )->method( 'getSubManager' )
207
			->will( $this->returnValue( $listManagerStub ) );
208
209
		$listManagerStub->expects( $this->once() )->method( 'searchItems' )
210
			->will( $this->returnValue( array( $item ) ) );
211
212
		$listManagerStub->expects( $this->once() )->method( 'saveItem' );
213
214
215
		$this->object->process();
216
	}
217
218
219
	public function testProcessDeleteItem()
220
	{
221
		$this->context->setUserId( '123' );
222
223
		$view = $this->object->getView();
224
		$param = array(
225
			'wat_action' => 'delete',
226
			'wat_id' => 321,
227
		);
228
229
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
230
		$view->addHelper( 'param', $helper );
231
232
233
234
		$listManagerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Lists\\Standard' )
235
			->setMethods( array( 'deleteItems' ) )
236
			->setConstructorArgs( array( $this->context ) )
237
			->getMock();
238
239
		$managerStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Customer\\Manager\\Standard' )
240
			->setMethods( array( 'getSubManager' ) )
241
			->setConstructorArgs( array( $this->context ) )
242
			->getMock();
243
244
		$name = 'ClientHtmlAccountWatchDefaultProcess';
245
		$this->context->getConfig()->set( 'mshop/customer/manager/name', $name );
246
247
		\Aimeos\MShop\Customer\Manager\Factory::injectManager( '\\Aimeos\\MShop\\Customer\\Manager\\' . $name, $managerStub );
248
249
250
		$managerStub->expects( $this->atLeastOnce() )->method( 'getSubManager' )
251
			->will( $this->returnValue( $listManagerStub ) );
252
253
		$listManagerStub->expects( $this->once() )->method( 'deleteItems' );
254
255
256
		$this->object->process();
257
	}
258
}