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

StandardTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 182
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 182
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 16 1
A tearDown() 0 4 1
A testCreate() 0 10 1
A testCopy() 0 10 1
A testDelete() 0 7 1
A testGet() 0 10 1
A testSave() 0 58 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), 2016
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Product\Download;
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
		$request = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.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...
23
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
24
		$this->view ->addHelper( 'request', $helper );
25
26
		$this->context = \TestHelperJqadm::getContext();
27
		$templatePaths = \TestHelperJqadm::getTemplatePaths();
28
29
		$this->object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Download\Standard' )
30
			->setConstructorArgs( array( $this->context, $templatePaths ) )
31
			->setMethods( array( 'storeFile' ) )
32
			->getMock();
33
		$this->object->setView( $this->view );
34
	}
35
36
37
	protected function tearDown()
38
	{
39
		unset( $this->object );
40
	}
41
42
43
	public function testCreate()
44
	{
45
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
46
47
		$this->view->item = $manager->createItem();
48
		$result = $this->object->create();
49
50
		$this->assertContains( 'Download', $result );
51
		$this->assertNull( $this->view->get( 'errors' ) );
52
	}
53
54
55
	public function testCopy()
56
	{
57
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
58
59
		$this->view->item = $manager->findItem( 'CNE', array( 'attribute' ) );
60
		$result = $this->object->copy();
61
62
		$this->assertNull( $this->view->get( 'errors' ) );
63
		$this->assertContains( 'Test URL', $result );
64
	}
65
66
67
	public function testDelete()
68
	{
69
		$result = $this->object->delete();
70
71
		$this->assertNull( $this->view->get( 'errors' ) );
72
		$this->assertNull( $result );
73
	}
74
75
76
	public function testGet()
77
	{
78
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
79
80
		$this->view->item = $manager->findItem( 'CNE', array( 'attribute' ) );
81
		$result = $this->object->get();
82
83
		$this->assertNull( $this->view->get( 'errors' ) );
84
		$this->assertContains( 'Test URL', $result );
85
	}
86
87
88
	public function testSave()
89
	{
90
		$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' );
91
92
		$item = $manager->findItem( 'CNE' );
93
		$item->setCode( 'jqadm-test-download' );
94
		$item->setId( null );
95
96
		$manager->saveItem( $item );
97
98
99
		$param = array(
100
			'download' => array(
101
				'product.lists.id' => '',
102
				'product.lists.status' => '1',
103
				'attribute.label' => 'test',
104
			),
105
		);
106
107
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
108
		$this->view->addHelper( 'param', $helper );
109
110
		$file = $this->getMock( '\Psr\Http\Message\UploadedFileInterface' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.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...
111
		$file->expects( $this->any() )->method( 'getError' )->will( $this->returnValue( UPLOAD_ERR_OK ) );
112
113
		$request = $this->getMock( '\Psr\Http\Message\ServerRequestInterface' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.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...
114
		$request->expects( $this->any() )->method( 'getUploadedFiles' )
115
			->will( $this->returnValue( array( 'download' => array( 'file' => $file ) ) ) );
116
117
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request );
118
		$this->view->addHelper( 'request', $helper );
119
120
		$this->view->item = $item;
121
122
123
		$this->object->expects( $this->once() )->method( 'storeFile' )
124
			->will( $this->returnValue( 'test/file.ext' ) );
125
126
		$attributeStub = $this->getMockBuilder( '\\Aimeos\\MShop\\Attribute\\Manager\\Standard' )
127
			->setConstructorArgs( array( $this->context ) )
128
			->setMethods( array( 'saveItem' ) )
129
			->getMock();
130
		$attributeStub->expects( $this->once() )->method( 'saveItem' );
131
		\Aimeos\MShop\Factory::injectManager( $this->context, 'attribute', $attributeStub );
132
133
134
		\Aimeos\MShop\Factory::setCache( true );
135
		$result = $this->object->save();
136
		\Aimeos\MShop\Factory::setCache( false );
137
138
139
		$item = $manager->getItem( $item->getId(), array( 'attribute' ) );
140
		$manager->deleteItem( $item->getId() );
141
142
		$this->assertNull( $this->view->get( 'errors' ) );
143
		$this->assertNull( $result );
144
		$this->assertEquals( 1, count( $item->getListItems( 'attribute', 'hidden' ) ) );
145
	}
146
147
148
	public function testSaveException()
149
	{
150
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Download\Standard' )
151
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
152
			->setMethods( array( 'updateItems' ) )
153
			->getMock();
154
155
		$object->expects( $this->once() )->method( 'updateItems' )
156
			->will( $this->throwException( new \Exception() ) );
157
158
		$object->setView( \TestHelperJqadm::getView() );
159
160
		$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...
161
		$object->save();
162
	}
163
164
165
	public function testSaveMShopException()
166
	{
167
		$object = $this->getMockBuilder( '\Aimeos\Admin\JQAdm\Product\Download\Standard' )
168
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
169
			->setMethods( array( 'updateItems' ) )
170
			->getMock();
171
172
		$object->expects( $this->once() )->method( 'updateItems' )
173
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
174
175
		$object->setView( \TestHelperJqadm::getView() );
176
177
		$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...
178
		$object->save();
179
	}
180
181
182
	public function testSearch()
183
	{
184
		$this->assertNull( $this->object->search() );
185
	}
186
187
188
	public function testGetSubClient()
189
	{
190
		$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...
191
		$this->object->getSubClient( 'invalid' );
192
	}
193
}
194