Completed
Push — master ( b98343...f157ac )
by Aimeos
03:37
created

StandardTest::testSaveException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Characteristic\Property;
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()
20
	{
21
		$this->view = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
		$templatePaths = \TestHelperJqadm::getTemplatePaths();
24
25
		$this->object = new \Aimeos\Admin\JQAdm\Product\Characteristic\Property\Standard( $this->context, $templatePaths );
26
		$this->object->setView( $this->view );
27
	}
28
29
30
	protected function tearDown()
31
	{
32
		unset( $this->object );
33
	}
34
35
36
	public function testCreate()
37
	{
38
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
39
40
		$this->view->item = $manager->createItem();
41
		$result = $this->object->create();
42
43
		$this->assertContains( 'Properties', $result );
44
		$this->assertNull( $this->view->get( 'errors' ) );
45
	}
46
47
48
	public function testCopy()
49
	{
50
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
51
52
		$this->view->item = $manager->findItem( 'CNC' );
53
		$result = $this->object->copy();
54
55
		$this->assertNull( $this->view->get( 'errors' ) );
56
		$this->assertContains( 'Properties', $result );
57
	}
58
59
60
	public function testDelete()
61
	{
62
		$result = $this->object->delete();
63
64
		$this->assertNull( $this->view->get( 'errors' ) );
65
		$this->assertNull( $result );
66
	}
67
68
69
	public function testGet()
70
	{
71
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
72
73
		$this->view->item = $manager->findItem( 'CNC' );
74
		$result = $this->object->get();
75
76
		$this->assertNull( $this->view->get( 'errors' ) );
77
		$this->assertContains( 'Properties', $result );
78
	}
79
80
81
	public function testSave()
82
	{
83
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
84
		$propManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product/property' );
85
		$typeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product/property/type' );
86
87
		$item = $manager->findItem( 'CNC' );
88
		$item->setCode( 'jqadm-test-property' );
89
		$item->setId( null );
90
91
		$manager->saveItem( $item );
92
93
94
		$typeid = $typeManager->findItem( 'package-height', array(), 'product' )->getId();
95
96
		$param = array(
97
			'characteristic' => array(
98
				'property' => array(
99
					'product.property.id' => array( '' ),
100
					'product.property.typeid' => array( $typeid ),
101
					'product.property.value' => array( '10.0' ),
102
				),
103
			),
104
		);
105
106
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
107
		$this->view->addHelper( 'param', $helper );
108
		$this->view->item = $item;
109
110
		$result = $this->object->save();
111
112
		$search = $propManager->createSearch();
113
		$search->setConditions( $search->compare( '==', 'product.property.parentid', $item->getId() ) );
114
		$items = $propManager->searchItems( $search );
115
116
		$manager->deleteItem( $item->getId() );
117
118
		$this->assertNull( $this->view->get( 'errors' ) );
119
		$this->assertNull( $result );
120
		$this->assertEquals( 1, count( $items ) );
121
		$this->assertEquals( null, reset( $items )->getLanguageId() );
122
		$this->assertEquals( '10.0', reset( $items )->getValue() );
123
	}
124
125
126
	public function testSaveException()
127
	{
128
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Characteristic\Property\Standard' )
129
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
130
			->setMethods( array( 'updateItems' ) )
131
			->getMock();
132
133
		$object->expects( $this->once() )->method( 'updateItems' )
134
			->will( $this->throwException( new \Exception() ) );
135
136
		$object->setView( \TestHelperJqadm::getView() );
137
138
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
139
		$object->save();
140
	}
141
142
143
	public function testSaveMShopException()
144
	{
145
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Characteristic\Property\Standard' )
146
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
147
			->setMethods( array( 'updateItems' ) )
148
			->getMock();
149
150
		$object->expects( $this->once() )->method( 'updateItems' )
151
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
152
153
		$object->setView( \TestHelperJqadm::getView() );
154
155
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
156
		$object->save();
157
	}
158
159
160
	public function testSearch()
161
	{
162
		$this->assertNull( $this->object->search() );
163
	}
164
165
166
	public function testGetSubClient()
167
	{
168
		$this->setExpectedException( '\Aimeos\Admin\JQAdm\Exception' );
1 ignored issue
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
169
		$this->object->getSubClient( 'invalid' );
170
	}
171
}
172