diff --git a/phpunit.xml b/phpunit.xml index 2ef025d..d9746c6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,43 @@ - tests/RESTClientTest.php + tests/util/RESTClientTest.php tests/ShopTest.php - tests/InputValidatorTest.php + tests/util/InputValidatorTest.php + + + tests/shopobjects/information/ContactInformationTest.php + + + tests/shopobjects/information/PrivacyPolicyInformationTest.php + + + tests/shopobjects/information/RightOfWithdrawalInformationTest.php + + + tests/shopobjects/information/ShippingInformationTest.php + + + tests/shopobjects/information/TermsAndConditionInformationTest.php + + + tests/shopobjects/address/AddressTest.php + + + tests/shopobjects/date/DateTest.php + + + tests/shopobjects/method/PaymentMethodTest.php + + + tests/shopobjects/method/ShippingMethodTest.php + + + tests/shopobjects/order/OrderTest.php diff --git a/src/Shop.class.php b/src/Shop.class.php index b1b8f0a..c20fa10 100644 --- a/src/Shop.class.php +++ b/src/Shop.class.php @@ -88,7 +88,7 @@ class Shop { private $isssl = true; /** @var Image|null The logo of the shop. */ - private $logo = null; + private $logoURL = null; /** @var String|null The name of the shop. */ private $name = null; @@ -130,14 +130,14 @@ class Shop { * @since 0.1.2 Add error reporting. * @since 0.1.3 Load shop attributes. */ - function __construct($host, $shop, $authToken, $isssl = true) { + function __construct($host, $shop, $authToken = null, $isssl = true) { if (!InputValidator::isHost($host) || !InputValidator::isShop($shop)) { Logger::warning("ep6\Shop\nHost (" . $host . ") or Shop (" . $shop . ") are not valid."); $error = !InputValidator::isHost($host) ? "S-1" : "S-2"; - self::setError($error); + self::errorSet($error); return; } @@ -182,9 +182,9 @@ public function __toString() { return "Name: " . $this->name . "
" . "Slogan: " . $this->slogan . "
" . - "Logo: " . $this->logo . "
" . - "Storefront URL: " . $this->storefrontUrl . "
" . - "Backoffice URL: " . $this->backofficeUrl . "
"; + "Logo: " . $this->logoURL . "
" . + "Storefront URL: " . $this->storefrontURL . "
" . + "Backoffice URL: " . $this->backofficeURL . "
"; } /** @@ -316,7 +316,7 @@ public function getLogo() { self::errorReset(); $this->reload(); - return $this->logo; + return $this->logoURL; } /** @@ -485,9 +485,9 @@ public function resetValues() { $this->name = null; $this->slogan = null; - $this->logoUrl = null; - $this->sfUrl = null; - $this->mboUrl = null; + $this->logoURL = null; + $this->storefrontURL = null; + $this->backofficeURL = null; } /** @@ -560,7 +560,8 @@ private function load() { return; } - $content = RESTClient::send(); + RESTClient::send(); + $content = RESTClient::getJSONContent(); // if respond has no name, slogan, logoUrl, sfUrl and mboUrl if (InputValidator::isExistsArrayKey($content, "name") || @@ -580,7 +581,7 @@ private function load() { // save the attributes $this->name = $content['name']; $this->slogan = $content['slogan']; - $this->logo = new Image($content['logoUrl']); + $this->logoURL = new Image($content['logoUrl']); $this->storefrontURL = new URL($content['sfUrl']); $this->backofficeURL = new URL($content['mboUrl']); @@ -602,7 +603,7 @@ private function reload() { // if the value is empty if (!InputValidator::isEmpty($this->name) && !InputValidator::isEmpty($this->slogan) && - !InputValidator::isEmpty($this->logo) && + !InputValidator::isEmpty($this->logoURL) && !InputValidator::isEmpty($this->storefrontURL) && !InputValidator::isEmpty($this->backofficeURL) && $this->NEXT_REQUEST_TIMESTAMP > $timestamp) { diff --git a/src/shopobjects/address/Address.class.php b/src/shopobjects/address/Address.class.php index 2a18ad8..d8157c1 100644 --- a/src/shopobjects/address/Address.class.php +++ b/src/shopobjects/address/Address.class.php @@ -69,10 +69,12 @@ class Address { */ public function __construct($addressParameter) { + self::errorReset(); + // if parameter is no array if (!InputValidator::isArray($addressParameter)) { - - $this->errorSet("D-1"); + + self::errorSet("A-1"); Logger::error("ep6\Address\nThe address parameter " . $addressParameter . " is no array."); return; } @@ -229,6 +231,19 @@ public function getCompany() { return $this->company; } + /** + * Returns the country. + * + * @author David Pauli + * @return String The country. + * @since 0.2.1 + */ + public function getCountry() { + + self::errorReset(); + return $this->country; + } + /** * Returns the email address. * @@ -408,6 +423,19 @@ public function setCompany($company) { $this->company = $company; } + /** + * Sets the country. + * + * @author David Pauli + * @param String $country The country. + * @since 0.2.1 + */ + public function setCountry($country) { + + self::errorReset(); + $this->country = $country; + } + /** * Sets the email address. * @@ -454,10 +482,10 @@ public function setLastName($lastName) { * @param String $salutation The salutation. * @since 0.2.0 */ - public function setSalutation($saluation) { + public function setSalutation($salutation) { self::errorReset(); - $this->salutation = $lastName; + $this->salutation = $salutation; } /** diff --git a/src/shopobjects/date/Date.class.php b/src/shopobjects/date/Date.class.php index 7f213bc..69950f5 100644 --- a/src/shopobjects/date/Date.class.php +++ b/src/shopobjects/date/Date.class.php @@ -33,6 +33,8 @@ class Date { */ public function __construct($date) { + self::errorReset(); + // if parameter is no string if (InputValidator::isTimestamp($date)) { $timestamp = $date; @@ -93,7 +95,7 @@ public function asReadable() { */ public function getTimestamp() { - $this->errorReset(); + self::errorReset(); return $this->timestamp; } } diff --git a/src/shopobjects/method/PaymentMethod.class.php b/src/shopobjects/method/PaymentMethod.class.php index 6163aa2..108248e 100644 --- a/src/shopobjects/method/PaymentMethod.class.php +++ b/src/shopobjects/method/PaymentMethod.class.php @@ -33,11 +33,13 @@ class PaymentMethod { */ public function __construct($paymentMethodParameter) { + self::errorReset(); + // if parameter is no string if (!InputValidator::isArray($paymentMethodParameter)) { - - $this->errorSet("SM-1"); - Logger::error("ep6\PaymentMethod\nThe parameter payment method paramater " . $paymentMethodParameter . " is no array."); + + $this->errorSet("PM-1"); + Logger::error("ep6\PaymentMethod\nThe payment method parameter " . $paymentMethodParameter . " is no array."); return; } @@ -75,9 +77,9 @@ public function __toString() { * @return String The payment method ID. * @since 0.1.3 */ - public function getPaymentMethodID() { + public function getID() { - $this->errorReset(); + self::errorReset(); return $this->paymentMethodId; } @@ -90,7 +92,7 @@ public function getPaymentMethodID() { */ public function getName() { - $this->errorReset(); + self::errorReset(); return $this->name; } } diff --git a/src/shopobjects/method/ShippingMethod.class.php b/src/shopobjects/method/ShippingMethod.class.php index 3cc719d..2278a58 100644 --- a/src/shopobjects/method/ShippingMethod.class.php +++ b/src/shopobjects/method/ShippingMethod.class.php @@ -33,11 +33,13 @@ class ShippingMethod { */ public function __construct($shippingMethodParameter) { + self::errorReset(); + // if parameter is no string if (!InputValidator::isArray($shippingMethodParameter)) { $this->errorSet("SM-1"); - Logger::error("ep6\ShippingMethod\nThe parameter shipping method paramater " . $shippingMethodParameter . " is no array."); + Logger::error("ep6\ShippingMethod\nThe shipping method parameter " . $shippingMethodParameter . " is no array."); return; } @@ -75,9 +77,9 @@ public function __toString() { * @return String The shipping method ID. * @since 0.1.3 */ - public function getShippingMethodID() { + public function getID() { - $this->errorReset(); + self::errorReset(); return $this->shippingMethodId; } @@ -90,7 +92,7 @@ public function getShippingMethodID() { */ public function getName() { - $this->errorReset(); + self::errorReset(); return $this->name; } } diff --git a/src/util/Logger.class.php b/src/util/Logger.class.php index f960911..45c5ab5 100644 --- a/src/util/Logger.class.php +++ b/src/util/Logger.class.php @@ -204,7 +204,7 @@ private static function getStacktrace() { $stacktrace .= "function " . $stackentry['function'] . "("; $stacktrace .= implode(",", $stackentry['args']); - $stacktrace .= ") called at " . $stackentry["file"] . " line " . $stackentry["line"]; + $stacktrace .= ") called at ". $stackentry["file"] . " line " . $stackentry["line"]; $stacktrace .= "\n"; } @@ -224,7 +224,10 @@ private static function getStacktrace() { private static function printMessage($message, $showStacktrace = false) { // build output - $output = $_SERVER['REMOTE_ADDR'] . " - "; + $output = ""; + if (!InputValidator::isEmptyArrayKey($_SERVER, 'REMOTE_ADDR')) { + $output = $_SERVER['REMOTE_ADDR'] . " - "; + } $output .= "[" . date("d/M/Y:H:i:s O") . "] "; // print message, if it is array or string diff --git a/src/util/RESTClient.class.php b/src/util/RESTClient.class.php index 56b6174..578cf91 100644 --- a/src/util/RESTClient.class.php +++ b/src/util/RESTClient.class.php @@ -28,7 +28,7 @@ class RESTClient { const PATHTOREST = "rs/shops"; /** @var String The user agent. */ - const USER_AGENT = "ePages REST SDk"; + const USER_AGENT = "ePages REST SDK"; /** @var int The time in ms the shop object should wait until the next request. */ public static $NEXT_RESPONSE_WAIT_TIME = 600; @@ -82,13 +82,13 @@ class RESTClient { public static function connect($host, $shop, $authToken = null, $isssl = true) { self::errorReset(); + self::disconnect(); // check parameters if (!InputValidator::isHost($host) || !InputValidator::isShop($shop)) { Logger::warning("ep6\RESTClient\nHost (" . $host . ") or Shop (" . $shop . ") are not valid."); - self::disconnect(); $error = !InputValidator::isHost($host) ? "RESTC-1" : "RESTC-2"; self::errorSet($error); return false; @@ -255,18 +255,6 @@ public static function getJSONContent() { return JSONHandler::parseJSON(self::$CONTENT); } - /** - * Gets the Location header of response. - * - * @author David Pauli - * @return String The Location header of last response. - * @since 0.2.1 - */ - public static function getLocation() { - - return self::$LOCATION; - } - /** * Returns if the last response was 200 OK. * @@ -539,6 +527,7 @@ public static function resetLastResponse() { self::$CONTENT_TYPE = null; self::$DATE = null; self::$HTTP_RESPONSE_CODE = 0; + self::$HEADERS = array(); } /** diff --git a/tests/ShopTest.php b/tests/ShopTest.php index f0aee11..778ecb0 100644 --- a/tests/ShopTest.php +++ b/tests/ShopTest.php @@ -5,90 +5,100 @@ class ShopTest extends \PHPUnit_Framework_TestCase { public $shop; - - /** - * @group shopobjects - */ - function testShopLocales() + + protected function setUp() { - $this->assertEquals("en_GB", $this->shop->getDefaultLocale()); - $this->assertContains("de_DE", $this->shop->getLocales()); + Logger::setLogLevel(LogLevel::NONE); } /** * @group shopobjects */ - function testShopCurrencies() + function testInvalidShop() { - $this->assertEquals("GBP", $this->shop->getDefaultCurrency()); - $this->assertContains("EUR", $this->shop->getCurrencies()); + // GIVEN / WHEN + $this->shop = new Shop("invalidDomain", "shopName"); + + // THEN + $this->assertTrue($this->shop->error()); + $this->assertEquals($this->shop->errorNumber(), "S-1"); } /** * @group shopobjects */ - function testShopContactInformation() + function testGetShopProperties() { - $contactInformation = $this->shop->getContactInformation(); - $this->assertEquals("Contact information", $contactInformation->getName()); - $this->assertEquals("Contact information", $contactInformation->getNavigationCaption()); - $this->assertEquals("David David", $contactInformation->getContactPerson()); - $this->assertEquals("000000", $contactInformation->getPhone()); - $this->assertEquals("bepeppered@gmail.com", $contactInformation->getEmail()); + // GIVEN / WHEN + $this->givenShop(); + + // THEN + $this->assertNotNull($this->shop->getBackofficeURL()); + $this->assertNotNull($this->shop->getLogo()); + $this->assertNotNull($this->shop->getName()); + $this->assertNotNull($this->shop->getStorefrontURL()); } /** * @group shopobjects */ - function testShopPrivacyPolicyInformation() + function testShopLocales() { - $privacyPolicyInformation = $this->shop->getPrivacyPolicyInformation(); - $this->assertEquals("Privacy policy", $privacyPolicyInformation->getName()); - $this->assertEquals("Privacy policy", $privacyPolicyInformation->getNavigationCaption()); + // GIVEN / WHEN + $this->givenShop(); + + // THEN + $this->assertEquals("en_GB", $this->shop->getDefaultLocale()); + $this->assertContains("de_DE", $this->shop->getLocales()); } /** * @group shopobjects */ - function testShopRightsOfWithdrawalInformation() + function testShopCurrencies() { - $rightsOfWithdrawalInformation = $this->shop->getRightsOfWithdrawalInformation(); - $this->assertEquals("Right of withdrawal", $rightsOfWithdrawalInformation->getName()); - $this->assertEquals("Right of withdrawal", $rightsOfWithdrawalInformation->getNavigationCaption()); + // GIVEN / WHEN + $this->givenShop(); + + // THEN + $this->assertEquals("GBP", $this->shop->getDefaultCurrency()); + $this->assertContains("EUR", $this->shop->getCurrencies()); } /** * @group shopobjects */ - function testShopShippingInformation() + function testUsedCurrency() { - $shippingInformation = $this->shop->getShippingInformation(); - $this->assertEquals("Shipping terms", $shippingInformation->getName()); - $this->assertEquals("Delivery", $shippingInformation->getNavigationCaption()); + // GIVEN + $this->givenShop(); + + // WHEN + $this->shop->setUsedCurrency("EUR"); + + // THEN + $this->assertEquals("EUR", $this->shop->getUsedCurrency()); } /** * @group shopobjects */ - function testShopTermsAndConditionInformation() + function testUsedLocale() { - $termsAndConditionInformation = $this->shop->getTermsAndConditionInformation(); - $this->assertEquals("Terms and Conditions", $termsAndConditionInformation->getName()); - $this->assertEquals("Terms and Conditions", $termsAndConditionInformation->getNavigationCaption()); - $this->assertEquals("You adapt this text via the preview or data sheet view under the \"Content/Categories\" menu item of your Administration.", $termsAndConditionInformation->getDescription()); + // GIVEN + $this->givenShop(); + + // WHEN + $this->shop->setUsedLocale("en_GB"); + + // THEN + $this->assertEquals("en_GB", $this->shop->getUsedLocale()); } - - /** - * @beforeClass - */ - function setUp() { - Logger::setLogLevel(LogLevel::NONE); + + function givenShop() { $this->shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); } - - /** - * @afterClass - */ + function cleanUp() { unset($this->shop); } diff --git a/tests/shopobjects/address/AddressTest.php b/tests/shopobjects/address/AddressTest.php new file mode 100644 index 0000000..92f2855 --- /dev/null +++ b/tests/shopobjects/address/AddressTest.php @@ -0,0 +1,133 @@ +givenInvalidAddressParameter(); + + // WHEN + $address = new Address($invalidAddressParameter); + + // THEN + $this->assertTrue($address->error()); + $this->assertEquals($address->errorNumber(), "A-1"); + } + + /** + * @group shopobjects + */ + function testAcceptCompleteAddressParameter() { + // GIVEN + $completeAddressParameter = $this->givenCompleteAddressParameter(); + + // WHEN + $address = new Address($completeAddressParameter); + + // THEN + $this->assertFalse($address->error()); + $this->thenCompleteAddressInformationIsExisting($address); + } + + /** + * @group shopobjects + */ + function testAcceptIncompleteAddressParameter() { + // GIVEN + $incompleteAddressParameter = $this->givenIncompleteAddressParameter(); + + // WHEN + $address = new Address($incompleteAddressParameter); + + // THEN + $this->assertFalse($address->error()); + $this->assertNotNull($address->getBirthday()); + $this->assertNull($address->getCity()); + } + + /** + * @group shopobjects + */ + function testSetAddressParameters() { + // GIVEN + $incompleteAddressParameter = $this->givenIncompleteAddressParameter(); + + // WHEN + $address = new Address($incompleteAddressParameter); + $address->setBirthday("01.02.1900"); + $address->setCity("Cologne"); + $address->setCompany("FakeCompany"); + $address->setCountry("England"); + $address->setEmailAddress("a@b.cd"); + $address->setFirstName("Max"); + $address->setLastName("Miller"); + $address->setSalutation("Mr."); + $address->setState("NRW"); + $address->setStreet("First street 2"); + $address->setStreetDetails("c/o Mister Smith"); + $address->setTitle("Master"); + $address->setVatId("DE1234567890"); + $address->setZipCode("12345"); + + // THEN + $this->assertFalse($address->error()); + $this->thenCompleteAddressInformationIsExisting($address); + } + + function givenInvalidAddressParameter() { + return "SomeString"; + } + + function givenCompleteAddressParameter() { + return array( + "birthday" => "01.02.1900", + "city" => "Cologne", + "company" => "FakeCompany", + "country" => "England", + "emailAddress" => "a@b.cd", + "firstName" => "Max", + "lastName" => "Miller", + "salutation" => "Mr.", + "state" => "NRW", + "street" => "First street 2", + "streetDetails" => "c/o Mister Smith", + "title" => "Master", + "vatId" => "DE1234567890", + "zipCode" => "12345" + ); + } + + function givenIncompleteAddressParameter() { + return array( + "birthday" => "01.02.1900" + ); + } + + function thenCompleteAddressInformationIsExisting($address) { + $this->assertNotNull($address->getBirthday()); + $this->assertNotNull($address->getCity()); + $this->assertNotNull($address->getCompany()); + $this->assertNotNull($address->getCountry()); + $this->assertNotNull($address->getEmailAddress()); + $this->assertNotNull($address->getFirstName()); + $this->assertNotNull($address->getLastName()); + $this->assertNotNull($address->getSalutation()); + $this->assertNotNull($address->getState()); + $this->assertNotNull($address->getStreet()); + $this->assertNotNull($address->getStreetDetails()); + $this->assertNotNull($address->getTitle()); + $this->assertNotNull($address->getVatId()); + $this->assertNotNull($address->getZipCode()); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/date/DateTest.php b/tests/shopobjects/date/DateTest.php new file mode 100644 index 0000000..42046b3 --- /dev/null +++ b/tests/shopobjects/date/DateTest.php @@ -0,0 +1,59 @@ +assertFalse($date->error()); + $this->assertEquals($date->getTimestamp(), 1477407378); + $this->assertEquals($date->asReadable(), "2016-10-25T14:56:18.000Z"); + } + + /** + * @group shopobjects + */ + function testCreateDateAsString() { + // GIVEN + $validString = "2016-10-25T14:56:18.000Z"; + + // WHEN + $date = new Date($validString); + + // THEN + $this->assertFalse($date->error()); + $this->assertEquals($date->getTimestamp(), 1477407378); + $this->assertEquals($date->asReadable(), "2016-10-25T14:56:18.000Z"); + } + + /** + * @group shopobjects + */ + function testRejectCreateDateNoString() { + // GIVEN + $invalidTimestamp = null; + + // WHEN + $date = new Date($invalidTimestamp); + + // THEN + $this->assertTrue($date->error()); + $this->assertEquals($date->errorNumber(), "D-1"); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/information/ContactInformationTest.php b/tests/shopobjects/information/ContactInformationTest.php new file mode 100644 index 0000000..0498118 --- /dev/null +++ b/tests/shopobjects/information/ContactInformationTest.php @@ -0,0 +1,39 @@ +shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); + $this->contactInformation = $this->shop->getContactInformation(); + } + + /** + * @group shopobjects + */ + function testContactInformation() + { + // THEN + $this->assertNotNull($this->contactInformation->getAddress()); + $this->assertNotNull($this->contactInformation->getDescription()); + $this->assertEquals("Contact information", $this->contactInformation->getName()); + $this->assertEquals("Contact information", $this->contactInformation->getNavigationCaption()); + $this->assertEquals("David David", $this->contactInformation->getContactPerson()); + $this->assertEquals("000000", $this->contactInformation->getPhone()); + $this->assertEquals("bepeppered@gmail.com", $this->contactInformation->getEmail()); + } + + function cleanUp() { + unset($this->shop); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/information/PrivacyPolicyInformationTest.php b/tests/shopobjects/information/PrivacyPolicyInformationTest.php new file mode 100644 index 0000000..28029b8 --- /dev/null +++ b/tests/shopobjects/information/PrivacyPolicyInformationTest.php @@ -0,0 +1,32 @@ +shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); + } + + /** + * @group shopobjects + */ + function testShopPrivacyPolicyInformation() + { + // THEN + $privacyPolicyInformation = $this->shop->getPrivacyPolicyInformation(); + $this->assertEquals("Privacy policy", $privacyPolicyInformation->getName()); + $this->assertEquals("Privacy policy", $privacyPolicyInformation->getNavigationCaption()); + } + + function cleanUp() { + unset($this->shop); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/information/RightsOfWithdrawalInformationTest.php b/tests/shopobjects/information/RightsOfWithdrawalInformationTest.php new file mode 100644 index 0000000..7e7d9cd --- /dev/null +++ b/tests/shopobjects/information/RightsOfWithdrawalInformationTest.php @@ -0,0 +1,32 @@ +shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); + } + + /** + * @group shopobjects + */ + function testShopRightsOfWithdrawalInformation() + { + // THEN + $rightsOfWithdrawalInformation = $this->shop->getRightsOfWithdrawalInformation(); + $this->assertEquals("Right of withdrawal", $rightsOfWithdrawalInformation->getName()); + $this->assertEquals("Right of withdrawal", $rightsOfWithdrawalInformation->getNavigationCaption()); + } + + function cleanUp() { + unset($this->shop); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/information/ShippingInformationTest.php b/tests/shopobjects/information/ShippingInformationTest.php new file mode 100644 index 0000000..2fa970a --- /dev/null +++ b/tests/shopobjects/information/ShippingInformationTest.php @@ -0,0 +1,32 @@ +shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); + } + + /** + * @group shopobjects + */ + function testShopShippingInformation() + { + // THEN + $shippingInformation = $this->shop->getShippingInformation(); + $this->assertEquals("Shipping terms", $shippingInformation->getName()); + $this->assertEquals("Delivery", $shippingInformation->getNavigationCaption()); + } + + function cleanUp() { + unset($this->shop); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/information/TermsAndConditionInformationTest.php b/tests/shopobjects/information/TermsAndConditionInformationTest.php new file mode 100644 index 0000000..b688032 --- /dev/null +++ b/tests/shopobjects/information/TermsAndConditionInformationTest.php @@ -0,0 +1,33 @@ +shop = new Shop("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); + } + + /** + * @group shopobjects + */ + function testShopTermsAndConditionInformation() + { + // THEN + $termsAndConditionInformation = $this->shop->getTermsAndConditionInformation(); + $this->assertEquals("Terms and Conditions", $termsAndConditionInformation->getName()); + $this->assertEquals("Terms and Conditions", $termsAndConditionInformation->getNavigationCaption()); + $this->assertEquals("You adapt this text via the preview or data sheet view under the \"Content/Categories\" menu item of your Administration.", $termsAndConditionInformation->getDescription()); + } + + function cleanUp() { + unset($this->shop); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/method/PaymentMethodTest.php b/tests/shopobjects/method/PaymentMethodTest.php new file mode 100644 index 0000000..63886a4 --- /dev/null +++ b/tests/shopobjects/method/PaymentMethodTest.php @@ -0,0 +1,95 @@ +assertTrue($paymentMethod->error()); + $this->assertEquals($paymentMethod->errorNumber(), "PM-1"); + } + + /** + * @group shopobjects + */ + function testCreateCompletePaymentMethod() { + // GIVEN + $paymentMethodParameter = $this->givenCompletePaymentMethod(); + + // WHEN + $paymentMethod = new PaymentMethod($paymentMethodParameter); + + // THEN + echo $paymentMethod->errorNumber(); + $this->assertFalse($paymentMethod->error()); + $this->assertEquals($paymentMethod->getName(), "Paypal"); + $this->assertEquals($paymentMethod->getID(), "123456789"); + } + + /** + * @group shopobjects + */ + function testCreatePaymentMethodOnlyID() { + // GIVEN + $paymentMethodParameter = $this->givenPaymentMethodOnlyID(); + + // WHEN + $paymentMethod = new PaymentMethod($paymentMethodParameter); + + // THEN + $this->assertFalse($paymentMethod->error()); + $this->assertNull($paymentMethod->getName()); + $this->assertEquals($paymentMethod->getID(), "123456789"); + } + + /** + * @group shopobjects + */ + function testCreatePaymentMethodOnlyName() { + // GIVEN + $paymentMethodParameter = $this->givenPaymentMethodOnlyName(); + + // WHEN + $paymentMethod = new PaymentMethod($paymentMethodParameter); + + // THEN + $this->assertFalse($paymentMethod->error()); + $this->assertEquals($paymentMethod->getName(), "Paypal"); + $this->assertNull($paymentMethod->getID()); + } + + function givenCompletePaymentMethod() { + return array( + "id" => "123456789", + "name" => "Paypal" + ); + } + + function givenPaymentMethodOnlyID() { + return array( + "id" => "123456789" + ); + } + + function givenPaymentMethodOnlyName() { + return array( + "name" => "Paypal" + ); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/method/ShippingMethodTest.php b/tests/shopobjects/method/ShippingMethodTest.php new file mode 100644 index 0000000..7ff3fbf --- /dev/null +++ b/tests/shopobjects/method/ShippingMethodTest.php @@ -0,0 +1,95 @@ +assertTrue($shippingMethod->error()); + $this->assertEquals($shippingMethod->errorNumber(), "SM-1"); + } + + /** + * @group shopobjects + */ + function testCreateCompleteShippingMethod() { + // GIVEN + $shippingMethodParameter = $this->givenCompleteShippingMethod(); + + // WHEN + $shippingMethod = new ShippingMethod($shippingMethodParameter); + + // THEN + echo $shippingMethod->errorNumber(); + $this->assertFalse($shippingMethod->error()); + $this->assertEquals($shippingMethod->getName(), "DHL"); + $this->assertEquals($shippingMethod->getID(), "123456789"); + } + + /** + * @group shopobjects + */ + function testCreateShippingMethodOnlyID() { + // GIVEN + $shippingMethodParameter = $this->givenShippingMethodOnlyID(); + + // WHEN + $shippingMethod = new PaymentMethod($shippingMethodParameter); + + // THEN + $this->assertFalse($shippingMethod->error()); + $this->assertNull($shippingMethod->getName()); + $this->assertEquals($shippingMethod->getID(), "123456789"); + } + + /** + * @group shopobjects + */ + function testCreateShippingMethodOnlyName() { + // GIVEN + $shippingMethodParameter = $this->givenShippingMethodOnlyName(); + + // WHEN + $shippingMethod = new PaymentMethod($shippingMethodParameter); + + // THEN + $this->assertFalse($shippingMethod->error()); + $this->assertEquals($shippingMethod->getName(), "DHL"); + $this->assertNull($shippingMethod->getID()); + } + + function givenCompleteShippingMethod() { + return array( + "id" => "123456789", + "name" => "DHL" + ); + } + + function givenShippingMethodOnlyID() { + return array( + "id" => "123456789" + ); + } + + function givenShippingMethodOnlyName() { + return array( + "name" => "DHL" + ); + } + +} + +?> \ No newline at end of file diff --git a/tests/shopobjects/order/OrderTest.php b/tests/shopobjects/order/OrderTest.php new file mode 100644 index 0000000..dc10d56 --- /dev/null +++ b/tests/shopobjects/order/OrderTest.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/tests/InputValidatorTest.php b/tests/util/InputValidatorTest.php similarity index 95% rename from tests/InputValidatorTest.php rename to tests/util/InputValidatorTest.php index f4be111..ba8a37f 100644 --- a/tests/InputValidatorTest.php +++ b/tests/util/InputValidatorTest.php @@ -3,6 +3,11 @@ namespace ep6; class InputValidatorTest extends \PHPUnit_Framework_TestCase { + + protected function setUp() + { + Logger::setLogLevel(LogLevel::NONE); + } /** * @group utility @@ -91,6 +96,15 @@ function testIsFloat() $this->assertTrue(InputValidator::isFloat(-1.2)); } + /** + * @group utility + */ + function testIsFormatterType() + { + $this->assertFalse(InputValidator::isFormatterType("NotAFormatterType")); + $this->assertTrue(InputValidator::isFormatterType("IMAGE")); + } + /** * @group utility */ @@ -278,6 +292,15 @@ function testIsString() $this->assertFalse(InputValidator::isString(1.2)); } + /** + * @group utility + */ + function testIsTimestamp() + { + $this->assertFalse(InputValidator::isTimestamp("NoTimestamp")); + $this->assertTrue(InputValidator::isTimestamp(1234567890)); + } + } ?> \ No newline at end of file diff --git a/tests/RESTClientTest.php b/tests/util/RESTClientTest.php similarity index 59% rename from tests/RESTClientTest.php rename to tests/util/RESTClientTest.php index 5840acc..415b4e9 100644 --- a/tests/RESTClientTest.php +++ b/tests/util/RESTClientTest.php @@ -3,18 +3,86 @@ namespace ep6; class RESTClientTest extends \PHPUnit_Framework_TestCase { + + protected function setUp() + { + Logger::setLogLevel(LogLevel::NONE); + } /** * @group utility */ function testConnection() { + // GIVEN / WHEN / THEN $this->assertTrue(RESTClient::connect("www.google.de", "Shopname")); $this->assertTrue(RESTClient::connect("www.google.de", "Shopname", "AuthToken")); $this->assertFalse(RESTClient::connect("ThisIsNODomain", "Shopname", "AuthToken")); $this->assertTrue(RESTClient::connect("www.google.de", "Shopname", "AuthToken", true)); $this->assertTrue(RESTClient::connect("www.google.de", "Shopname", "AuthToken", false)); + $this->assertTrue(RESTClient::disconnect()); } + + /** + * @group utility + */ + function testGetContent() { + // GIVEN + RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63"); + + // WHEN + RESTClient::send("legal"); + + // THEN + $this->assertTrue(RESTClient::isResponseOk()); + $this->assertNotNull(RESTClient::getContent()); + $this->assertNotNull(RESTClient::getJSONContent()); + } + + /** + * @group utility + */ + function testGetContentWithLocalization() { + // GIVEN + RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63"); + + // WHEN + RESTClient::sendWithLocalization("legal", "de_DE"); + + // THEN + $this->assertTrue(RESTClient::isResponseOk()); + $this->assertNotNull(RESTClient::getContent()); + $this->assertNotNull(RESTClient::getJSONContent()); + } + + /** + * @group utility + */ + function testGetCookie() { + // GIVEN + RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63"); + + // WHEN + RESTClient::setCookie("testKey", "testValue"); + + // THEN + $this->assertNotEmpty(RESTClient::getCookies()); + $this->assertEquals(RESTClient::getCookie("testKey"), "testValue"); + } + + /** + * @group utility + */ + function testGetHeader() { + // GIVEN + RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63"); + + // WHEN + RESTClient::send("legal"); + + // THEN + $this->assertNotNull(RESTClient::getHeader("Date")); + } /** * @group utility @@ -38,24 +106,23 @@ function testSend() { RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); - $this->assertNull(RESTClient::send("locales", "NoArray")); + RESTClient::send("locales", "NoArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-5", RESTClient::errorNumber()); RESTClient::disconnect(); - $this->assertNull(RESTClient::send("locales")); + RESTClient::send("locales"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-6", RESTClient::errorNumber()); RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); - $this->assertNull(RESTClient::send("NoValidRessource")); - $this->assertTrue(RESTClient::error()); - $this->assertEquals("RESTC-7", RESTClient::errorNumber()); + RESTClient::send("NoValidRessource"); + $this->assertFalse(RESTClient::isResponseOk()); + $this->assertFalse(RESTClient::isResponseFound()); - $this->assertNotNull(RESTClient::send()); - $this->assertFalse(RESTClient::error()); - $this->assertNull(RESTClient::errorNumber()); + RESTClient::send(); + $this->assertTrue(RESTClient::isResponseOk()); } /** @@ -65,43 +132,43 @@ function testSendWithLocalization() { RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); - $this->assertNull(RESTClient::sendWithLocalization("locale", "NoLocale")); + RESTClient::sendWithLocalization("locale", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); - $this->assertNull(RESTClient::sendWithLocalization("locales", "NoLocale", "NoArray")); + RESTClient::sendWithLocalization("locales", "NoLocale", "NoArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); - $this->assertNull(RESTClient::sendWithLocalization("locales", "en_GB", "NoArray")); + RESTClient::sendWithLocalization("locales", "en_GB", "NoArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-5", RESTClient::errorNumber()); RESTClient::disconnect(); - $this->assertNull(RESTClient::sendWithLocalization("locales", "NoLocale")); + RESTClient::sendWithLocalization("locales", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); RESTClient::disconnect(); - $this->assertNull(RESTClient::sendWithLocalization("locales", "en_GB")); + RESTClient::sendWithLocalization("locales", "en_GB"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-6", RESTClient::errorNumber()); RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); - $this->assertNull(RESTClient::sendWithLocalization("NoValidRessource", "en_GB")); - $this->assertTrue(RESTClient::error()); - $this->assertEquals("RESTC-7", RESTClient::errorNumber()); + RESTClient::sendWithLocalization("NoValidRessource", "en_GB"); + $this->assertFalse(RESTClient::isResponseOk()); + $this->assertFalse(RESTClient::isResponseFound()); - $this->assertNull(RESTClient::sendWithLocalization("NoValidRessource", "NoLocale")); + RESTClient::sendWithLocalization("NoValidRessource", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); - $this->assertNull(RESTClient::sendWithLocalization("locales", "de_DE", "noArray")); + RESTClient::sendWithLocalization("locales", "de_DE", "noArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-5", RESTClient::errorNumber()); - $this->assertNotNull(RESTClient::sendWithLocalization("locales", "de_DE")); + RESTClient::sendWithLocalization("locales", "de_DE"); $this->assertFalse(RESTClient::error()); $this->assertNull(RESTClient::errorNumber()); }