Passed
Push — master ( 3ca382...ddd5fe )
by Aimeos
03:12
created

StandardTest::testSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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), 2017-2023
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Related;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->view = \TestHelper::view();
22
		$this->context = \TestHelper::context();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Product\Related\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelper::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown() : void
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testCreate()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
40
41
		$this->view->item = $manager->create();
42
		$result = $this->object->create();
43
44
		$this->assertStringContainsString( 'item-related', $result );
45
		$this->assertEmpty( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
52
53
		$this->view->item = $manager->find( 'CNE', ['product'] );
54
		$result = $this->object->copy();
55
56
		$this->assertEmpty( $this->view->get( 'errors' ) );
57
		$this->assertMatchesRegularExpression( '/&quot;product.label&quot;:&quot;Cafe Noire Cappuccino \(CNC\)&quot;/', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertEmpty( $this->view->get( 'errors' ) );
66
		$this->assertEmpty( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
73
74
		$this->view->item = $manager->find( 'CNE', ['product'] );
75
		$result = $this->object->get();
76
77
		$this->assertEmpty( $this->view->get( 'errors' ) );
78
		$this->assertMatchesRegularExpression( '/&quot;product.label&quot;:&quot;Cafe Noire Cappuccino \(CNC\)&quot;/', $result );
79
	}
80
81
82
	public function testSave()
83
	{
84
		$param = array(
85
			'related' => [[
86
				'product.lists.id' => '',
87
				'product.lists.type' => 'suggestion',
88
				'product.lists.refid' => '-1',
89
			]]
90
		);
91
92
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
93
		$this->view->item = $manager->create()->setCode( 'jqadm:product/related' )->setId( -1 );
94
95
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
96
		$this->view->addHelper( 'param', $helper );
97
98
		$result = $this->object->save();
99
		$manager->delete( $this->view->item );
100
101
		$this->assertEmpty( $this->view->get( 'errors' ) );
102
		$this->assertEmpty( $result );
103
		$this->assertEquals( 1, count( $this->view->item->getListItems( 'product', 'suggestion' ) ) );
104
	}
105
106
107
	public function testSaveException()
108
	{
109
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Product\Related\Standard::class )
110
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
111
			->onlyMethods( array( 'fromArray' ) )
112
			->getMock();
113
114
		$object->expects( $this->once() )->method( 'fromArray' )
115
			->will( $this->throwException( new \RuntimeException() ) );
116
117
		$this->view = \TestHelper::view();
118
		$this->view->item = \Aimeos\MShop::create( $this->context, 'product' )->create();
119
120
		$object->setView( $this->view );
121
122
		$this->expectException( \RuntimeException::class );
123
		$object->save();
124
	}
125
126
127
	public function testSearch()
128
	{
129
		$this->assertEmpty( $this->object->search() );
130
	}
131
132
133
	public function testGetSubClient()
134
	{
135
		$this->expectException( \LogicException::class );
136
		$this->object->getSubClient( 'unknown' );
137
	}
138
}
139