Skip to content

Commit 06beed0

Browse files
committed
Merge pull request #463 from magento-south/BUGS
[South] Code coverage
2 parents c36b15c + 47cdb1c commit 06beed0

File tree

5 files changed

+334
-2
lines changed

5 files changed

+334
-2
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;
7+
8+
class DeleteFilesTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
11+
protected $controller;
12+
13+
/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/
14+
protected $objectManager;
15+
16+
/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
17+
protected $storage;
18+
19+
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $request;
21+
22+
/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $response;
24+
25+
public function setUp()
26+
{
27+
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
28+
$this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false);
29+
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
30+
$this->request = $this->getMockForAbstractClass(
31+
'Magento\Framework\App\RequestInterface',
32+
[],
33+
'',
34+
false,
35+
false,
36+
true,
37+
['isPost', 'getParam']
38+
);
39+
40+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
41+
$this->controller = $helper->getObject(
42+
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFiles',
43+
[
44+
'objectManager' => $this->objectManager,
45+
'request' => $this->request,
46+
'response' => $this->response,
47+
]
48+
);
49+
}
50+
51+
public function testExecuteWithWrongRequest()
52+
{
53+
$this->request->expects($this->once())
54+
->method('isPost')
55+
->willReturn(false);
56+
57+
$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
58+
$jsonData->expects($this->once())
59+
->method('jsonEncode')
60+
->with(['error' => true, 'message' => 'Wrong request'])
61+
->willReturn('{"error":"true","message":"Wrong request"}');
62+
63+
$this->objectManager->expects($this->once())
64+
->method('get')
65+
->with('Magento\Framework\Json\Helper\Data')
66+
->willReturn($jsonData);
67+
68+
$this->response->expects($this->once())
69+
->method('representJson')
70+
->with('{"error":"true","message":"Wrong request"}');
71+
72+
$this->controller->execute();
73+
}
74+
75+
public function testExecute()
76+
{
77+
$this->request->expects($this->once())
78+
->method('isPost')
79+
->willReturn(true);
80+
$this->request->expects($this->once())
81+
->method('getParam')
82+
->with('files')
83+
->willReturn('{"files":"file"}');
84+
85+
$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
86+
$jsonData->expects($this->once())
87+
->method('jsonDecode')
88+
->with('{"files":"file"}')
89+
->willReturn(['files' => 'file']);
90+
$this->objectManager->expects($this->at(0))
91+
->method('get')
92+
->with('Magento\Framework\Json\Helper\Data')
93+
->willReturn($jsonData);
94+
$this->objectManager->expects($this->at(1))
95+
->method('get')
96+
->with('Magento\Theme\Model\Wysiwyg\Storage')
97+
->willReturn($this->storage);
98+
$this->storage->expects($this->once())
99+
->method('deleteFile')
100+
->with('file');
101+
102+
$this->controller->execute();
103+
}
104+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;
7+
8+
class DeleteFolderTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
11+
protected $controller;
12+
13+
/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/
14+
protected $objectManager;
15+
16+
/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
17+
protected $response;
18+
19+
/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $storage;
21+
22+
/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $storageHelper;
24+
25+
public function setUp()
26+
{
27+
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
28+
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
29+
$this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false);
30+
$this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false);
31+
32+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33+
$this->controller = $helper->getObject(
34+
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFolder',
35+
[
36+
'objectManager' => $this->objectManager,
37+
'response' => $this->response,
38+
'storage' => $this->storageHelper
39+
]
40+
);
41+
}
42+
43+
public function testExecute()
44+
{
45+
$this->storageHelper->expects($this->once())
46+
->method('getCurrentPath')
47+
->willReturn('/current/path/');
48+
49+
$this->objectManager->expects($this->at(0))
50+
->method('get')
51+
->with('Magento\Theme\Model\Wysiwyg\Storage')
52+
->willReturn($this->storage);
53+
$this->storage->expects($this->once())
54+
->method('deleteDirectory')
55+
->with('/current/path/')
56+
->willThrowException(new \Exception('Message'));
57+
58+
$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
59+
$jsonData->expects($this->once())
60+
->method('jsonEncode')
61+
->with(['error' => true, 'message' => 'Message'])
62+
->willReturn('{"error":"true","message":"Message"}');
63+
64+
$this->objectManager->expects($this->at(1))
65+
->method('get')
66+
->with('Magento\Framework\Json\Helper\Data')
67+
->willReturn($jsonData);
68+
69+
$this->controller->execute();
70+
}
71+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;
7+
8+
class IndexTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
11+
protected $controller;
12+
13+
/** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
14+
protected $view;
15+
16+
public function setUp()
17+
{
18+
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false);
19+
20+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
21+
$this->controller = $helper->getObject(
22+
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\Index',
23+
[
24+
'view' => $this->view,
25+
]
26+
);
27+
}
28+
29+
public function testExecute()
30+
{
31+
$this->view ->expects($this->once())
32+
->method('loadLayout')
33+
->with('overlay_popup');
34+
$this->view ->expects($this->once())
35+
->method('renderLayout');
36+
37+
$this->controller->execute();
38+
}
39+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;
7+
8+
class OnInsertTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
11+
protected $controller;
12+
13+
/** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
14+
protected $view;
15+
16+
/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject */
17+
protected $objectManager;
18+
19+
/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $storageHelper;
21+
22+
/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $response;
24+
25+
public function setUp()
26+
{
27+
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
28+
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false);
29+
$this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false);
30+
$this->response = $this->getMock('Magento\Framework\App\Response\Http', ['setBody'], [], '', false);
31+
32+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33+
$this->controller = $helper->getObject(
34+
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\OnInsert',
35+
[
36+
'objectManager' => $this->objectManager,
37+
'view' => $this->view,
38+
'response' => $this->response
39+
]
40+
);
41+
}
42+
43+
public function testExecute()
44+
{
45+
$this->objectManager->expects($this->once())
46+
->method('get')
47+
->with('Magento\Theme\Helper\Storage')
48+
->willReturn($this->storageHelper);
49+
$this->storageHelper
50+
->expects($this->once())
51+
->method('getRelativeUrl')
52+
->willReturn('http://relative.url/');
53+
$this->response->expects($this->once())
54+
->method('setBody')
55+
->with('http://relative.url/');
56+
57+
$this->controller->execute();
58+
}
59+
}

