StandardTest::testBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
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-2025
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
		\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\Account\Favorite\Standard( $this->context );
30
		$this->object->setView( $this->view );
31
	}
32
33
34
	protected function tearDown() : void
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 testHeader()
44
	{
45
		$output = $this->object->header();
46
47
		$this->assertStringContainsString( '<link class="account-favorite"', $output );
48
		$this->assertStringContainsString( '<script defer class="account-favorite"', $output );
49
	}
50
51
52
	public function testBody()
53
	{
54
		$output = $this->object->body();
55
56
		$this->assertStringContainsString( '<div class="section aimeos account-favorite"', $output );
57
		$this->assertStringContainsString( 'Cafe Noire Expresso', $output );
58
	}
59
60
61
	public function testInit()
62
	{
63
		$this->object->init();
64
65
		$this->assertEmpty( $this->view->get( 'errors' ) );
66
	}
67
68
69
	public function testInitAddItem()
70
	{
71
		$item = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]' );
72
		$id = \Aimeos\MShop::create( $this->context, 'product' )->find( 'CNC' )->getId();
73
		$this->context->setUser( $item );
74
75
		$param = ['fav_action' => 'add', 'fav_id' => $id];
76
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
77
		$this->view->addHelper( 'param', $helper );
78
		$this->object->setView( $this->view );
79
80
81
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class )
82
			->onlyMethods( array( 'addListItem', 'store' ) )
83
			->setConstructorArgs( [$this->context] )
84
			->getMock();
85
86
		$stub->expects( $this->once() )->method( 'addListItem' );
87
		$stub->expects( $this->once() )->method( 'store' );
88
89
90
		\Aimeos\Controller\Frontend::inject( \Aimeos\Controller\Frontend\Customer\Standard::class, $stub );
91
		$this->object->init();
92
	}
93
94
95
	public function testInitDeleteItem()
96
	{
97
		$item = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]', ['product' => ['favorite']] );
98
		$id = $item->getListItems( 'product', 'favorite' )->first()->getRefId();
99
		$this->context->setUser( $item );
100
101
		$param = ['fav_action' => 'delete', 'fav_id' => $id];
102
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
103
		$this->view->addHelper( 'param', $helper );
104
		$this->object->setView( $this->view );
105
106
107
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class )
108
			->onlyMethods( array( 'deleteListItem', 'store' ) )
109
			->setConstructorArgs( [$this->context] )
110
			->getMock();
111
112
		$stub->expects( $this->once() )->method( 'deleteListItem' );
113
		$stub->expects( $this->once() )->method( 'store' );
114
115
116
		\Aimeos\Controller\Frontend::inject( \Aimeos\Controller\Frontend\Customer\Standard::class, $stub );
117
		$this->object->init();
118
	}
119
}
120