Passed
Push — master ( 29da27...7ca054 )
by Aimeos
03:58
created

StandardTest::testHeaderException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A StandardTest::testBody() 0 6 1
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\Watch;
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\Watch\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-watch"', $output );
42
		$this->assertStringContainsString( '<script defer class="account-watch"', $output );
43
	}
44
45
46
	public function testBody()
47
	{
48
		$output = $this->object->body();
49
50
		$this->assertStringContainsString( '<section class="aimeos account-watch"', $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( 'watchErrorList' ) );
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 = ['wat_action' => 'add', 'wat_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' => ['watch']] );
93
		$id = $item->getListItems( 'product', 'watch' )->first()->getRefId();
94
		$this->context->setUserId( $item->getId() );
95
96
		$param = ['wat_action' => 'delete', 'wat_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
117
	public function testInitEditItem()
118
	{
119
		$item = \Aimeos\MShop::create( $this->context, 'customer' )->find( '[email protected]', ['product' => ['watch']] );
120
		$id = $item->getListItems( 'product', 'watch' )->first()->getRefId();
121
		$this->context->setUserId( $item->getId() );
122
123
		$param = ['wat_action' => 'edit', 'wat_id' => $id];
124
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
125
		$this->view->addHelper( 'param', $helper );
126
		$this->object->setView( $this->view );
127
128
129
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class )
130
			->setMethods( array( 'addListItem', 'store' ) )
131
			->setConstructorArgs( [$this->context] )
132
			->getMock();
133
134
		$stub->expects( $this->once() )->method( 'addListItem' );
135
		$stub->expects( $this->once() )->method( 'store' );
136
137
138
		\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', $stub );
139
		$this->object->init();
140
		\Aimeos\Controller\Frontend\Customer\Factory::injectController( '\Aimeos\Controller\Frontend\Customer\Standard', null );
141
	}
142
}
143