Skip to content

Commit 4fab755

Browse files
author
okarpenko
committed
MAGETWO-40041: Increase code coverage for South Team Modules
1 parent 2382298 commit 4fab755

File tree

4 files changed

+273
-0
lines changed

4 files changed

+273
-0
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+
}

0 commit comments

Comments
 (0)