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

StandardTest::testGetSubClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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\Attribute;
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\Attribute\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( 'Attributes', $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', array( 'attribute' ) );
53
		$result = $this->object->copy();
54
55
		$this->assertNull( $this->view->get( 'errors' ) );
56
		$this->assertContains( 'xs', $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', array( 'attribute' ) );
74
		$result = $this->object->get();
75
76
		$this->assertNull( $this->view->get( 'errors' ) );
77
		$this->assertContains( 'xs', $result );
78
	}
79
80
81
	public function testSave()
82
	{
83
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
84
		$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' );
85
86
		$item = $manager->findItem( 'CNC' );
87
		$item->setCode( 'jqadm-test-attribute' );
88
		$item->setId( null );
89
90
		$manager->saveItem( $item );
91
92
93
		$param = array(
94
			'characteristic' => array(
95
				'attribute' => array(
96
					'product.lists.id' => array( '' ),
97
					'product.lists.refid' => array( $attrManager->findItem( 'xs', array(), 'product', 'size' )->getId() ),
98
				),
99
			),
100
		);
101
102
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
103
		$this->view->addHelper( 'param', $helper );
104
		$this->view->item = $item;
105
106
		$result = $this->object->save();
107
108
		$item = $manager->getItem( $item->getId(), array( 'attribute' ) );
109
		$manager->deleteItem( $item->getId() );
110
111
		$this->assertNull( $this->view->get( 'errors' ) );
112
		$this->assertNull( $result );
113
		$this->assertEquals( 1, count( $item->getListItems( 'attribute' ) ) );
114
	}
115
116
117
	public function testSaveException()
118
	{
119
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Characteristic\Attribute\Standard' )
120
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
121
			->setMethods( array( 'updateItems' ) )
122
			->getMock();
123
124
		$object->expects( $this->once() )->method( 'updateItems' )
125
			->will( $this->throwException( new \Exception() ) );
126
127
		$object->setView( \TestHelperJqadm::getView() );
128
129
		$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...
130
		$object->save();
131
	}
132
133
134
	public function testSaveMShopException()
135
	{
136
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Characteristic\Attribute\Standard' )
137
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
138
			->setMethods( array( 'updateItems' ) )
139
			->getMock();
140
141
		$object->expects( $this->once() )->method( 'updateItems' )
142
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
143
144
		$object->setView( \TestHelperJqadm::getView() );
145
146
		$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...
147
		$object->save();
148
	}
149
150
151
	public function testSearch()
152
	{
153
		$this->assertNull( $this->object->search() );
154
	}
155
156
157
	public function testGetSubClient()
158
	{
159
		$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...
160
		$this->object->getSubClient( 'invalid' );
161
	}
162
}
163