Skip to content

Commit

Permalink
OX6-164 - Added UnitTests to PPE V2 integration
Browse files Browse the repository at this point in the history
  • Loading branch information
FatchipRobert committed Nov 22, 2024
1 parent 6cacb02 commit c4471d6
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 51 deletions.
19 changes: 19 additions & 0 deletions application/helper/fcpobasehelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

abstract class fcpobasehelper
{
/**
Expand Down
19 changes: 19 additions & 0 deletions application/helper/fcpopaymenthelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

class fcpopaymenthelper extends fcpobasehelper
{
/**
Expand Down
21 changes: 20 additions & 1 deletion application/helper/fcpopaypalhelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

class fcpopaypalhelper extends fcpobasehelper
{
const PPE_EXPRESS = 'fcpopaypal_express';
Expand Down Expand Up @@ -118,7 +137,7 @@ protected function getClientId()
protected function getSupportedLocaleCode($sLocale = null)
{
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
return 'en_US';
$sLocale = 'en_US';
}
return $sLocale;
}
Expand Down
40 changes: 27 additions & 13 deletions application/helper/fcporedirecthelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

class fcporedirecthelper extends fcpobasehelper
{
/**
Expand Down Expand Up @@ -103,26 +122,21 @@ public function getSuccessUrl($sRefNr = false, $sRedirectFunction = false, $sTok
$sAddParams .= '&refnr=' . $sRefNr;
}

if (!empty($sRedirectFunction)) {
$sAddParams .= '&fnc='.$sRedirectFunction;
} else {
$sAddParams .= '&fnc=execute';
if (empty($sRedirectFunction)) {
$sRedirectFunction = "execute";
}
$sAddParams .= '&fnc='.$sRedirectFunction;


if (!empty($sDeliveryMD5)) {
$sAddParams .= '&sDeliveryAddressMD5=' . $sDeliveryMD5;
} elseif ($this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5')) {
$sAddParams .= '&sDeliveryAddressMD5=' . $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5');
if (empty($sDeliveryMD5) && $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5')) {
$sDeliveryMD5 = $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5');
}
$sAddParams .= '&sDeliveryAddressMD5=' . $sDeliveryMD5;

$blDownloadableProductsAgreement = $this->getMainHelper()->fcpoGetRequestParameter('oxdownloadableproductsagreement');
if ($blDownloadableProductsAgreement) {
if ($this->getMainHelper()->fcpoGetRequestParameter('oxdownloadableproductsagreement')) {
$sAddParams .= '&fcdpa=1'; // rewrite for oxdownloadableproductsagreement-param because of length-restriction
}

$blServiceProductsAgreement = $this->getMainHelper()->fcpoGetRequestParameter('oxserviceproductsagreement');
if ($blServiceProductsAgreement) {
if ($this->getMainHelper()->fcpoGetRequestParameter('oxserviceproductsagreement')) {
$sAddParams .= '&fcspa=1'; // rewrite for oxserviceproductsagreement-param because of length-restriction
}

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../application/models</directory>
<directory suffix=".php">../application/helper</directory>
<directory suffix=".php">../application/controllers</directory>
<directory suffix=".php">../extend</directory>
<exclude>
Expand Down
74 changes: 74 additions & 0 deletions tests/unit/fcPayOne/application/helper/fcpopaymenthelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

use OxidEsales\Eshop\Core\UtilsObject;
use OxidEsales\EshopCommunity\Application\Model\Payment;
use OxidEsales\Eshop\Core\Field;

class fcpopaymenthelperTest extends OxidTestCase
{
public function testLoadPaymentMethodFalse()
{
$oPayment = $this->getMockBuilder(Payment::class)->disableOriginalConstructor()->getMock();
$oPayment->method('load')->willReturn(false);

UtilsObject::setClassInstance(Payment::class, $oPayment);

$oClassToTest = new fcpopaymenthelper();
$sResult = $oClassToTest->loadPaymentMethod('test');

$this->assertFalse($sResult);

UtilsObject::resetClassInstances();
}

public function testIsPaymentMethodActive()
{
$oPayment = $this->getMockBuilder('oxpayment')->disableOriginalConstructor()->getMock();
$oPayment->method('load')->willReturn(true);
$oPayment->method('__get')->willReturn(new Field(true));

UtilsObject::setClassInstance('oxpayment', $oPayment);

$oClassToTest = new fcpopaymenthelper();
$sResult = $oClassToTest->isPaymentMethodActive('test');

$this->assertTrue($sResult);

UtilsObject::resetClassInstances();
}

public function testIsLiveMode()
{
$oPayment = $this->getMockBuilder('oxpayment')->disableOriginalConstructor()->getMock();
$oPayment->method('load')->willReturn(true);
$oPayment->method('__get')->willReturn(new Field(true));

UtilsObject::setClassInstance('oxpayment', $oPayment);

$oClassToTest = new fcpopaymenthelper();
$sResult = $oClassToTest->isLiveMode('test');

$this->assertTrue($sResult);

UtilsObject::resetClassInstances();
}
}
135 changes: 135 additions & 0 deletions tests/unit/fcPayOne/application/helper/fcpopaypalhelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/**
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAYONE OXID Connector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://www.payone.de
* @copyright (C) Payone GmbH
* @version OXID eShop CE
*/

use OxidEsales\Eshop\Core\UtilsObject;

class fcpopaypalhelperTest extends OxidTestCase
{
public function testGetButtonColor()
{
$sExpected = "gold";

$oConfig = $this->getMockBuilder(\OxidEsales\Eshop\Core\Config::class)->disableOriginalConstructor()->getMock();
$oConfig->method('getConfigParam')->willReturn($sExpected);

$oHelper = $this->getMockBuilder(fcpohelper::class)->disableOriginalConstructor()->getMock();
$oHelper->method('fcpoGetConfig')->willReturn($oConfig);

UtilsObject::setClassInstance(fcpohelper::class, $oHelper);

$oClassToTest = new fcpopaypalhelper();
$sResult = $oClassToTest->getButtonColor();

$this->assertEquals($sExpected, $sResult);

UtilsObject::resetClassInstances();
}

public function testGetButtonShape()
{
$sExpected = "rect";

$oConfig = $this->getMockBuilder(\OxidEsales\Eshop\Core\Config::class)->disableOriginalConstructor()->getMock();
$oConfig->method('getConfigParam')->willReturn($sExpected);

$oHelper = $this->getMockBuilder(fcpohelper::class)->disableOriginalConstructor()->getMock();
$oHelper->method('fcpoGetConfig')->willReturn($oConfig);

UtilsObject::setClassInstance(fcpohelper::class, $oHelper);

$oClassToTest = new fcpopaypalhelper();
$sResult = $oClassToTest->getButtonShape();

$this->assertEquals($sExpected, $sResult);

UtilsObject::resetClassInstances();
}

public function testShowBNPLButton()
{
$oConfig = $this->getMockBuilder(\OxidEsales\Eshop\Core\Config::class)->disableOriginalConstructor()->getMock();
$oConfig->method('getConfigParam')->willReturn(true);

$oHelper = $this->getMockBuilder(fcpohelper::class)->disableOriginalConstructor()->getMock();
$oHelper->method('fcpoGetConfig')->willReturn($oConfig);

UtilsObject::setClassInstance(fcpohelper::class, $oHelper);

$oClassToTest = new fcpopaypalhelper();
$sResult = $oClassToTest->showBNPLButton();

$this->assertTrue($sResult);

UtilsObject::resetClassInstances();
}

public function testGetJavascriptUrl()
{
$oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock();
$oPaymentHelper->method('isLiveMode')->willReturn(true);

UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper);

$oCurrency = new \stdClass();
$oCurrency->name = "EURTEST";

$oBasket = $this->getMockBuilder(OxidEsales\Eshop\Application\Model\Basket::class)->disableOriginalConstructor()->getMock();
$oBasket->method('getBasketCurrency')->willReturn($oCurrency);

$oSession = $this->getMockBuilder(\OxidEsales\Eshop\Core\Session::class)->disableOriginalConstructor()->getMock();
$oSession->method('getBasket')->willReturn($oBasket);

$oConfig = $this->getMockBuilder(\OxidEsales\Eshop\Core\Config::class)->disableOriginalConstructor()->getMock();
$oConfig->method('getConfigParam')->willReturnMap([
['blFCPOPayPalV2MerchantID', null, "merchantId"],
['blFCPOPayPalV2BNPL', null, true],
]);

$oLang = $this->getMockBuilder(\OxidEsales\Eshop\Core\Language::class)->disableOriginalConstructor()->getMock();
$oLang->method('translateString')->willReturn('not_found');

$oHelper = $this->getMockBuilder(fcpohelper::class)->disableOriginalConstructor()->getMock();
$oHelper->method('fcpoGetConfig')->willReturn($oConfig);
$oHelper->method('fcpoGetSession')->willReturn($oSession);
$oHelper->method('fcpoGetLang')->willReturn($oLang);

UtilsObject::setClassInstance(fcpohelper::class, $oHelper);

$oClassToTest = new fcpopaypalhelper();
$sResult = $oClassToTest->getJavascriptUrl();

$this->assertStringContainsString("FZ8jE7shhaY2mVydsWsSrjmHk0qJxmgJoWgHESqyoG35jL", $sResult);
$this->assertStringContainsString("merchantId", $sResult);
$this->assertStringContainsString("EURTEST", $sResult);
$this->assertStringContainsString("enable-funding=paylater", $sResult);

UtilsObject::resetClassInstances();
fcpopaymenthelper::destroyInstance();
}

public function testGetInstance()
{
$oResult = fcpopaypalhelper::getInstance();
$this->assertInstanceOf(fcpopaypalhelper::class, $oResult);

fcpopaypalhelper::destroyInstance();
}
}
Loading

0 comments on commit c4471d6

Please sign in to comment.