Skip to content

Commit

Permalink
added changelog & test dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Karen Baker committed May 3, 2016
1 parent 85a20ed commit 8dc68fc
Show file tree
Hide file tree
Showing 6 changed files with 540 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [20.0.1] - 2016-04-25
### Added
- Fixed composer file


## [20.0.2] - 2016-05-02
### Added
- Removed version from composer so uses tagged version
160 changes: 160 additions & 0 deletions test/Unit/Block/Adminhtml/Carrier/Matrixrate/GridTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
/**
* WebShopApps
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* WebShopApps MatrixRate
*
* @category WebShopApps
* @package WebShopApps_MatrixRate
* @copyright Copyright (c) 2014 Zowta LLC (http://www.WebShopApps.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author WebShopApps Team [email protected]
*
*/
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace WebShopApps\MatrixRate\Test\Unit\Block\Adminhtml\Carrier\Matrixrate;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class GridTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \WebShopApps\MatrixRate\Block\Adminhtml\Carrier\Matrixrate\Grid
*/
protected $model;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManagerMock;

/**
* @var \Magento\Backend\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
*/
protected $backendHelperMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $matrixrateMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $context;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $collectionFactoryMock;

/** @var ObjectManagerHelper */
protected $objectManagerHelper;

protected function setUp()
{
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')
->disableOriginalConstructor()
->getMock();

$this->context = $this->objectManagerHelper->getObject('Magento\Backend\Block\Template\Context', [
'storeManager' => $this->storeManagerMock
]);

$this->backendHelperMock = $this->getMockBuilder('\Magento\Backend\Helper\Data')
->disableOriginalConstructor()
->getMock();

$this->collectionFactoryMock =
$this->getMockBuilder('\WebShopApps\MatrixRate\Model\ResourceModel\Carrier\Matrixrate\CollectionFactory')
->disableOriginalConstructor()
->getMock();

$this->matrixrateMock = $this->getMockBuilder('WebShopApps\MatrixRate\Model\Carrier\Matrixrate')
->disableOriginalConstructor()
->getMock();

$this->model = new \WebShopApps\MatrixRate\Block\Adminhtml\Carrier\Matrixrate\Grid(
$this->context,
$this->backendHelperMock,
$this->collectionFactoryMock,
$this->matrixrateMock
);
}

public function testSetWebsiteId()
{
$websiteId = 1;

$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
->setMethods(['getId'])
->disableOriginalConstructor()
->getMock();

$this->storeManagerMock->expects($this->once())
->method('getWebsite')
->with($websiteId)
->willReturn($websiteMock);

$websiteMock->expects($this->once())
->method('getId')
->willReturn($websiteId);

$this->assertSame($this->model, $this->model->setWebsiteId($websiteId));
$this->assertEquals($websiteId, $this->model->getWebsiteId());
}

public function testGetWebsiteId()
{
$websiteId = 10;

$websiteMock = $this->getMockBuilder('Magento\Store\Model\Website')
->disableOriginalConstructor()
->setMethods(['getId'])
->getMock();

$websiteMock->expects($this->once())
->method('getId')
->willReturn($websiteId);

$this->storeManagerMock->expects($this->once())
->method('getWebsite')
->willReturn($websiteMock);

$this->assertEquals($websiteId, $this->model->getWebsiteId());

$this->storeManagerMock->expects($this->never())
->method('getWebsite')
->willReturn($websiteMock);

$this->assertEquals($websiteId, $this->model->getWebsiteId());
}

