|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Account\Favorite; |
|
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
|
|
|
$this->context->setUserId( \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' )->getId() ); |
|
25
|
|
|
|
|
26
|
|
|
$this->object = new \Aimeos\Client\Html\Account\Favorite\Standard( $this->context ); |
|
27
|
|
|
$this->object->setView( $this->view ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
protected function tearDown() : void |
|
32
|
|
|
{ |
|
33
|
|
|
unset( $this->object, $this->context, $this->view ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
public function testHeader() |
|
38
|
|
|
{ |
|
39
|
|
|
$output = $this->object->header(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertStringContainsString( '<link class="account-favorite"', $output ); |
|
42
|
|
|
$this->assertStringContainsString( '<script defer class="account-favorite"', $output ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function testBody() |
|
47
|
|
|
{ |
|
48
|
|
|
$output = $this->object->body(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertStringContainsString( '<section class="aimeos account-favorite"', $output ); |
|
51
|
|
|
$this->assertStringContainsString( 'Cafe Noire Expresso', $output ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testInit() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->object->init(); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function testInitAddItem() |
|
64
|
|
|
{ |
|
65
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' ); |
|
66
|
|
|
$id = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC' )->getId(); |
|
67
|
|
|
$this->context->setUserId( $item->getId() ); |
|
68
|
|
|
|
|
69
|
|
|
$param = ['fav_action' => 'add', 'fav_id' => $id]; |
|
70
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
71
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
72
|
|
|
$this->object->setView( $this->view ); |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
|
76
|
|
|
->setMethods( array( 'addListItem', 'store' ) ) |
|
77
|
|
|
->setConstructorArgs( [$this->context] ) |
|
78
|
|
|
->getMock(); |
|
79
|
|
|
|
|
80
|
|
|
$stub->expects( $this->once() )->method( 'addListItem' ); |
|
81
|
|
|
$stub->expects( $this->once() )->method( 'store' ); |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', $stub ); |
|
85
|
|
|
$this->object->init(); |
|
86
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', null ); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testInitDeleteItem() |
|
91
|
|
|
{ |
|
92
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]', ['product' => ['favorite']] ); |
|
93
|
|
|
$id = $item->getListItems( 'product', 'favorite' )->first()->getRefId(); |
|
94
|
|
|
$this->context->setUserId( $item->getId() ); |
|
95
|
|
|
|
|
96
|
|
|
$param = ['fav_action' => 'delete', 'fav_id' => $id]; |
|
97
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
|
98
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
99
|
|
|
$this->object->setView( $this->view ); |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
|
103
|
|
|
->setMethods( array( 'deleteListItem', 'store' ) ) |
|
104
|
|
|
->setConstructorArgs( [$this->context] ) |
|
105
|
|
|
->getMock(); |
|
106
|
|
|
|
|
107
|
|
|
$stub->expects( $this->once() )->method( 'deleteListItem' ); |
|
108
|
|
|
$stub->expects( $this->once() )->method( 'store' ); |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', $stub ); |
|
112
|
|
|
$this->object->init(); |
|
113
|
|
|
\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', null ); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|