app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testRemoveOptionByCode($code, $option)
165165
$this->model->addOption($option);
166166
$this->assertEquals(1, count($this->model->getOptions()));
167167
$this->model->removeOption($code);
168-
$actualOptions = $this->model->getOptions();
168+
$actualOptions = $this->model->getOptions();
169169
$actualOption = array_pop($actualOptions);
170170
$this->assertTrue($actualOption->isDeleted());
171171
}
@@ -185,7 +185,7 @@ public function getOptionsDataProvider()
185185
->getMock();
186186
return [
187187
['first_key', ['code' => 'first_key', 'value' => 'first_data']],
188-
['second_key',$optionMock],
188+
['second_key', $optionMock],
189189
['third_key', new \Magento\Framework\Object(['code' => 'third_key', 'product' => $productMock])],
190190
];
191191
}
@@ -262,4 +262,63 @@ public function testCompareOptionsNegativeOptionsTwoHaveNotOption()
262262

263263
$this->assertFalse($result);
264264
}
265+
266+
public function testSetAndSaveItemOptions()
267+
{
268+
$this->assertEmpty($this->model->getOptions());
269+
$firstOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
270+
->disableOriginalConstructor()
271+
->setMethods(['getCode', 'isDeleted', 'delete', '__wakeup'])
272+
->getMock();
273+
$firstOptionMock->expects($this->any())
274+
->method('getCode')
275+
->willReturn('first_code');
276+
$firstOptionMock->expects($this->any())
277+
->method('isDeleted')
278+
->willReturn(true);
279+
$firstOptionMock->expects($this->once())
280+
->method('delete');
281+
282+
$secondOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
283+
->disableOriginalConstructor()
284+
->setMethods(['getCode', 'save', '__wakeup'])
285+
->getMock();
286+
$secondOptionMock->expects($this->any())
287+
->method('getCode')
288+
->willReturn('second_code');
289+
$secondOptionMock->expects($this->once())
290+
->method('save');
291+
292+
$this->model->setOptions([$firstOptionMock, $secondOptionMock]);
293+
$this->assertNull($this->model->isOptionsSaved());
294+
$this->model->saveItemOptions();
295+
$this->assertTrue($this->model->isOptionsSaved());
296+
}
297+
298+
public function testGetProductWithException()
299+
{
300+
$this->setExpectedException('Magento\Framework\Exception\LocalizedException', __('Cannot specify product.'));
301+
$this->model->getProduct();
302+
}
303+
304+
public function testGetProduct()
305+
{
306+
$productId = 1;
307+
$storeId = 0;
308+
$this->model->setData('product_id', $productId);
309+
$this->model->setData('store_id', $storeId);
310+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
311+
->disableOriginalConstructor()
312+
->getMock();
313+
$productMock->expects($this->any())
314+
->method('setFinalPrice')
315+
->with(null);
316+
$productMock->expects($this->any())
317+
->method('setCustomOprtions')
318+
->with([]);
319+
$this->productRepository->expects($this->once())
320+
->method('getById')
321+
->willReturn($productMock);
322+
$this->assertEquals($productMock, $this->model->getProduct());
323+
}
265324
}

0 commit comments

Comments
 (0)