![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /home/fdshops/public_html/vendor/myfatoorah/library/tests/API/ |
<?php namespace MyFatoorah\Test\API; use MyFatoorah\Library\API\MyFatoorahShipping; class MyFatoorahShippingTest extends \PHPUnit\Framework\TestCase { private $keys; //----------------------------------------------------------------------------------------------------------------------------------------- public function __construct() { parent::__construct(); $this->keys = include __DIR__ . '/../apiKeys.php'; } //----------------------------------------------------------------------------------------------------------------------------------------- public function testGetShippingCountries() { foreach ($this->keys as $config) { try { $mfObj = new MyFatoorahShipping($config); $data = $mfObj->getShippingCountries(); $this->assertEquals('AD', $data[0]->CountryCode); $this->assertEquals('ANDORRA', $data[0]->CountryName); } catch (\Exception $ex) { $this->assertEquals($config['exception'], $ex->getMessage(), $config['message']); } } } //----------------------------------------------------------------------------------------------------------------------------------------- public function testGetShippingCities() { foreach ($this->keys as $config) { try { $mfObj = new MyfatoorahShipping($config); $cities = $mfObj->getShippingCities(1, 'KW', 'ada'); $this->assertEquals('ADAN', $cities[0]); $this->assertEquals('SHUHADA', $cities[1]); } catch (\Exception $ex) { $this->assertEquals($config['exception'], $ex->getMessage(), $config['message']); } } } //----------------------------------------------------------------------------------------------------------------------------------------- public function testCalculateShippingCharge() { $mfObj = new MyfatoorahShipping($this->keys['valid']); $shippingData = [ 'ShippingMethod' => 1, 'Items' => [ [ 'ProductName' => 'product', 'Description' => 'product', 'Weight' => 10, 'Width' => 10, 'Height' => 10, 'Depth' => 10, 'Quantity' => 1, 'UnitPrice' => '17.234', ] ], 'CountryCode' => 'KW', 'CityName' => 'adan', 'PostalCode' => '12345', ]; $data = $mfObj->calculateShippingCharge($shippingData); $this->assertEquals('KD', $data->Currency); } public function testCalculateShippingChargeExceptionProductName() { $mfObj = new MyfatoorahShipping($this->keys['valid']); //test empty ProductName $shippingData1 = [ 'ShippingMethod' => 1, 'Items' => [[ 'ProductName' => '', 'Description' => 'product', 'Weight' => 10, 'Width' => 10, 'Height' => 10, 'Depth' => 10, 'Quantity' => 1, 'UnitPrice' => '17.234', ]], 'CountryCode' => 'KW', 'CityName' => 'adan', 'PostalCode' => '12345', ]; $this->expectException(\Exception::class); $this->expectExceptionMessage('model.Items[0].ProductName: The field Product Name (En) is mandatory.'); $mfObj->calculateShippingCharge($shippingData1); } //----------------------------------------------------------------------------------------------------------------------------------------- }