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-2025 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Checkout\Standard\Address; |
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
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
23
|
|
|
\Aimeos\MShop::cache( true ); |
24
|
|
|
|
25
|
|
|
$this->view = \TestHelper::view(); |
26
|
|
|
$this->context = \TestHelper::context(); |
27
|
|
|
$this->context->setUser( \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ) ); |
28
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\Client\Html\Checkout\Standard\Address\Standard( $this->context ); |
30
|
|
|
$this->object->setView( $this->view ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function tearDown() : void |
35
|
|
|
{ |
36
|
|
|
\Aimeos\Controller\Frontend::create( $this->context, 'basket' )->clear(); |
37
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
38
|
|
|
\Aimeos\MShop::cache( false ); |
39
|
|
|
|
40
|
|
|
unset( $this->object, $this->context, $this->view ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testBody() |
45
|
|
|
{ |
46
|
|
|
$item = $this->getCustomerItem(); |
47
|
|
|
$this->context->setUser( $item ); |
48
|
|
|
|
49
|
|
|
$this->view->standardStepActive = 'address'; |
50
|
|
|
$this->view->standardSteps = array( 'address', 'after' ); |
51
|
|
|
$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
52
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
53
|
|
|
|
54
|
|
|
$output = $this->object->body(); |
55
|
|
|
$this->assertStringStartsWith( '<div class="section checkout-standard-address">', $output ); |
56
|
|
|
|
57
|
|
|
$this->assertGreaterThanOrEqual( 0, count( $this->view->addressLanguages ) ); |
58
|
|
|
$this->assertGreaterThanOrEqual( 0, count( $this->view->addressCountries ) ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testBodyOtherStep() |
63
|
|
|
{ |
64
|
|
|
$this->view->standardStepActive = 'xyz'; |
65
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
66
|
|
|
|
67
|
|
|
$output = $this->object->body(); |
68
|
|
|
$this->assertEquals( '', $output ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testGetSubClientInvalid() |
73
|
|
|
{ |
74
|
|
|
$this->expectException( \LogicException::class ); |
75
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
public function testGetSubClientInvalidName() |
80
|
|
|
{ |
81
|
|
|
$this->expectException( \LogicException::class ); |
82
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testInit() |
87
|
|
|
{ |
88
|
|
|
$this->object->init(); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( 'address', $this->view->get( 'standardStepActive' ) ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns the customer item for the given code |
96
|
|
|
* |
97
|
|
|
* @param string $code Unique customer code |
98
|
|
|
* @throws \Exception If no customer item is found |
99
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface Customer item object |
100
|
|
|
*/ |
101
|
|
|
protected function getCustomerItem( $code = '[email protected]' ) |
102
|
|
|
{ |
103
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'customer' ); |
104
|
|
|
$search = $manager->filter(); |
105
|
|
|
$search->setConditions( $search->compare( '==', 'customer.code', $code ) ); |
106
|
|
|
|
107
|
|
|
if( ( $item = $manager->search( $search )->first() ) === null ) { |
108
|
|
|
throw new \RuntimeException( 'Customer item not found' ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $item; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|