Skip to content

Commit

Permalink
Add several tests (#172)
Browse files Browse the repository at this point in the history
* Add several tests

* Move tests in correct folder.

* Extends tests
  • Loading branch information
David Pauli authored Oct 26, 2016
1 parent 07f6431 commit c6f20bc
Show file tree
Hide file tree
Showing 21 changed files with 820 additions and 109 deletions.
34 changes: 32 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
<phpunit bootstrap="src/Shop.class.php" colors="always">
<testsuites>
<testsuite name="RESTClient Test">
<file>tests/RESTClientTest.php</file>
<file>tests/util/RESTClientTest.php</file>
</testsuite>
<testsuite name="Shop Test">
<file>tests/ShopTest.php</file>
</testsuite>
<testsuite name="InputValidator Test">
<file>tests/InputValidatorTest.php</file>
<file>tests/util/InputValidatorTest.php</file>
</testsuite>
<testsuite name="Contact Information Test">
<file>tests/shopobjects/information/ContactInformationTest.php</file>
</testsuite>
<testsuite name="Privacy Policy Information Test">
<file>tests/shopobjects/information/PrivacyPolicyInformationTest.php</file>
</testsuite>
<testsuite name="Right Of Withdrawal Information Test">
<file>tests/shopobjects/information/RightOfWithdrawalInformationTest.php</file>
</testsuite>
<testsuite name="Shipping Information Test">
<file>tests/shopobjects/information/ShippingInformationTest.php</file>
</testsuite>
<testsuite name="Terms And Condition Information Test">
<file>tests/shopobjects/information/TermsAndConditionInformationTest.php</file>
</testsuite>
<testsuite name="Address Test">
<file>tests/shopobjects/address/AddressTest.php</file>
</testsuite>
<testsuite name="Date Test">
<file>tests/shopobjects/date/DateTest.php</file>
</testsuite>
<testsuite name="Payment Method Test">
<file>tests/shopobjects/method/PaymentMethodTest.php</file>
</testsuite>
<testsuite name="Shipping Method Test">
<file>tests/shopobjects/method/ShippingMethodTest.php</file>
</testsuite>
<testsuite name="Shipping Method Test">
<file>tests/shopobjects/order/OrderTest.php</file>
</testsuite>
</testsuites>
<groups>
Expand Down
27 changes: 14 additions & 13 deletions src/Shop.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -182,9 +182,9 @@ public function __toString() {

return "<strong>Name:</strong> " . $this->name . "<br/>" .
"<strong>Slogan:</strong> " . $this->slogan . "<br/>" .
"<strong>Logo:</strong> " . $this->logo . "<br/>" .
"<strong>Storefront URL:</strong> " . $this->storefrontUrl . "<br/>" .
"<strong>Backoffice URL:</strong> " . $this->backofficeUrl . "<br/>";
"<strong>Logo:</strong> " . $this->logoURL . "<br/>" .
"<strong>Storefront URL:</strong> " . $this->storefrontURL . "<br/>" .
"<strong>Backoffice URL:</strong> " . $this->backofficeURL . "<br/>";
}

/**
Expand Down Expand Up @@ -316,7 +316,7 @@ public function getLogo() {

self::errorReset();
$this->reload();
return $this->logo;
return $this->logoURL;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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") ||
Expand All @@ -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']);

Expand All @@ -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) {
Expand Down
36 changes: 32 additions & 4 deletions src/shopobjects/address/Address.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -229,6 +231,19 @@ public function getCompany() {
return $this->company;
}

/**
* Returns the country.
*
* @author David Pauli <[email protected]>
* @return String The country.
* @since 0.2.1
*/
public function getCountry() {

self::errorReset();
return $this->country;
}

/**
* Returns the email address.
*
Expand Down Expand Up @@ -408,6 +423,19 @@ public function setCompany($company) {
$this->company = $company;
}

/**
* Sets the country.
*
* @author David Pauli <[email protected]>
* @param String $country The country.
* @since 0.2.1
*/
public function setCountry($country) {

self::errorReset();
$this->country = $country;
}

/**
* Sets the email address.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/shopobjects/date/Date.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Date {
*/
public function __construct($date) {

self::errorReset();

// if parameter is no string
if (InputValidator::isTimestamp($date)) {
$timestamp = $date;
Expand Down Expand Up @@ -93,7 +95,7 @@ public function asReadable() {
*/
public function getTimestamp() {

$this->errorReset();
self::errorReset();
return $this->timestamp;
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/shopobjects/method/PaymentMethod.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -90,7 +92,7 @@ public function getPaymentMethodID() {
*/
public function getName() {

$this->errorReset();
self::errorReset();
return $this->name;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/shopobjects/method/ShippingMethod.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -90,7 +92,7 @@ public function getShippingMethodID() {
*/
public function getName() {

$this->errorReset();
self::errorReset();
return $this->name;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/util/Logger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand All @@ -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
Expand Down
17 changes: 3 additions & 14 deletions src/util/RESTClient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -255,18 +255,6 @@ public static function getJSONContent() {
return JSONHandler::parseJSON(self::$CONTENT);
}

/**
* Gets the Location header of response.
*
* @author David Pauli <[email protected]>
* @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.
*
Expand Down Expand Up @@ -539,6 +527,7 @@ public static function resetLastResponse() {
self::$CONTENT_TYPE = null;
self::$DATE = null;
self::$HTTP_RESPONSE_CODE = 0;
self::$HEADERS = array();
}

/**
Expand Down
Loading

0 comments on commit c6f20bc

Please sign in to comment.