Passed
Push — master ( 8bf70e...6a7093 )
by Aimeos
03:42
created

StandardTest::testInitAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
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
		$this->view = \TestHelperHtml::view();
22
		$this->context = \TestHelperHtml::context();
23
24
		$this->object = new \Aimeos\Client\Html\Catalog\Session\Pinned\Standard( $this->context );
25
		$this->object->setView( $this->view );
26
	}
27
28
29
	protected function tearDown() : void
30
	{
31
		$this->context->session()->set( 'aimeos/catalog/session/pinned/list', null );
32
		unset( $this->object, $this->context, $this->view );
33
	}
34
35
36
	public function testBody()
37
	{
38
		$pinned = array( $this->getProductItem( 'CNC' )->getId() );
39
		$this->context->session()->set( 'aimeos/catalog/session/pinned/list', $pinned );
40
41
		$this->object->setView( $this->object->data( $this->view ) );
42
		$output = $this->object->body();
43
44
		$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smU', $output );
45
		$this->assertStringStartsWith( '<section class="catalog-session-pinned">', $output );
46
	}
47
48
49
	public function testInitAdd()
50
	{
51
		$prodId = $this->getProductItem( 'CNE' )->getId();
52
53
		$param = array(
54
			'pin_action' => 'add',
55
			'pin_id' => $prodId,
56
		);
57
58
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
59
		$this->view->addHelper( 'param', $helper );
60
61
		$this->object->init();
62
63
		$pinned = $this->context->session()->get( 'aimeos/catalog/session/pinned/list' );
64
		$this->assertEquals( array( $prodId => $prodId ), $pinned );
65
	}
66
67
68
	public function testInitDelete()
69
	{
70
		$prodId = $this->getProductItem( 'CNE' )->getId();
71
		$this->context->session()->set( 'aimeos/catalog/session/pinned/list', array( $prodId => $prodId ) );
72
73
		$param = array(
74
			'pin_action' => 'delete',
75
			'pin_id' => $prodId,
76
		);
77
78
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
79
		$this->view->addHelper( 'param', $helper );
80
81
		$this->object->init();
82
83
		$pinned = $this->context->session()->get( 'aimeos/catalog/session/pinned/list' );
84
		$this->assertEquals( [], $pinned );
85
	}
86
87
88
	/**
89
	 * Returns the product for the given code.
90
	 *
91
	 * @param string $code Unique product code
92
	 * @throws \Exception If no product is found
93
	 * @return \Aimeos\MShop\Product\Item\Iface
94
	 */
95
	protected function getProductItem( $code )
96
	{
97
		return \Aimeos\MShop::create( $this->context, 'product' )->find( $code );
98
	}
99
}
100