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\Basket\Mini; |
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
|
|
|
|
28
|
|
|
$this->object = new \Aimeos\Client\Html\Basket\Mini\Standard( $this->context ); |
29
|
|
|
$this->object->setView( $this->view ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() : void |
34
|
|
|
{ |
35
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
36
|
|
|
\Aimeos\MShop::cache( false ); |
37
|
|
|
|
38
|
|
|
unset( $this->object, $this->context, $this->view ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function testHeader() |
43
|
|
|
{ |
44
|
|
|
$output = $this->object->header(); |
45
|
|
|
$this->assertNotNull( $output ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testBody() |
50
|
|
|
{ |
51
|
|
|
$output = $this->object->body(); |
52
|
|
|
$miniBasket = $this->view->miniBasket; |
53
|
|
|
|
54
|
|
|
$this->assertTrue( $miniBasket instanceof \Aimeos\MShop\Order\Item\Base\Iface ); |
55
|
|
|
$this->assertStringContainsString( '<section class="aimeos basket-mini', $output ); |
56
|
|
|
$this->assertStringContainsString( '<div class="basket-mini-main', $output ); |
57
|
|
|
$this->assertStringContainsString( '<div class="basket-mini-product', $output ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testBodyAddedOneProduct() |
62
|
|
|
{ |
63
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
64
|
|
|
|
65
|
|
|
$productItem = $this->getProductItem( 'CNE' ); |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
$controller->addProduct( $productItem, 9 ); |
69
|
|
|
$this->view->miniBasket = $controller->get(); |
70
|
|
|
|
71
|
|
|
$output = $this->object->body(); |
72
|
|
|
|
73
|
|
|
$controller->clear(); |
74
|
|
|
|
75
|
|
|
$this->assertStringContainsString( '<div class="basket-mini-product', $output ); |
76
|
|
|
$this->assertRegExp( '#9#smU', $output ); |
77
|
|
|
$this->assertRegExp( '#171.00#smU', $output ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testGetSubClientInvalid() |
82
|
|
|
{ |
83
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
84
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testGetSubClientInvalidName() |
89
|
|
|
{ |
90
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
91
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
public function testInit() |
96
|
|
|
{ |
97
|
|
|
$this->object->init(); |
98
|
|
|
|
99
|
|
|
$this->assertEmpty( $this->view->get( 'miniErrorList' ) ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $code |
105
|
|
|
*/ |
106
|
|
|
protected function getProductItem( $code ) |
107
|
|
|
{ |
108
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
109
|
|
|
$search = $manager->filter(); |
110
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
111
|
|
|
|
112
|
|
|
if( ( $item = $manager->search( $search, ['price'] )->first() ) === null ) { |
113
|
|
|
throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $item; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|