public function testSetAndGetConditionName()
{
$conditionName = 'someName';
$this->assertEquals($this->model, $this->model->setConditionName($conditionName));
$this->assertEquals($conditionName, $this->model->getConditionName());
}
}
94 changes: 94 additions & 0 deletions test/Unit/Block/Adminhtml/Form/Field/ExportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* WebShopApps
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* WebShopApps MatrixRate
*
* @category WebShopApps
* @package WebShopApps_MatrixRate
* @copyright Copyright (c) 2014 Zowta LLC (http://www.WebShopApps.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author WebShopApps Team [email protected]
*
*/
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace WebShopApps\MatrixRate\Test\Unit\Block\Adminhtml\Form\Field;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class ExportTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Export
*/
protected $_object;

/** @var ObjectManagerHelper */
protected $objectManagerHelper;

protected function setUp()
{
$backendUrl = $this->getMock('Magento\Backend\Model\UrlInterface', [], [], '', false, false);
$backendUrl->expects($this->once())->method('getUrl')->with("*/*/exportMatrixrates", ['website' => 1]);

// $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->objectManagerHelper = new ObjectManagerHelper($this);

$this->_object = $this->objectManagerHelper->getObject(
'WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Export',
['backendUrl' => $backendUrl]
);
}

public function testGetElementHtml()
{
$expected = 'some test data';

$form = $this->getMock('Magento\Framework\Data\Form', ['getParent'], [], '', false, false);
$parentObjectMock = $this->getMock(
'Magento\Backend\Block\Template',
['getLayout'],
[],
'',
false,
false
);
$layoutMock = $this->getMock('Magento\Framework\View\Layout', [], [], '', false, false);

$blockMock = $this->getMock('Magento\Backend\Block\Widget\Button', [], [], '', false, false);

$requestMock = $this->getMock('Magento\Framework\App\RequestInterface', [], [], '', false, false);
$requestMock->expects($this->once())->method('getParam')->with('website')->will($this->returnValue(1));

$mockData = $this->getMock('StdClass', ['toHtml']);
$mockData->expects($this->once())->method('toHtml')->will($this->returnValue($expected));

$blockMock->expects($this->once())->method('getRequest')->will($this->returnValue($requestMock));
$blockMock->expects($this->any())->method('setData')->will($this->returnValue($mockData));

$layoutMock->expects($this->once())->method('createBlock')->will($this->returnValue($blockMock));
$parentObjectMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
$form->expects($this->once())->method('getParent')->will($this->returnValue($parentObjectMock));

$this->_object->setForm($form);
$this->assertEquals($expected, $this->_object->getElementHtml());
}
}
110 changes: 110 additions & 0 deletions test/Unit/Block/Adminhtml/Form/Field/ImportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* WebShopApps
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* WebShopApps MatrixRate
*
* @category WebShopApps
* @package WebShopApps_MatrixRate
* @copyright Copyright (c) 2014 Zowta LLC (http://www.WebShopApps.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author WebShopApps Team [email protected]
*
*/
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace WebShopApps\MatrixRate\Test\Unit\Block\Adminhtml\Form\Field;

class ImportTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Import
*/
protected $_object;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $_formMock;

protected function setUp()
{
$this->_formMock = $this->getMock(
'Magento\Framework\Data\Form',
['getFieldNameSuffix', 'addSuffixToName'],
[],
'',
false,
false
);
$testData = ['name' => 'test_name', 'html_id' => 'test_html_id'];
$testHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_object = $testHelper->getObject(
'WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Import',
['data' => $testData]
);
$this->_object->setForm($this->_formMock);
}

public function testGetNameWhenFormFiledNameSuffixIsEmpty()
{
$this->_formMock->expects($this->once())->method('getFieldNameSuffix')->will($this->returnValue(false));
$this->_formMock->expects($this->never())->method('addSuffixToName');
$actual = $this->_object->getName();
$this->assertEquals('test_name', $actual);
}

public function testGetNameWhenFormFiledNameSuffixIsNotEmpty()
{
$this->_formMock->expects($this->once())->method('getFieldNameSuffix')->will($this->returnValue(true));
$this->_formMock->expects($this->once())->method('addSuffixToName')->will($this->returnValue('test_suffix'));
$actual = $this->_object->getName();
$this->assertEquals('test_suffix', $actual);
}

public function testGetElementHtml()
{
$this->_formMock->expects(
$this->any()
)->method(
'getHtmlIdPrefix'
)->will(
$this->returnValue('test_name_prefix')
);
$this->_formMock->expects(
$this->any()
)->method(
'getHtmlIdSuffix'
)->will(
$this->returnValue('test_name_suffix')
);
$testString = $this->_object->getElementHtml();
$this->assertStringStartsWith(
'<input id="time_condition" type="hidden" name="test_name" value="',
$testString
);
$this->assertStringEndsWith(
'<input id="test_html_id" name="test_name" data-ui-id="form-element-test_name"' .
' value="" type="file"/>',
$testString
);
}
}
Loading

0 comments on commit 8dc68fc

Please sign in to comment.