1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Catalog\Session\Pinned; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
22
|
|
|
\Aimeos\MShop::cache( true ); |
23
|
|
|
|
24
|
|
|
$this->view = \TestHelper::view(); |
25
|
|
|
$this->context = \TestHelper::context(); |
26
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Session\Pinned\Standard( $this->context ); |
28
|
|
|
$this->object->setView( $this->view ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function tearDown() : void |
33
|
|
|
{ |
34
|
|
|
$this->context->session()->set( 'aimeos/catalog/session/pinned/list', null ); |
35
|
|
|
|
36
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
37
|
|
|
\Aimeos\MShop::cache( false ); |
38
|
|
|
|
39
|
|
|
unset( $this->object, $this->context, $this->view ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testBody() |
44
|
|
|
{ |
45
|
|
|
$pinned = array( $this->getProductItem( 'CNC' )->getId() ); |
46
|
|
|
$this->context->session()->set( 'aimeos/catalog/session/pinned/list', $pinned ); |
47
|
|
|
|
48
|
|
|
$this->object->setView( $this->object->data( $this->view ) ); |
49
|
|
|
$output = $this->object->body(); |
50
|
|
|
|
51
|
|
|
$this->assertMatchesRegularExpression( '#.*Cafe Noire Cappuccino.*#smU', $output ); |
52
|
|
|
$this->assertStringStartsWith( '<div class="section catalog-session-pinned">', $output ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testInitAdd() |
57
|
|
|
{ |
58
|
|
|
$prodId = $this->getProductItem( 'CNE' )->getId(); |
59
|
|
|
|
60
|
|
|
$param = array( |
61
|
|
|
'pin_action' => 'add', |
62
|
|
|
'pin_id' => $prodId, |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
66
|
|
|
$this->view->addHelper( 'param', $helper ); |
67
|
|
|
|
68
|
|
|
$this->object->init(); |
69
|
|
|
|
70
|
|
|
$pinned = $this->context->session()->get( 'aimeos/catalog/session/pinned/list' ); |
71
|
|
|
$this->assertEquals( array( $prodId => $prodId ), $pinned ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testInitDelete() |
76
|
|
|
{ |
77
|
|
|
$prodId = $this->getProductItem( 'CNE' )->getId(); |
78
|
|
|
$this->context->session()->set( 'aimeos/catalog/session/pinned/list', array( $prodId => $prodId ) ); |
79
|
|
|
|
80
|
|
|
$param = array( |
81
|
|
|
'pin_action' => 'delete', |
82
|
|
|
'pin_id' => $prodId, |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
86
|
|
|
$this->view->addHelper( 'param', $helper ); |
87
|
|
|
|
88
|
|
|
$this->object->init(); |
89
|
|
|
|
90
|
|
|
$pinned = $this->context->session()->get( 'aimeos/catalog/session/pinned/list' ); |
91
|
|
|
$this->assertEquals( [], $pinned ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the product for the given code. |
97
|
|
|
* |
98
|
|
|
* @param string $code Unique product code |
99
|
|
|
* @throws \Exception If no product is found |
100
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface |
101
|
|
|
*/ |
102
|
|
|
protected function getProductItem( $code ) |
103
|
|
|
{ |
104
|
|
|
return \Aimeos\MShop::create( $this->context, 'product' )->find( $code ); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|