Skip to content

Commit

Permalink
Merge pull request #463 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Code coverage
  • Loading branch information
vpelipenko committed Jul 14, 2015
2 parents c36b15c + 47cdb1c commit 06beed0
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;

class DeleteFilesTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
protected $controller;

/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/
protected $objectManager;

/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
protected $storage;

/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $request;

/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $response;

public function setUp()
{
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false);
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
$this->request = $this->getMockForAbstractClass(
'Magento\Framework\App\RequestInterface',
[],
'',
false,
false,
true,
['isPost', 'getParam']
);

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $helper->getObject(
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFiles',
[
'objectManager' => $this->objectManager,
'request' => $this->request,
'response' => $this->response,
]
);
}

public function testExecuteWithWrongRequest()
{
$this->request->expects($this->once())
->method('isPost')
->willReturn(false);

$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
$jsonData->expects($this->once())
->method('jsonEncode')
->with(['error' => true, 'message' => 'Wrong request'])
->willReturn('{"error":"true","message":"Wrong request"}');

$this->objectManager->expects($this->once())
->method('get')
->with('Magento\Framework\Json\Helper\Data')
->willReturn($jsonData);

$this->response->expects($this->once())
->method('representJson')
->with('{"error":"true","message":"Wrong request"}');

$this->controller->execute();
}

public function testExecute()
{
$this->request->expects($this->once())
->method('isPost')
->willReturn(true);
$this->request->expects($this->once())
->method('getParam')
->with('files')
->willReturn('{"files":"file"}');

$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
$jsonData->expects($this->once())
->method('jsonDecode')
->with('{"files":"file"}')
->willReturn(['files' => 'file']);
$this->objectManager->expects($this->at(0))
->method('get')
->with('Magento\Framework\Json\Helper\Data')
->willReturn($jsonData);
$this->objectManager->expects($this->at(1))
->method('get')
->with('Magento\Theme\Model\Wysiwyg\Storage')
->willReturn($this->storage);
$this->storage->expects($this->once())
->method('deleteFile')
->with('file');

$this->controller->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;

class DeleteFolderTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
protected $controller;

/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject*/
protected $objectManager;

/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $response;

/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
protected $storage;

/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
protected $storageHelper;

public function setUp()
{
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false);
$this->storage = $this->getMock('Magento\Theme\Model\Wysiwyg\Storage', [], [], '', false);
$this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false);

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $helper->getObject(
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\DeleteFolder',
[
'objectManager' => $this->objectManager,
'response' => $this->response,
'storage' => $this->storageHelper
]
);
}

public function testExecute()
{
$this->storageHelper->expects($this->once())
->method('getCurrentPath')
->willReturn('/current/path/');

$this->objectManager->expects($this->at(0))
->method('get')
->with('Magento\Theme\Model\Wysiwyg\Storage')
->willReturn($this->storage);
$this->storage->expects($this->once())
->method('deleteDirectory')
->with('/current/path/')
->willThrowException(new \Exception('Message'));

$jsonData = $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false);
$jsonData->expects($this->once())
->method('jsonEncode')
->with(['error' => true, 'message' => 'Message'])
->willReturn('{"error":"true","message":"Message"}');

$this->objectManager->expects($this->at(1))
->method('get')
->with('Magento\Framework\Json\Helper\Data')
->willReturn($jsonData);

$this->controller->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;

class IndexTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
protected $controller;

/** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $view;

public function setUp()
{
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false);

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $helper->getObject(
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\Index',
[
'view' => $this->view,
]
);
}

public function testExecute()
{
$this->view ->expects($this->once())
->method('loadLayout')
->with('overlay_popup');
$this->view ->expects($this->once())
->method('renderLayout');

$this->controller->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Theme\Test\Unit\Controller\Adminhtml\System\Design\Wysiwyg\Files;

class OnInsertTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files */
protected $controller;

/** @var \Magento\Framework\App\ViewInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $view;

/** @var \PHPUnit_Framework_MockObject_MockObject|\PHPUnit_Framework_MockObject_MockObject */
protected $objectManager;

