Skip to content

Commit

Permalink
20.1.6 MNB-3 Fix MatrixRate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wsajason committed May 5, 2020
1 parent 70ab8e3 commit b0e9ceb
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 67 deletions.
52 changes: 52 additions & 0 deletions CHANGELOG-PUBLIC.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning(http://semver.org/).

## 1.2.1
Fixed composer file

## 1.2.2
Removed version from composer so just uses tagged version on packagist

## 1.2.3
SHQ16-911 resolved shipping carrier validation in cart and checkout

## 1.2.4
M2-19 modified js validation

## 1.2.5
SHQ16-1346 make address fields not mandatory and include region for support for text field region

## 1.2.6
SHQ16-1335 updated docs links in readme and configuration header, SHQ16-1346 make address fields not mandatory and include region for support for text field region, M2-19 modified js validation

## 1.2.7
SHQ16-1617 remove csv from url params

## 20.0.6
M2-20 account for php configuration temp dir

## 20.0.7
M2-23 remove crontab file, not required

## 20.0.8
M2-20 account for upload when no upload_tmp_dir setting in php config

## 20.0.9
M2-23 remove crontab file, not required, M2-20 account for upload when no upload_tmp_dir setting in php config, Updated readme with latest M2 issues and updated support statement

## 20.1.0
M2-23 remove crontab file

## 20.2.3 (2019-05-09)
SHQ18-1978 Trim postcode and ensure condition value is not null


## 20.1.5 (2019-05-09)
SHQ18-1978 Trim postcode and ensure condition value is not null


## 20.1.6 (2020-05-05)
MNB-3 Fix MatrixRate unit tests


4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ SHQ18-1978 Trim postcode and ensure condition value is not null
SHQ18-1978 Trim postcode and ensure condition value is not null


## 20.1.6 (2020-05-05)
MNB-3 Fix MatrixRate unit tests


21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ShipperHQ and WebShopApps MatrixRate
A Shipping Rate module for Magento 2.x which supports showing multiple shipping methods. This is based on the Magento Tablerate module and is managed via a csv file.
A Shipping Rate module for Magento 2.3+ which supports showing multiple shipping methods. This is based on the Magento Tablerate module and is managed via a csv file.

Facts
-----
Expand All @@ -12,20 +12,16 @@ The MatrixRate shipping extension is the original Magento solution that enables

Compatibility
-------------
- Magento >= 2.0 (Includes 2.3)
- Magento >= 2.3

This library aims to support and is tested against the following PHP
implementations:

* PHP 5.5
* PHP 5.6
* PHP 5.7
* PHP 7.0
* PHP 7.1
* PHP 7.2
* PHP 7.3
* PHP 7.1.3
* PHP 7.2.0
* PHP 7.3.0

per the [official Magento 2 requirements](https://devdocs.magento.com/guides/v2.0/install-gde/system-requirements-tech.html)
per the [official Magento 2 requirements](https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements-tech.html)

Installation Instructions
-------------------------
Expand Down Expand Up @@ -79,8 +75,7 @@ Any contribution is highly appreciated. The best way to contribute code is to op

License
-------
Copyright (c) 2015 Zowta LLC & Zowta Ltd. See [LICENSE][] for
details.
Copyright (c) 2020 Zowta LLC & Zowta Ltd. See [LICENSE][] for details.

We also dutifully respect the [Magento][] OSL license, which is included in this codebase.

Expand All @@ -90,6 +85,6 @@ We also dutifully respect the [Magento][] OSL license, which is included in this

Copyright
---------
Copyright (c) 2015 Zowta LLC & Zowta Ltd.
Copyright (c) 2020 Zowta LLC & Zowta Ltd.


3 changes: 2 additions & 1 deletion Test/Unit/Block/Adminhtml/Carrier/Matrixrate/GridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
*/

namespace WebShopApps\MatrixRate\Test\Unit\Block\Adminhtml\Carrier\Matrixrate;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class GridTest extends \PHPUnit_Framework_TestCase
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \WebShopApps\MatrixRate\Block\Adminhtml\Carrier\Matrixrate\Grid
Expand Down
37 changes: 13 additions & 24 deletions Test/Unit/Block/Adminhtml/Form/Field/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,24 @@
* 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
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]);
$backendUrl = $this->createMock(\Magento\Backend\Model\UrlInterface::class);
$backendUrl->expects($this->once())->method('getUrl')->with("shqmatrixrate/system/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',
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->_object = $objectManager->getObject(
\WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Export::class,
['backendUrl' => $backendUrl]
);
}
Expand All @@ -62,23 +58,16 @@ 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);
$form = $this->createPartialMock(\Magento\Framework\Data\Form::class, ['getParent']);
$parentObjectMock = $this->createPartialMock(\Magento\Backend\Block\Template::class, ['getLayout']);
$layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);

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

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

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

