Passed
Push — master ( 140d1a...4bf2ae )
by Aimeos
18:27 queued 14:35
created

StandardTest::getViewNoRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2023
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Attribute\Product;
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\Attribute\Product\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 testCopy()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
40
		$this->view->item = $manager->find( 'pink', [], 'product', 'color' );
41
42
		$result = $this->object->copy();
43
44
		$this->assertStringContainsString( 'item-product', $result );
45
	}
46
47
48
	public function testCreate()
49
	{
50
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
51
		$this->view->item = $manager->find( 'pink', [], 'product', 'color' );
52
53
		$result = $this->object->create();
54
55
		$this->assertStringContainsString( 'item-product', $result );
56
	}
57
58
59
	public function testGet()
60
	{
61
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
62
		$this->view->item = $manager->find( 'pink', [], 'product', 'color' );
63
64
		$result = $this->object->get();
65
66
		$this->assertStringContainsString( 'item-product', $result );
67
	}
68
69
70
	public function testSave()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
73
74
		$item = $manager->find( 'pink', [], 'product', 'color' );
75
		$item->setCode( 'jqadm-test-save' );
76
		$item->setId( null );
77
78
		$item = $manager->save( $item );
79
80
81
		$param = array(
82
			'site' => 'unittest',
83
			'product' => array(
84
				'attribute.lists.id' => [0 => ''],
85
				'attribute.lists.status' => [0 => 1],
86
				'attribute.lists.refid' => [0 => 'test'],
87
				'attribute.lists.type' => [0 => 'favorite'],
88
				'attribute.lists.datestart' => [0 => '2000-01-01 00:00:00'],
89
				'attribute.lists.dateend' => [0 => '2100-01-01 00:00:00'],
90
				'config' => [0 => ['key' => [0 => 'test'], 'val' => [0 => 'value']]],
91
			),
92
		);
93
94
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
95
		$this->view->addHelper( 'param', $helper );
96
		$this->view->item = $item;
97
98
		$result = $this->object->save();
99
100
		$item = $manager->get( $item->getId(), ['product'] );
0 ignored issues
show
Bug introduced by
It seems like $item->getId() can also be of type Aimeos\Map and null; however, parameter $id of Aimeos\MShop\Common\Manager\Iface::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
		$item = $manager->get( /** @scrutinizer ignore-type */ $item->getId(), ['product'] );
Loading history...
101
		$manager->delete( $item->getId() );
102
103
		$this->assertEmpty( $this->view->get( 'errors' ) );
104
		$this->assertEmpty( $result );
105
		$this->assertEquals( 1, count( $item->getListItems() ) );
106
107
		foreach( $item->getListItems( 'product' ) as $listItem )
108
		{
109
			$this->assertEquals( $item->getId(), $listItem->getParentId() );
110
			$this->assertEquals( 'favorite', $listItem->getType() );
111
			$this->assertEquals( 'product', $listItem->getDomain() );
112
			$this->assertEquals( '2000-01-01 00:00:00', $listItem->getDateStart() );
113
			$this->assertEquals( '2100-01-01 00:00:00', $listItem->getDateEnd() );
114
			$this->assertEquals( ['test' => 'value'], $listItem->getConfig() );
115
			$this->assertEquals( 'test', $listItem->getRefId() );
116
			$this->assertEquals( 1, $listItem->getStatus() );
117
		}
118
	}
119
120
121
	public function testSaveException()
122
	{
123
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Attribute\Product\Standard::class )
124
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
125
			->onlyMethods( array( 'fromArray' ) )
126
			->getMock();
127
128
		$object->expects( $this->once() )->method( 'fromArray' )
129
			->will( $this->throwException( new \RuntimeException() ) );
130
131
		$object->setView( $this->getViewNoRender() );
132
133
		$this->expectException( \RuntimeException::class );
134
		$object->save();
135
	}
136
137
138
	public function testGetSubClient()
139
	{
140
		$this->expectException( \LogicException::class );
141
		$this->object->getSubClient( 'unknown' );
142
	}
143
144
145
	protected function getViewNoRender()
146
	{
147
		$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
148
			->setConstructorArgs( array( [] ) )
149
			->onlyMethods( ['render'] )->addMethods( ['config'] )
150
			->getMock();
151
152
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
153
		$view->item = $manager->find( 'pink', [], 'product', 'color' );
0 ignored issues
show
Bug introduced by
Accessing item on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
154
155
		return $view;
156
	}
157
}
158