|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Payment; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $object; |
|
16
|
|
|
private $context; |
|
17
|
|
|
private $view; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->view = \TestHelperHtml::view(); |
|
23
|
|
|
$this->context = \TestHelperHtml::context(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\Html\Checkout\Standard\Payment\Standard( $this->context ); |
|
26
|
|
|
$this->object->setView( $this->view ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() : void |
|
31
|
|
|
{ |
|
32
|
|
|
\Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->clear(); |
|
33
|
|
|
|
|
34
|
|
|
unset( $this->object, $this->context, $this->view ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testBody() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->view = \TestHelperHtml::view(); |
|
41
|
|
|
$this->view->standardStepActive = 'payment'; |
|
42
|
|
|
$this->view->standardSteps = array( 'before', 'payment', 'after' ); |
|
43
|
|
|
$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order/base' )->create(); |
|
44
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
|
45
|
|
|
|
|
46
|
|
|
$output = $this->object->body(); |
|
47
|
|
|
$this->assertStringStartsWith( '<section class="checkout-standard-payment">', $output ); |
|
48
|
|
|
$this->assertRegExp( '#<li class="row form-item form-group directdebit.accountowner mandatory">#smU', $output ); |
|
49
|
|
|
$this->assertRegExp( '#<li class="row form-item form-group directdebit.accountno mandatory">#smU', $output ); |
|
50
|
|
|
$this->assertRegExp( '#<li class="row form-item form-group directdebit.bankcode mandatory">#smU', $output ); |
|
51
|
|
|
$this->assertRegExp( '#<li class="row form-item form-group directdebit.bankname mandatory">#smU', $output ); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertGreaterThan( 0, count( $this->view->paymentServices ) ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function testBodyOtherStep() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->view = \TestHelperHtml::view(); |
|
60
|
|
|
$this->object->setView( $this->view ); |
|
61
|
|
|
|
|
62
|
|
|
$output = $this->object->body(); |
|
63
|
|
|
$this->assertEquals( '', $output ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
public function testGetSubClientInvalid() |
|
68
|
|
|
{ |
|
69
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
70
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testGetSubClientInvalidName() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
|
77
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testInit() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->object->init(); |
|
84
|
|
|
|
|
85
|
|
|
$this->assertEquals( 'payment', $this->view->get( 'standardStepActive' ) ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function testInitExistingId() |
|
90
|
|
|
{ |
|
91
|
|
|
$manager = \Aimeos\MShop\Service\Manager\Factory::create( $this->context ); |
|
92
|
|
|
$search = $manager->filter(); |
|
93
|
|
|
$search->setConditions( $search->compare( '==', 'service.code', 'unitpaymentcode' ) ); |
|
94
|
|
|
|
|
95
|
|
|
if( ( $service = $manager->search( $search )->first() ) === null ) { |
|
96
|
|
|
throw new \RuntimeException( 'Service item not found' ); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->view = \TestHelperHtml::view(); |
|
100
|
|
|
|
|
101
|
|
|
$param = array( |
|
102
|
|
|
'c_paymentoption' => $service->getId(), |
|
103
|
|
|
); |
|
104
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
105
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
106
|
|
|
|
|
107
|
|
|
$this->object->setView( $this->view ); |
|
108
|
|
|
|
|
109
|
|
|
$this->object->init(); |
|
110
|
|
|
|
|
111
|
|
|
$basket = \Aimeos\Controller\Frontend\Basket\Factory::create( $this->context )->get(); |
|
112
|
|
|
$this->assertEquals( 'unitpaymentcode', $basket->getService( 'payment', 0 )->getCode() ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
public function testInitInvalidId() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->view = \TestHelperHtml::view(); |
|
119
|
|
|
|
|
120
|
|
|
$param = array( 'c_paymentoption' => -1 ); |
|
121
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
122
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
123
|
|
|
|
|
124
|
|
|
$this->object->setView( $this->view ); |
|
125
|
|
|
|
|
126
|
|
|
$this->expectException( '\\Aimeos\\MShop\\Exception' ); |
|
127
|
|
|
$this->object->init(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
public function testInitNotExistingAttributes() |
|
132
|
|
|
{ |
|
133
|
|
|
$manager = \Aimeos\MShop\Service\Manager\Factory::create( $this->context ); |
|
134
|
|
|
$search = $manager->filter(); |
|
135
|
|
|
$search->setConditions( $search->compare( '==', 'service.code', 'unitpaymentcode' ) ); |
|
136
|
|
|
|
|
137
|
|
|
if( ( $service = $manager->search( $search )->first() ) === null ) { |
|
138
|
|
|
throw new \RuntimeException( 'Service item not found' ); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$this->view = \TestHelperHtml::view(); |
|
142
|
|
|
|
|
143
|
|
|
$param = array( |
|
144
|
|
|
'c_paymentoption' => $service->getId(), |
|
145
|
|
|
'c_payment' => array( |
|
146
|
|
|
$service->getId() => array( |
|
147
|
|
|
'notexisting' => 'invalid value', |
|
148
|
|
|
), |
|
149
|
|
|
), |
|
150
|
|
|
); |
|
151
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
152
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
153
|
|
|
|
|
154
|
|
|
$this->object->setView( $this->view ); |
|
155
|
|
|
|
|
156
|
|
|
$this->expectException( '\\Aimeos\\Controller\\Frontend\\Basket\\Exception' ); |
|
157
|
|
|
$this->object->init(); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|