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

StandardTest::testGetBodyException()   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\Checkout\Standard;
4
5
6
/**
7
 * @copyright Metaways Infosystems GmbH, 2013
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\Checkout\Standard\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\Checkout\Standard\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
		$view = $this->object->getView();
59
		$view->standardStepActive = 'address';
60
61
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'c_step' => 'payment' ) );
62
		$view->addHelper( 'param', $helper );
63
64
		$output = $this->object->getBody();
65
66
		$this->assertStringStartsWith( '<section class="aimeos checkout-standard">', $output );
67
		$this->assertRegExp( '#<ol class="steps">.*<li class="step.*>.*</li>.*</ol>#smU', $output );
68
		$this->assertContains( '<section class="checkout-standard-address', $output );
69
		$this->assertNotContains( '<section class="checkout-standard-delivery', $output );
70
		$this->assertNotContains( '<section class="checkout-standard-payment', $output );
71
		$this->assertNotContains( '<section class="checkout-standard-summary', $output );
72
		$this->assertNotContains( '<section class="checkout-standard-order', $output );
73
	}
74
75
76
	public function testGetBodyOnepage()
77
	{
78
		$view = $this->object->getView();
79
80
		$config = $this->context->getConfig();
81
		$config->set( 'client/html/checkout/standard/onepage', array( 'address', 'delivery', 'payment', 'summary' ) );
82
83
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
84
		$view->addHelper( 'config', $helper );
85
86
		$output = $this->object->getBody();
87
88
		$this->assertContains( '<section class="checkout-standard-address', $output );
89
		$this->assertContains( '<section class="checkout-standard-delivery', $output );
90
		$this->assertContains( '<section class="checkout-standard-payment', $output );
91
		$this->assertContains( '<section class="checkout-standard-summary', $output );
92
		$this->assertNotContains( '<section class="checkout-standard-order', $output );
93
	}
94
95
96
	public function testGetBodyOnepagePartitial()
97
	{
98
		$view = $this->object->getView();
99
		$view->standardStepActive = 'delivery';
100
101
		$config = $this->context->getConfig();
102
		$config->set( 'client/html/checkout/standard/onepage', array( 'delivery', 'payment' ) );
103
104
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
105
		$view->addHelper( 'config', $helper );
106
107
		$output = $this->object->getBody();
108
109
		$this->assertContains( '<section class="checkout-standard-delivery', $output );
110
		$this->assertContains( '<section class="checkout-standard-payment', $output );
111
		$this->assertNotContains( '<section class="checkout-standard-address', $output );
112
		$this->assertNotContains( '<section class="checkout-standard-summary', $output );
113
		$this->assertNotContains( '<section class="checkout-standard-order', $output );
114
	}
115
116
117
	public function testGetBodyOnepageDifferentStep()
118
	{
119
		$view = $this->object->getView();
120
		$view->standardStepActive = 'address';
121
122
		$config = $this->context->getConfig();
123
		$config->set( 'client/html/checkout/standard/onepage', array( 'delivery', 'payment' ) );
124
125
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
126
		$view->addHelper( 'config', $helper );
127
128
		$output = $this->object->getBody();
129
130
		$this->assertContains( '<section class="checkout-standard-address', $output );
131
		$this->assertNotContains( '<section class="checkout-standard-delivery', $output );
132
		$this->assertNotContains( '<section class="checkout-standard-payment', $output );
133
		$this->assertNotContains( '<section class="checkout-standard-summary', $output );
134
		$this->assertNotContains( '<section class="checkout-standard-order', $output );
135
	}
136
137
138
	public function testGetBodyHtmlException()
139
	{
140
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Standard\Standard' )
141
			->setConstructorArgs( array( $this->context, array() ) )
142
			->setMethods( array( 'setViewParams' ) )
143
			->getMock();
144
145
		$object->expects( $this->once() )->method( 'setViewParams' )
146
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
147
148
		$object->setView( \TestHelperHtml::getView() );
149
150
		$this->assertContains( 'test exception', $object->getBody() );
151
	}
152
153
154
	public function testGetBodyFrontendException()
155
	{
156
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Standard\Standard' )
157
			->setConstructorArgs( array( $this->context, array() ) )
158
			->setMethods( array( 'setViewParams' ) )
159
			->getMock();
160
161
		$object->expects( $this->once() )->method( 'setViewParams' )
162
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
163
164
		$object->setView( \TestHelperHtml::getView() );
165
166
		$this->assertContains( 'test exception', $object->getBody() );
167
	}
168
169
170
	public function testGetBodyMShopException()
171
	{
172
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Standard\Standard' )
173
			->setConstructorArgs( array( $this->context, array() ) )
174
			->setMethods( array( 'setViewParams' ) )
175
			->getMock();
176
177
		$object->expects( $this->once() )->method( 'setViewParams' )
178
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
179
180
		$object->setView( \TestHelperHtml::getView() );
181
182
		$this->assertContains( 'test exception', $object->getBody() );
183
	}
184
185
186
	public function testGetBodyException()
187
	{
188
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Standard\Standard' )
189
			->setConstructorArgs( array( $this->context, array() ) )
190
			->setMethods( array( 'setViewParams' ) )
191
			->getMock();
192
193
		$object->expects( $this->once() )->method( 'setViewParams' )
194
			->will( $this->throwException( new \Exception() ) );
195
196
		$object->setView( \TestHelperHtml::getView() );
197
198
		$this->assertContains( 'A non-recoverable error occured', $object->getBody() );
199
	}
200
201
202
	public function testGetSubClient()
203
	{
204
		$client = $this->object->getSubClient( 'address', 'Standard' );
205
		$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client );
206
	}
207
208
209
	public function testGetSubClientInvalid()
210
	{
211
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
212
		$this->object->getSubClient( 'invalid', 'invalid' );
213
	}
214
215
216
	public function testGetSubClientInvalidName()
217
	{
218
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
219
		$this->object->getSubClient( '$$$', '$$$' );
220
	}
221
222
223
	public function testProcess()
224
	{
225
		$this->object->process();
226
	}
227
}
228