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\Checkout\Update;
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
		$paths = \TestHelperHtml::getHtmlTemplatePaths();
20
		$this->context = \TestHelperHtml::getContext();
21
22
		$this->object = new \Aimeos\Client\Html\Checkout\Update\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\Update\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
		$this->assertEquals( '', $this->object->getBody() );
59
	}
60
61
62
	public function testGetBodyHtmlException()
63
	{
64
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Update\Standard' )
65
			->setConstructorArgs( array( $this->context, array() ) )
66
			->setMethods( array( 'setViewParams' ) )
67
			->getMock();
68
69
		$object->expects( $this->once() )->method( 'setViewParams' )
70
			->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) );
71
72
		$object->setView( \TestHelperHtml::getView() );
73
74
		$object->getBody();
75
	}
76
77
78
	public function testGetBodyFrontendException()
79
	{
80
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Update\Standard' )
81
			->setConstructorArgs( array( $this->context, array() ) )
82
			->setMethods( array( 'setViewParams' ) )
83
			->getMock();
84
85
		$object->expects( $this->once() )->method( 'setViewParams' )
86
			->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) );
87
88
		$object->setView( \TestHelperHtml::getView() );
89
90
		$object->getBody();
91
	}
92
93
94
	public function testGetBodyMShopException()
95
	{
96
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Update\Standard' )
97
			->setConstructorArgs( array( $this->context, array() ) )
98
			->setMethods( array( 'setViewParams' ) )
99
			->getMock();
100
101
		$object->expects( $this->once() )->method( 'setViewParams' )
102
			->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) );
103
104
		$object->setView( \TestHelperHtml::getView() );
105
106
		$object->getBody();
107
	}
108
109
110
	public function testGetBodyException()
111
	{
112
		$object = $this->getMockBuilder( '\Aimeos\Client\Html\Checkout\Update\Standard' )
113
			->setConstructorArgs( array( $this->context, array() ) )
114
			->setMethods( array( 'setViewParams' ) )
115
			->getMock();
116
117
		$object->expects( $this->once() )->method( 'setViewParams' )
118
			->will( $this->throwException( new \Exception() ) );
119
120
		$object->setView( \TestHelperHtml::getView() );
121
122
		$object->getBody();
123
	}
124
125
126
	public function testGetSubClientInvalid()
127
	{
128
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
129
		$this->object->getSubClient( 'invalid', 'invalid' );
130
	}
131
132
133
	public function testGetSubClientInvalidName()
134
	{
135
		$this->setExpectedException( '\\Aimeos\\Client\\Html\\Exception' );
136
		$this->object->getSubClient( '$$$', '$$$' );
137
	}
138
139
140
	public function testProcess()
141
	{
142
		$params = array(
143
			'code' => 'paypalexpress',
144
			'orderid' => $this->getOrder( '2011-09-17 16:14:32' )->getId(),
145
		);
146
147
		$view = $this->object->getView();
148
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $params );
149
		$view->addHelper( 'param', $helper );
150
151
		$request = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' );
152
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $request, '127.0.0.1', 'test' );
153
		$view->addHelper( 'request', $helper );
154
155
		$this->object->process();
156
	}
157
158
159
	public function testProcessNoService()
160
	{
161
		$view = $this->object->getView();
162
163
		$request = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' );
164
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $request, '127.0.0.1', 'test' );
165
		$view->addHelper( 'request', $helper );
166
167
		$this->object->process();
168
	}
169
170
171
	/**
172
	 * @param string $date
173
	 */
174
	protected function getOrder( $date )
175
	{
176
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context );
177
178
		$search = $orderManager->createSearch();
179
		$search->setConditions( $search->compare( '==', 'order.datepayment', $date ) );
180
181
		$result = $orderManager->searchItems( $search );
182
183
		if( ( $item = reset( $result ) ) === false ) {
184
			throw new \Exception( 'No order found' );
185
		}
186
187
		return $item;
188
	}
189
}
190