Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
#34: Add new unit tests and remove unused tests
Browse files Browse the repository at this point in the history
Adds new unit tests to test a few new areas of the code and removes unit tests that tested the previous logic. Some of these tests are already run on the royal mail library, and have been moved there.
  • Loading branch information
Aaron Rickard committed Dec 22, 2015
1 parent c8cb7c2 commit 1bfdcb2
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 335 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2643,4 +2643,6 @@ composer.lock
/var/package/Mage_Ogone_Official-1.14.2.2.xml
/var/package/Magento_Mobile-1.14.2.2.xml
/var/package/Phoenix_Moneybookers-1.14.2.2.xml
/var/session
/var/session
/var/cache
/var/phpunit.cache
40 changes: 20 additions & 20 deletions app/code/community/Meanbee/Royalmail/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ public function _setWeight($data)
$this->_weight = $data;
}

protected function _setCartTotal($value)
{
$this->_cart_total = $value;
}

public function getCartTotal()
{
return $this->_cart_total;
}

public function setNegativeWeight($value)
{
$this->_negative_weight = $value;
}

public function getNegativeWeight()
{
return $this->_negative_weight;
}

// Return the weight in grammes
public function _getWeight()
{
Expand All @@ -85,24 +105,4 @@ public function _getWeight()

return $weight;
}

protected function _setCartTotal($value)
{
$this->_cart_total = $value;
}

public function getCartTotal()
{
return $this->_cart_total;
}

public function setNegativeWeight($value)
{
$this->_negative_weight = $value;
}

public function getNegativeWeight()
{
return $this->_negative_weight;
}
}
2 changes: 1 addition & 1 deletion app/code/community/Meanbee/Royalmail/Test/Config/Base.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class Meanbee_Royalmail_Test_Config_Base extends EcomDev_PHPUnit_Test_Case_Config {
class Meanbee_Royalmail_Test_Config_Base extends EcomDev_PHPUnit_Test_Case_Config{
public function testValidCodepool() {
$this->assertModuleCodePool('community');
}
Expand Down
42 changes: 39 additions & 3 deletions app/code/community/Meanbee/Royalmail/Test/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
<?php

class Meanbee_Royalmail_Test_Helper_Data extends EcomDev_PHPUnit_Test_Case {
class Meanbee_Royalmail_Test_Helper_Data extends EcomDev_PHPUnit_Test_Case
{

private $_dataHelper;

public function setUp()
{
$this->_dataHelper = Mage::helper('royalmail');
}

public function tearDown()
{
$this->_dataHelper = null;
}

/**
* @test
*/
public function testGetWeightKg()
{
$this->_dataHelper->setWeightUnit('kg');
$this->_dataHelper->_setWeight(0.02);
$this->assertEquals(20.0, Mage::helper('royalmail')->_getWeight());
}

/**
* @test
*/
public function testGetWeightG()
{
$this->_dataHelper->setWeightUnit('g');
$this->_dataHelper->_setWeight(0.02);
$this->assertEquals(0.02, Mage::helper('royalmail')->_getWeight());
}

/**
* @test
*/
public function testGetCountryWorldZone() {
$this->assertEquals('wz2', Mage::helper('royalmail')->getWorldZone('TO'));
public function testGetWeightlb()
{
$this->_dataHelper->setWeightUnit('lb');
$this->_dataHelper->_setWeight(0.02);
$this->assertEquals(9.0718474000000011, Mage::helper('royalmail')->_getWeight());
}
}
13 changes: 13 additions & 0 deletions app/code/community/Meanbee/Royalmail/Test/Model/Parcelsize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class Meanbee_Royalmail_Test_Model_Parcelsize extends Meanbee_Royalmail_Test_Util_Sourcemodel {
/** @var Meanbee_Royalmail_Model_Parcelsize */
protected $_model = null;

public function setUp() {
$this->_model = Mage::getModel('royalmail/parcelsize');
}

public function tearDown() {
$this->_model = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<?php
class Meanbee_Royalmail_Test_Model_Shipping_Carrier_Royalmail extends Meanbee_Royalmail_Test_Model_Shipping_Carrier_Royalmail_Abstract {
class Meanbee_Royalmail_Test_Model_Shipping_Carrier_Royalmail extends Meanbee_Royalmail_Test_Model_Shipping_Carrier_Royalmail_Abstract{
/** @var Meanbee_Royalmail_Model_Shipping_Carrier_Royalmail */
protected $_model = null;
private $_model = null;
private $_request;

public function setUp() {
$this->_model = Mage::getModel('royalmail/shipping_carrier_royalmail');
$this->_request = Mage::getModel('shipping/rate_request');
}

public function tearDown() {
$this->_model = null;
$this->_request = null;
}


public function testGetAllowedMethods() {
$this->assertTrue(is_array($this->_model->getAllowedMethods()));
}

public function testGetMethodsSingle() {
$this->assertTrue(is_string($this->_model->getMethods('letter')));
$this->assertNull($this->_model->getMethods('idontexist'));
$this->assertTrue(is_array($this->_model->getMethods()));
}

/**
Expand All @@ -28,4 +31,5 @@ public function testDisableByDefault() {
100, 1.0, 'GB'
)));
}
}

}

This file was deleted.

Loading

0 comments on commit 1bfdcb2

Please sign in to comment.