$blockMock->expects($this->once())->method('getRequest')->will($this->returnValue($requestMock));
Expand Down
44 changes: 20 additions & 24 deletions Test/Unit/Block/Adminhtml/Form/Field/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,77 +33,73 @@
*/
namespace WebShopApps\MatrixRate\Test\Unit\Block\Adminhtml\Form\Field;

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

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

protected function setUp()
{
$this->_formMock = $this->getMock(
'Magento\Framework\Data\Form',
['getFieldNameSuffix', 'addSuffixToName'],
[],
'',
false,
false
$this->formMock = $this->createPartialMock(
\Magento\Framework\Data\Form::class,
['getFieldNameSuffix', 'addSuffixToName', 'getHtmlIdPrefix', 'getHtmlIdSuffix']
);
$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',
$this->object = $testHelper->getObject(
\WebShopApps\MatrixRate\Block\Adminhtml\Form\Field\Import::class,
['data' => $testData]
);
$this->_object->setForm($this->_formMock);
$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->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->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->formMock->expects(
$this->any()
)->method(
'getHtmlIdPrefix'
)->will(
$this->returnValue('test_name_prefix')
);
$this->_formMock->expects(
$this->formMock->expects(
$this->any()
)->method(
'getHtmlIdSuffix'
)->will(
$this->returnValue('test_name_suffix')
);
$testString = $this->_object->getElementHtml();
$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"/>',
'<input id="test_name_prefixtest_html_idtest_name_suffix" ' .
'name="test_name" data-ui-id="form-element-test_name" value="" type="file"/>',
$testString
);
}
Expand Down
11 changes: 7 additions & 4 deletions Test/Unit/Model/Config/Backend/MatrixrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
* See COPYING.txt for license details.
*/
namespace WebShopApps\MatrixRate\Test\Unit\Model\Config\Backend;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class MatrixrateTest extends \PHPUnit_Framework_TestCase
class MatrixrateTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \WebShopApps\MatrixRate\Model\Config\Backend\Matrixrate
Expand All @@ -59,9 +60,11 @@ protected function setUp()
->setMethods(['create'])
->getMock();

$this->model = $this->objectManagerHelper->getObject('\WebShopApps\MatrixRate\Model\Config\Backend\Matrixrate', [
'matrixrateFactory' => $this->tableateFactoryMock
]);
$this->model = $this->objectManagerHelper->getObject(
'\WebShopApps\MatrixRate\Model\Config\Backend\Matrixrate',
['matrixrateFactory' => $this->tableateFactoryMock
]
);
}

public function testAfterSave()
Expand Down
3 changes: 2 additions & 1 deletion Test/Unit/Model/Config/Source/MatrixrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
* See COPYING.txt for license details.
*/
namespace WebShopApps\MatrixRate\Test\Unit\Model\Config\Source;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class MatrixrateTest extends \PHPUnit_Framework_TestCase
class MatrixrateTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \WebShopApps\MatrixRate\Model\Config\Source\Matrixrate
Expand Down
Binary file removed ZIP/Matrixrates M2-20.1.5.zip
Binary file not shown.

0 comments on commit b0e9ceb

Please sign in to comment.