Completed
Push — master ( a13539...bd1b6d )
by Aimeos
04:27
created

StandardTest::testSaveMShopException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
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), 2017-2020
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Catalog\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 = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Catalog\Product\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelperJqadm::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, 'catalog' );
40
		$this->view->item = $manager->findItem( 'cafe' );
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, 'catalog' );
51
		$this->view->item = $manager->findItem( 'cafe' );
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, 'catalog' );
62
		$this->view->item = $manager->findItem( 'cafe' );
63
64
		$result = $this->object->get();
65
66
		$this->assertStringContainsString( 'item-product', $result );
67
		$this->assertStringContainsString( 'Cafe Noire Expresso', $result );
68
	}
69
70
71
	public function testSave()
72
	{
73
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
74
75
		$item = $manager->findItem( 'cafe' );
76
		$item->setCode( 'jqadm-test-save' );
77
		$item->setId( null );
78
79
		$item = $manager->insertItem( $item );
80
81
82
		$param = array(
83
			'site' => 'unittest',
84
			'product' => array(
85
				'catalog.lists.id' => [0 => ''],
86
				'catalog.lists.status' => [0 => 1],
87
				'catalog.lists.refid' => [0 => 'test'],
88
				'catalog.lists.type' => [0 => 'promotion'],
89
				'catalog.lists.datestart' => [0 => '2000-01-01 00:00:00'],
90
				'catalog.lists.dateend' => [0 => '2100-01-01 00:00:00'],
91
				'config' => [0 => ['key' => [0 => 'test'], 'val' => [0 => 'value']]],
92
			),
93
		);
94
95
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
96
		$this->view->addHelper( 'param', $helper );
97
		$this->view->item = $item;
98
99
		$result = $this->object->save();
100
101
		$item = $manager->getItem( $item->getId(), ['product'] );
102
		$manager->deleteItem( $item->getId() );
103
104
		$this->assertEmpty( $this->view->get( 'errors' ) );
105
		$this->assertEmpty( $result );
106
		$this->assertEquals( 1, count( $item->getListItems() ) );
107
108
		foreach( $item->getListItems( 'product' ) as $listItem )
109
		{
110
			$this->assertEquals( $item->getId(), $listItem->getParentId() );
111
			$this->assertEquals( 'promotion', $listItem->getType() );
112
			$this->assertEquals( 'product', $listItem->getDomain() );
113
			$this->assertEquals( '2000-01-01 00:00:00', $listItem->getDateStart() );
114
			$this->assertEquals( '2100-01-01 00:00:00', $listItem->getDateEnd() );
115
			$this->assertEquals( ['test' => 'value'], $listItem->getConfig() );
116
			$this->assertEquals( 'test', $listItem->getRefId() );
117
			$this->assertEquals( 1, $listItem->getStatus() );
118
		}
119
	}
120
121
122
	public function testSaveException()
123
	{
124
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Catalog\Product\Standard::class )
125
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
126
			->setMethods( array( 'fromArray' ) )
127
			->getMock();
128
129
		$object->expects( $this->once() )->method( 'fromArray' )
130
			->will( $this->throwException( new \RuntimeException() ) );
131
132
		$object->setView( $this->getViewNoRender() );
133
134
		$this->expectException( \RuntimeException::class );
135
		$object->save();
136
	}
137
138
139
	public function testGetSubClient()
140
	{
141
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
142
		$this->object->getSubClient( 'unknown' );
143
	}
144
145
146
	protected function getViewNoRender()
147
	{
148
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
149
			->setConstructorArgs( array( [] ) )
150
			->setMethods( array( 'render', 'config' ) )
151
			->getMock();
152
153
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
154
		$view->item = $manager->findItem( 'cafe' );
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...
155
156
		return $view;
157
	}
158
}
159