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

StandardTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 8
dl 0
loc 150
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testCreate() 0 10 1
A testCopy() 0 11 1
A testDelete() 0 7 1
A testGet() 0 11 1
B testSave() 0 31 1
A setUp() 0 9 1
A testSaveException() 0 15 1
A testSaveMShopException() 0 15 1
A testSearch() 0 4 1
A testGetSubClient() 0 5 1
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\Bundle;
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\Bundle\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( 'Bundles', $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( 'U:BUNDLE', array( 'product' ) );
53
		$result = $this->object->copy();
54
55
		$this->assertNull( $this->view->get( 'errors' ) );
56
		$this->assertContains( 'Cafe Noire Cappuccino', $result );
57
		$this->assertContains( 'Cafe Noire Expresso', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertNull( $this->view->get( 'errors' ) );
66
		$this->assertNull( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
73
74
		$this->view->item = $manager->findItem( 'U:BUNDLE', array( 'product' ) );
75
		$result = $this->object->get();
76
77
		$this->assertNull( $this->view->get( 'errors' ) );
78
		$this->assertContains( 'Cafe Noire Cappuccino', $result );
79
		$this->assertContains( 'Cafe Noire Expresso', $result );
80
	}
81
82
83
	public function testSave()
84
	{
85
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
86
87
		$item = $manager->findItem( 'U:BUNDLE' );
88
		$item->setCode( 'jqadm-test-bundle' );
89
		$item->setId( null );
90
91
		$manager->saveItem( $item );
92
93
94
		$param = array(
95
			'bundle' => array(
96
				'product.lists.id' => array( '' ),
97
				'product.lists.refid' => array( $manager->findItem( 'CNE' )->getId() ),
98
			),
99
		);
100
101
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
102
		$this->view->addHelper( 'param', $helper );
103
		$this->view->item = $item;
104
105
		$result = $this->object->save();
106
107
		$item = $manager->getItem( $item->getId(), array( 'product' ) );
108
		$manager->deleteItem( $item->getId() );
109
110
		$this->assertNull( $this->view->get( 'errors' ) );
111
		$this->assertNull( $result );
112
		$this->assertEquals( 1, count( $item->getListItems( 'product' ) ) );
113
	}
114
115
116
	public function testSaveException()
117
	{
118
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Bundle\Standard' )
119
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
120
			->setMethods( array( 'updateItems' ) )
121
			->getMock();
122
123
		$object->expects( $this->once() )->method( 'updateItems' )
124
			->will( $this->throwException( new \Exception() ) );
125
126
		$object->setView( \TestHelperJqadm::getView() );
127
128
		$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...
129
		$object->save();
130
	}
131
132
133
	public function testSaveMShopException()
134
	{
135
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Bundle\Standard' )
136
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
137
			->setMethods( array( 'updateItems' ) )
138
			->getMock();
139
140
		$object->expects( $this->once() )->method( 'updateItems' )
141
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
142
143
		$object->setView( \TestHelperJqadm::getView() );
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
		$object->save();
147
	}
148
149
150
	public function testSearch()
151
	{
152
		$this->assertNull( $this->object->search() );
153
	}
154
155
156
	public function testGetSubClient()
157
	{
158
		$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...
159
		$this->object->getSubClient( 'invalid' );
160
	}
161
}
162