diff --git a/.gitignore b/.gitignore index 4b4b8b9..0cfc422 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +/var/session +/var/cache +/var/phpunit.cache \ No newline at end of file diff --git a/app/code/community/Meanbee/Royalmail/Helper/Data.php b/app/code/community/Meanbee/Royalmail/Helper/Data.php index 7eb151c..7cde7fe 100644 --- a/app/code/community/Meanbee/Royalmail/Helper/Data.php +++ b/app/code/community/Meanbee/Royalmail/Helper/Data.php @@ -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() { @@ -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; - } } \ No newline at end of file diff --git a/app/code/community/Meanbee/Royalmail/Test/Config/Base.php b/app/code/community/Meanbee/Royalmail/Test/Config/Base.php index 543c7d1..e606457 100644 --- a/app/code/community/Meanbee/Royalmail/Test/Config/Base.php +++ b/app/code/community/Meanbee/Royalmail/Test/Config/Base.php @@ -1,5 +1,5 @@ assertModuleCodePool('community'); } diff --git a/app/code/community/Meanbee/Royalmail/Test/Helper/Data.php b/app/code/community/Meanbee/Royalmail/Test/Helper/Data.php index be26691..32e59cd 100644 --- a/app/code/community/Meanbee/Royalmail/Test/Helper/Data.php +++ b/app/code/community/Meanbee/Royalmail/Test/Helper/Data.php @@ -1,11 +1,47 @@ _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()); } } \ No newline at end of file diff --git a/app/code/community/Meanbee/Royalmail/Test/Model/Parcelsize.php b/app/code/community/Meanbee/Royalmail/Test/Model/Parcelsize.php new file mode 100644 index 0000000..d2b0ce7 --- /dev/null +++ b/app/code/community/Meanbee/Royalmail/Test/Model/Parcelsize.php @@ -0,0 +1,13 @@ +_model = Mage::getModel('royalmail/parcelsize'); + } + + public function tearDown() { + $this->_model = null; + } +} diff --git a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail.php b/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail.php index b7d0349..4014aa2 100644 --- a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail.php +++ b/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail.php @@ -1,23 +1,26 @@ _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())); } /** @@ -28,4 +31,5 @@ public function testDisableByDefault() { 100, 1.0, 'GB' ))); } -} + +} \ No newline at end of file diff --git a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules.php b/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules.php deleted file mode 100644 index 60c15b3..0000000 --- a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules.php +++ /dev/null @@ -1,167 +0,0 @@ - 'GB', - Meanbee_Royalmail_Helper_Data::WORLD_ZONE_EU => 'FR', - Meanbee_Royalmail_Helper_Data::WORLD_ZONE_ONE => 'US', - Meanbee_Royalmail_Helper_Data::WORLD_ZONE_TWO => 'AU', - ); - - /** - * @test - * @dataProvider dataProvider - * @dataProviderFile runTests.yaml - * - * @param $modelAlias - * @param $data - */ - public function runTests($modelAlias, $data) - { - $this->_model = Mage::getModel("royalmail/shipping_carrier_royalmail_{$modelAlias}"); - - if (!is_array($data['zones'])) { - $this->testAllowedZone($this->getCountryCode($data), $data['weights']['lowest'], $data['weights']['highest']); - $this->testNotAllowedZones($this->getNotAllowedCountryCode($data), $data['weights']['lowest'], $data['weights']['highest']); - } else { - foreach ($data['zones'] as $key => $zone) { - $this->testAllowedZone($this->getCountryCode($data, $key), $data['weights']['lowest'], $data['weights']['highest']); - $this->testNotAllowedZones($this->getNotAllowedCountryCode($data, $key), $data['weights']['lowest'], $data['weights']['highest']); - } - } - } - - /** - * Test each allowed zones set, for the maximum and minimum - * weight and prices. - * - * @param string $zone - * @param string $lowest - * @param string $highest - */ - protected function testAllowedZone($zone, $lowest, $highest) - { - $this->testWeight(floatval($lowest['price']), floatval($lowest['weight']), $zone, $this->getCartTotal($lowest)); - $this->testWeight(floatval($highest['price']), floatval($highest['weight']), $zone, $this->getCartTotal($highest)); - } - - /** - * Test each all zones which are not allowed for the maximum and - * minimum weight and prices. - * - * @param string $zone - * @param array $lowest - * @param array $highest - * @param float $cartTotal - */ - protected function testNotAllowedZones($zone, $lowest, $highest, $cartTotal = 1.00) - { - $this->assertNull( - $this->_model->getCost( - $this->_getRateRequest( - $lowest['weight'], - $cartTotal, - $zone - ) - ) - ); - $this->assertNull( - $this->_model->getCost( - $this->_getRateRequest( - $highest['weight'], - $cartTotal, - $zone - ) - ) - ); - } - - /** - * Test that the price is correct based on country code and weight. - * - * @param mixed $price - * @param float $weight - * @param string $zone - * @param float $cartTotal - */ - protected function testWeight($price, $weight, $zone, $cartTotal = 1.00) - { - $this->assertEquals( - $price, - $this->_model->getCost( - $this->_getRateRequest( - $weight, - $cartTotal, - $zone - ) - ) - ); - } - - /** - * Get the Country Code from Zone. - * - * @param $data - * @param null|string $key - * - * @return string - */ - protected function getCountryCode($data, $key = null) - { - if (isset($data['country_code'])) { - if (is_array($data['country_code'])) { - return $data['country_code'][$key]; - } else { - return $data['country_code']; - } - } - - if (is_array($data['zones'])) { - return $this->_countryCodes[$data['zones'][$key]]; - } else { - return $this->_countryCodes[$data['zones']]; - } - - } - - /** - * Get the total price of the cart. - * - * @param $data - * @return float - */ - protected function getCartTotal($data) - { - if (isset($data['cart_total'])) { - return $data['cart_total']; - } else { - return 1.00; - } - } - - /** - * Get a country code that isn't aloud for the method. - * - * @param array $data - * @param null|string $key - * - * @return string - */ - protected function getNotAllowedCountryCode($data, $key = null) - { - if(isset($data['not_allowed_zone'])) { - $data['zone'] = $data['not_allowed_zone']; - return $this->getCountryCode($data, $key); - } - $code = $this->getCountryCode($data, $key); - if($code == 'GB') { - return $this->_countryCodes[Meanbee_Royalmail_Helper_Data::WORLD_ZONE_ONE]; - } else { - return $this->_countryCodes[Meanbee_Royalmail_Helper_Data::WORLD_ZONE_GB]; - } - } - -} diff --git a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules/providers/runTests.yaml b/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules/providers/runTests.yaml deleted file mode 100644 index 77b7c39..0000000 --- a/app/code/community/Meanbee/Royalmail/Test/Model/Shipping/Carrier/Royalmail/Rules/providers/runTests.yaml +++ /dev/null @@ -1,126 +0,0 @@ -- - model_alias: letter - data: { csv: letter, weights: { lowest: { weight: '100', price: "0.63" }, highest: { weight: '100', price: "0.63" } }, zones: gb } -- - model_alias: largeletter - data: { csv: largeletter, weights: { lowest: { weight: '250', price: '1.26' }, highest: { weight: '750', price: '2.42' } }, zones: gb } -- - model_alias: firstclasslettersignedfor - data: { csv: firstclass_letter_signedfor, weights: { lowest: { weight: '100', price: "1.73" }, highest: { weight: '100', price: "1.73" } }, zones: gb } -- - model_alias: firstclasslargelettersignedfor - data: { csv: firstclass_largeletter_signedfor, weights: { lowest: { weight: '250', price: '2.36' }, highest: { weight: '750', price: '3.52' } }, zones: gb } -- - model_alias: secondclassletter - data: { csv: secondclass_letter, weights: { lowest: { weight: '100', price: "0.54" }, highest: { weight: '100', price: "0.54" } }, zones: gb } -- - model_alias: secondclasslargeletter - data: { csv: secondclass_largeletter, weights: { lowest: { weight: '250', price: '1.19' }, highest: { weight: '750', price: '2.05' } }, zones: gb } -- - model_alias: secondclasslettersignedfor - data: { csv: secondclass_letter_signedfor, weights: { lowest: { weight: '100', price: "1.64" }, highest: { weight: '100', price: "1.64" } }, zones: gb } -- - model_alias: secondclasslargelettersignedfor - data: { csv: secondclass_largeletter_signedfor, weights: { lowest: { weight: '250', price: '2.36' }, highest: { weight: '750', price: '3.52' } }, zones: gb } -- - model_alias: specialdeliverynextday - data: { csv: nextday500, weights: { lowest: { weight: '500', price: '7.25' }, highest: { weight: '20000', price: '41.20' } }, zones: gb } -- - model_alias: specialdeliverynextday - data: { csv: nextday1000, weights: { lowest: { weight: '500', price: '8.25', cart_total: '999' }, highest: { weight: '20000', price: '41.20', cart_total: '999' } }, zones: gb } -- - model_alias: specialdeliverynextday - data: { csv: nextday2500, weights: { lowest: { weight: '500', price: '10.25', cart_total: '2499' }, highest: { weight: '20000', price: '44.20', cart_total: '2499' } }, zones: gb } -- - model_alias: specialdelivery9am - data: { csv: 9am50, weights: { lowest: { weight: '500', price: '20.76' }, highest: { weight: '2000', price: '26.94' } }, zones: gb } -- - model_alias: specialdelivery9am - data: { csv: 9am1000, weights: { lowest: { weight: '500', price: '22.96', cart_total: '999' }, highest: { weight: '2000', price: '29.14', cart_total: '999' } }, zones: gb } -- - model_alias: specialdelivery9am - data: { csv: 9am2500, weights: { lowest: { weight: '500', price: '26.46', cart_total: '2499' }, highest: { weight: '2000', price: '32.64', cart_total: '2499' } }, zones: gb } -- - model_alias: specialdelivery9amsaturday - data: { csv: 9am50saturday, weights: { lowest: { weight: '500', price: '23.76' }, highest: { weight: '2000', price: '29.94' } }, zones: gb } -- - model_alias: specialdelivery9amsaturday - data: { csv: 9am1000saturday, weights: { lowest: { weight: '500', price: '25.96', cart_total: '999' }, highest: { weight: '2000', price: '32.14', cart_total: '999' } }, zones: gb } -- - model_alias: specialdelivery9amsaturday - data: { csv: 9am2500saturday, weights: { lowest: { weight: '500', price: '29.46', cart_total: '2499' }, highest: { weight: '2000', price: '35.64', cart_total: '2499' } }, zones: gb } -- - model_alias: specialdeliverynextdaysaturday - data: { csv: nextday500saturday, weights: { lowest: { weight: '500', price: '11.70' }, highest: { weight: '20000', price: '52.44' } }, zones: gb } -- - model_alias: specialdeliverynextdaysaturday - data: { csv: nextday1000saturday, weights: { lowest: { weight: '500', price: '12.90', cart_total: '999' }, highest: { weight: '20000', price: '53.64', cart_total: '999' } }, zones: gb } -- - model_alias: specialdeliverynextdaysaturday - data: { csv: nextday2500saturday, weights: { lowest: { weight: '500', price: '15.18', cart_total: '2499' }, highest: { weight: '20000', price: '56.04', cart_total: '2499' } }, zones: gb } -- - model_alias: internationalstandard - data: { csv: internationalstandard_europe, weights: { lowest: { weight: '250', price: '3.95' }, highest: { weight: '2000', price: '13.46' } }, zones: eu } -- - model_alias: internationalstandard - data: { csv: internationalstandard_wz1, weights: { lowest: { weight: '250', price: '5.00' }, highest: { weight: '2000', price: '19.75' } }, zones: wz1 } -- - model_alias: internationalstandard - data: { csv: internationalstandard_wz2, weights: { lowest: { weight: '250', price: '5.45' }, highest: { weight: '2000', price: '21.50' } }, zones: wz2 } -- - model_alias: internationaltrackedsigned - data: { csv: internationaltrackedsigned_eu, weights: { lowest: { weight: '250', price: '8.7' }, highest: { weight: '2000', price: '16.96' } }, zones: eu } -- - model_alias: internationaltrackedsigned - data: { csv: internationaltrackedsigned_wz1, weights: { lowest: { weight: '250', price: '9.75' }, highest: { weight: '2000', price: '23.25' } }, zones: wz1 } -- - model_alias: internationaltrackedsigned - data: { csv: internationaltrackedsigned_wz2, weights: { lowest: { weight: '250', price: '10.05' }, highest: { weight: '2000', price: '25.00' } }, zones: wz2, country_code: NZ } -- - model_alias: internationaltracked - data: { csv: internationaltracked_eu, weights: { lowest: { weight: '250', price: '10.44' }, highest: { weight: '2000', price: '20.36' } }, zones: eu } -- - model_alias: internationaltracked - data: { csv: internationaltracked_wz1, weights: { lowest: { weight: '250', price: '9.75' }, highest: { weight: '2000', price: '23.55' } }, zones: wz1 } -- - model_alias: internationaltracked - data: { csv: internationaltracked_wz2, weights: { lowest: { weight: '250', price: '10.05' }, highest: { weight: '2000', price: '25.00' } }, zones: wz2 } -- - model_alias: internationalsigned - data: { csv: internationalsigned_eu, weights: { lowest: { weight: '250', price: '8.7' }, highest: { weight: '2000', price: '16.96' } }, zones: eu, country_code: CY } -- - model_alias: internationalsigned - data: { csv: internationalsigned_wz1, weights: { lowest: { weight: '250', price: '9.75' }, highest: { weight: '2000', price: '23.25' } }, zones: wz1, country_code: AO } -- - model_alias: internationalsigned - data: { csv: internationalsigned_wz2, weights: { lowest: { weight: '250', price: '10.05' }, highest: { weight: '2000', price: '25.00' } }, zones: wz2 } -- - model_alias: internationaleconomy - data: { csv: internationaleconomy, weights: { lowest: { weight: '250', price: '3.75' }, highest: { weight: '2000', price: '13.26' } }, zones: wz1 } -- - model_alias: internationallettertracked - data: { csv: internationallettertracked_eu, weights: { lowest: { weight: '20', price: '7.20' }, highest: { weight: '100', price: '7.83' } }, zones: eu } -- - model_alias: internationallettertracked - data: { csv: internationallettertracked_wz, weights: { lowest: { weight: '20', price: '6.33' }, highest: { weight: '100', price: '7.25' } }, zones: [wz1, wz2] } -- - model_alias: internationallettersigned - data: { csv: internationallettersigned_eu, weights: { lowest: { weight: '20', price: null }, highest: { weight: '100', price: null } }, zones: eu } -- - model_alias: internationallettersigned - data: { csv: internationallettersigned_wz, weights: { lowest: { weight: '20', price: '6.33' }, highest: { weight: '100', price: '7.25' } }, zones: [wz1, wz2], country_code: [TN, NC] } -- - model_alias: internationallettereconomy - data: { csv: internationalltettereconomy, weights: { lowest: { weight: '20', price: '1.33' }, highest: { weight: '100', price: '2.25' } }, zones: [wz1, wz2, eu] } -- - model_alias: internationalletterstandard - data: { csv: internationalletterstandard_eu, weights: { lowest: { weight: '20', price: '1.00' }, highest: { weight: '100', price: '1.52' } }, zones: eu } -- - model_alias: internationalletterstandard - data: { csv: internationalletterstandard_wz, weights: { lowest: { weight: '20', price: '1.33' }, highest: { weight: '100', price: '2.25' } }, zones: [wz1, wz2] } -- - model_alias: internationallettertrackedsigned - data: { csv: internationallettertrackedsigned_eu, weights: { lowest: { weight: '20', price: '1.00' }, highest: { weight: '100', price: '1.52' } }, zones: eu, country_code: AT } -- - model_alias: internationallettertrackedsigned - data: { csv: internationallettertrackedsigned_wz, weights: { lowest: { weight: '60', price: '7.15' }, highest: { weight: '100', price: '8.45' } }, zones: [wz1, wz2], country_code: [CA, CA] } diff --git a/composer.json b/composer.json index dbd1de3..400980d 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "require-dev": { "aydin-hassan/magento-core-composer-installer": "^1.3", "ecomdev/ecomdev_phpunit": "*", + "mikey179/vfsStream": "*@stable", "magento/magento": "1.14.2.2", "squizlabs/php_codesniffer": "*", "magento-ecg/coding-standard": "*" diff --git a/phpunit.xml b/phpunit.xml index 9d72497..70dcdd2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,26 @@ - - - UnitTests.php + + + + + + + + app/code/community/EcomDev/PHPUnit/Test/Suite.php - - - - - app/code/community/Meanbee/Royalmail - - app/code/community/Meanbee/Royalmail/Test - - + + app/code/community/Meanbee/Royalmail +