/** @var \Magento\Theme\Helper\Storage|\PHPUnit_Framework_MockObject_MockObject */
protected $storageHelper;

/** @var \Magento\Framework\App\Response\Http|\PHPUnit_Framework_MockObject_MockObject */
protected $response;

public function setUp()
{
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
$this->view = $this->getMock('\Magento\Framework\App\ViewInterface', [], [], '', false);
$this->storageHelper = $this->getMock('Magento\Theme\Helper\Storage', [], [], '', false);
$this->response = $this->getMock('Magento\Framework\App\Response\Http', ['setBody'], [], '', false);

$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->controller = $helper->getObject(
'Magento\Theme\Controller\Adminhtml\System\Design\Wysiwyg\Files\OnInsert',
[
'objectManager' => $this->objectManager,
'view' => $this->view,
'response' => $this->response
]
);
}

public function testExecute()
{
$this->objectManager->expects($this->once())
->method('get')
->with('Magento\Theme\Helper\Storage')
->willReturn($this->storageHelper);
$this->storageHelper
->expects($this->once())
->method('getRelativeUrl')
->willReturn('http://relative.url/');
$this->response->expects($this->once())
->method('setBody')
->with('http://relative.url/');

$this->controller->execute();
}
}
63 changes: 61 additions & 2 deletions app/code/Magento/Wishlist/Test/Unit/Model/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testRemoveOptionByCode($code, $option)
$this->model->addOption($option);
$this->assertEquals(1, count($this->model->getOptions()));
$this->model->removeOption($code);
$actualOptions = $this->model->getOptions();
$actualOptions = $this->model->getOptions();
$actualOption = array_pop($actualOptions);
$this->assertTrue($actualOption->isDeleted());
}
Expand All @@ -185,7 +185,7 @@ public function getOptionsDataProvider()
->getMock();
return [
['first_key', ['code' => 'first_key', 'value' => 'first_data']],
['second_key',$optionMock],
['second_key', $optionMock],
['third_key', new \Magento\Framework\Object(['code' => 'third_key', 'product' => $productMock])],
];
}
Expand Down Expand Up @@ -262,4 +262,63 @@ public function testCompareOptionsNegativeOptionsTwoHaveNotOption()

$this->assertFalse($result);
}

public function testSetAndSaveItemOptions()
{
$this->assertEmpty($this->model->getOptions());
$firstOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
->disableOriginalConstructor()
->setMethods(['getCode', 'isDeleted', 'delete', '__wakeup'])
->getMock();
$firstOptionMock->expects($this->any())
->method('getCode')
->willReturn('first_code');
$firstOptionMock->expects($this->any())
->method('isDeleted')
->willReturn(true);
$firstOptionMock->expects($this->once())
->method('delete');

$secondOptionMock = $this->getMockBuilder('Magento\Wishlist\Model\Item\Option')
->disableOriginalConstructor()
->setMethods(['getCode', 'save', '__wakeup'])
->getMock();
$secondOptionMock->expects($this->any())
->method('getCode')
->willReturn('second_code');
$secondOptionMock->expects($this->once())
->method('save');

$this->model->setOptions([$firstOptionMock, $secondOptionMock]);
$this->assertNull($this->model->isOptionsSaved());
$this->model->saveItemOptions();
$this->assertTrue($this->model->isOptionsSaved());
}

public function testGetProductWithException()
{
$this->setExpectedException('Magento\Framework\Exception\LocalizedException', __('Cannot specify product.'));
$this->model->getProduct();
}

public function testGetProduct()
{
$productId = 1;
$storeId = 0;
$this->model->setData('product_id', $productId);
$this->model->setData('store_id', $storeId);
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();
$productMock->expects($this->any())
->method('setFinalPrice')
->with(null);
$productMock->expects($this->any())
->method('setCustomOprtions')
->with([]);
$this->productRepository->expects($this->once())
->method('getById')
->willReturn($productMock);
$this->assertEquals($productMock, $this->model->getProduct());
}
}

0 comments on commit 06beed0

Please sign in to comment.