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), 2015
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Physical;
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\Physical\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( 'Physical', $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( 'value="20.0"', $result );
57
		$this->assertContains( 'value="15.0"', $result );
58
		$this->assertContains( 'value="10.0"', $result );
59
		$this->assertContains( 'value="1.25"', $result );
60
	}
61
62
63
	public function testGet()
64
	{
65
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
66
67
		$this->view->item = $manager->findItem( 'CNC' );
68
		$result = $this->object->get();
69
70
		$this->assertNull( $this->view->get( 'errors' ) );
71
		$this->assertContains( 'value="20.0"', $result );
72
		$this->assertContains( 'value="15.0"', $result );
73
		$this->assertContains( 'value="10.0"', $result );
74
		$this->assertContains( 'value="1.25"', $result );
75
	}
76
77
78
	public function testSave()
79
	{
80
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
81
82
		$item = $manager->findItem( 'CNC' );
83
		$item->setCode( 'jqadm-test-physical' );
84
		$item->setId( null );
85
86
		$manager->saveItem( $item );
87
88
89
		$param = array(
90
			'physical' => array(
91
				'package-length' => '10.00',
92
				'package-weight' => '5.25',
93
			),
94
		);
95
96
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
97
		$this->view->addHelper( 'param', $helper );
98
		$this->view->item = $item;
99
100
		$result = $this->object->save();
101
102
		$manager->deleteItem( $item->getId() );
103
104
		$this->assertNull( $this->view->get( 'errors' ) );
105
		$this->assertNull( $result );
106
	}
107
108
109
	public function testSaveException()
110
	{
111
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Physical\Standard' )
112
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
113
			->setMethods( array( 'updateItems' ) )
114
			->getMock();
115
116
		$object->expects( $this->once() )->method( 'updateItems' )
117
			->will( $this->throwException( new \Exception() ) );
118
119
		$object->setView( \TestHelperJqadm::getView() );
120
121
		$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...
122
		$object->save();
123
	}
124
125
126
	public function testSaveMShopException()
127
	{
128
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Physical\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 \Aimeos\MShop\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 testGetSubClient()
144
	{
145
		$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...
146
		$this->object->getSubClient( 'invalid' );
147
	}
148
}
149