From c4471d630ca854f52a1cb55d845c5d9b617380fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 22 Nov 2024 12:21:31 +0100 Subject: [PATCH] OX6-164 - Added UnitTests to PPE V2 integration --- application/helper/fcpobasehelper.php | 19 +++ application/helper/fcpopaymenthelper.php | 19 +++ application/helper/fcpopaypalhelper.php | 21 ++- application/helper/fcporedirecthelper.php | 40 +++-- tests/phpunit.xml | 1 + .../helper/fcpopaymenthelperTest.php | 74 +++++++++ .../helper/fcpopaypalhelperTest.php | 135 +++++++++++++++++ .../helper/fcporedirecthelperTest.php | 69 +++++++++ .../application/models/fcpayone_ajaxTest.php | 42 +++++ .../controllers/fcPayOneBasketViewTest.php | 29 ++-- .../controllers/fcPayOneOrderViewTest.php | 19 +-- .../controllers/fcPayonePaymentViewTest.php | 20 +++ .../application/models/fcPayOneOrderTest.php | 28 +++- .../extend/core/fcPayOneViewConfTest.php | 143 ++++++++++++++++-- 14 files changed, 608 insertions(+), 51 deletions(-) create mode 100644 tests/unit/fcPayOne/application/helper/fcpopaymenthelperTest.php create mode 100644 tests/unit/fcPayOne/application/helper/fcpopaypalhelperTest.php create mode 100644 tests/unit/fcPayOne/application/helper/fcporedirecthelperTest.php diff --git a/application/helper/fcpobasehelper.php b/application/helper/fcpobasehelper.php index 9c9ad438..4597b118 100644 --- a/application/helper/fcpobasehelper.php +++ b/application/helper/fcpobasehelper.php @@ -1,5 +1,24 @@ . + * + * @link http://www.payone.de + * @copyright (C) Payone GmbH + * @version OXID eShop CE + */ + abstract class fcpobasehelper { /** diff --git a/application/helper/fcpopaymenthelper.php b/application/helper/fcpopaymenthelper.php index b83b7431..3e8e3ab2 100644 --- a/application/helper/fcpopaymenthelper.php +++ b/application/helper/fcpopaymenthelper.php @@ -1,5 +1,24 @@ . + * + * @link http://www.payone.de + * @copyright (C) Payone GmbH + * @version OXID eShop CE + */ + class fcpopaymenthelper extends fcpobasehelper { /** diff --git a/application/helper/fcpopaypalhelper.php b/application/helper/fcpopaypalhelper.php index 1c2291e7..88498537 100644 --- a/application/helper/fcpopaypalhelper.php +++ b/application/helper/fcpopaypalhelper.php @@ -1,5 +1,24 @@ . + * + * @link http://www.payone.de + * @copyright (C) Payone GmbH + * @version OXID eShop CE + */ + class fcpopaypalhelper extends fcpobasehelper { const PPE_EXPRESS = 'fcpopaypal_express'; @@ -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; } diff --git a/application/helper/fcporedirecthelper.php b/application/helper/fcporedirecthelper.php index 297a807c..df0b82ef 100644 --- a/application/helper/fcporedirecthelper.php +++ b/application/helper/fcporedirecthelper.php @@ -1,5 +1,24 @@ . + * + * @link http://www.payone.de + * @copyright (C) Payone GmbH + * @version OXID eShop CE + */ + class fcporedirecthelper extends fcpobasehelper { /** @@ -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 } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index e2679cba..be6c8da3 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -15,6 +15,7 @@ ../application/models + ../application/helper ../application/controllers ../extend diff --git a/tests/unit/fcPayOne/application/helper/fcpopaymenthelperTest.php b/tests/unit/fcPayOne/application/helper/fcpopaymenthelperTest.php new file mode 100644 index 00000000..765a3e0f --- /dev/null +++ b/tests/unit/fcPayOne/application/helper/fcpopaymenthelperTest.php @@ -0,0 +1,74 @@ +. + * + * @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(); + } +} \ No newline at end of file diff --git a/tests/unit/fcPayOne/application/helper/fcpopaypalhelperTest.php b/tests/unit/fcPayOne/application/helper/fcpopaypalhelperTest.php new file mode 100644 index 00000000..1a1af13a --- /dev/null +++ b/tests/unit/fcPayOne/application/helper/fcpopaypalhelperTest.php @@ -0,0 +1,135 @@ +. + * + * @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(); + } +} \ No newline at end of file diff --git a/tests/unit/fcPayOne/application/helper/fcporedirecthelperTest.php b/tests/unit/fcPayOne/application/helper/fcporedirecthelperTest.php new file mode 100644 index 00000000..38d2f703 --- /dev/null +++ b/tests/unit/fcPayOne/application/helper/fcporedirecthelperTest.php @@ -0,0 +1,69 @@ +. + * + * @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 fcporedirecthelperTest extends OxidTestCase +{ + public function testGetErrorUrl() + { + $sExpected = 'abortTest'; + + $oClassToTest = new fcporedirecthelper(); + $sResult = $oClassToTest->getErrorUrl($sExpected, true); + + $this->assertStringContainsString($sExpected, $sResult); + $this->assertStringContainsString('fcpoamzaction=logoff', $sResult); + } + + public function testGetSuccessUrl() + { + $oSession = $this->getMockBuilder(\OxidEsales\Eshop\Core\Session::class)->disableOriginalConstructor()->getMock(); + $oSession->method('sid')->willReturn('sid12345'); + + $oConfig = $this->getMockBuilder(\OxidEsales\Eshop\Core\Config::class)->disableOriginalConstructor()->getMock(); + $oConfig->method('getCurrentShopUrl')->willReturn('shopURL'); + + $oHelper = $this->getMockBuilder(fcpohelper::class)->disableOriginalConstructor()->getMock(); + $oHelper->method('fcpoGetRequestParameter')->willReturn('testValue'); + $oHelper->method('fcpoGetSession')->willReturn($oSession); + $oHelper->method('fcpoGetConfig')->willReturn($oConfig); + + UtilsObject::setClassInstance(fcpohelper::class, $oHelper); + + $oClassToTest = new fcporedirecthelper(); + $sResult = $oClassToTest->getSuccessUrl('testRefNr', false, false, false); + + $this->assertStringContainsString('sid12345', $sResult); + $this->assertStringContainsString('testValue', $sResult); + $this->assertStringContainsString('testRefNr', $sResult); + $this->assertStringContainsString('shopURL', $sResult); + + UtilsObject::resetClassInstances(); + } + + public function testDestroyInstance() + { + $this->assertNull(fcporedirecthelper::destroyInstance()); + } +} diff --git a/tests/unit/fcPayOne/application/models/fcpayone_ajaxTest.php b/tests/unit/fcPayOne/application/models/fcpayone_ajaxTest.php index 78dbba09..1534ef4e 100755 --- a/tests/unit/fcPayOne/application/models/fcpayone_ajaxTest.php +++ b/tests/unit/fcPayOne/application/models/fcpayone_ajaxTest.php @@ -538,4 +538,46 @@ public function test__fcpoGetInsterestCaption_Coverage() $this->assertEquals($sExpect, $sResponse); } + public function testFcpoStartPayPalExpress() + { + $oTestObject = oxNew('fcpayone_ajax'); + + $aResponse = [ + 'status' => 'REDIRECT', + 'workorderid' => '4711', + 'add_paydata[orderId]' => '47110815', + ]; + + $oRequest = $this->getMockBuilder(fcpoRequest::class)->disableOriginalConstructor()->getMock(); + $oRequest->method('sendRequestGenericPayment')->willReturn($aResponse); + + $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); + $oHelper->method('getFactoryObject')->willReturn($oRequest); + $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + + $sResult = $oTestObject->fcpoStartPayPalExpress(); + + $this->assertStringContainsString('47110815', $sResult); + } + + public function testFcpoStartPayPalExpressError() + { + $oTestObject = oxNew('fcpayone_ajax'); + + $aResponse = [ + 'status' => 'ERROR', + 'customermessage' => 'ERRORTEST', + ]; + + $oRequest = $this->getMockBuilder(fcpoRequest::class)->disableOriginalConstructor()->getMock(); + $oRequest->method('sendRequestGenericPayment')->willReturn($aResponse); + + $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); + $oHelper->method('getFactoryObject')->willReturn($oRequest); + $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + + $sResult = $oTestObject->fcpoStartPayPalExpress(); + + $this->assertStringContainsString('ERRORTEST', $sResult); + } } diff --git a/tests/unit/fcPayOne/extend/application/controllers/fcPayOneBasketViewTest.php b/tests/unit/fcPayOne/extend/application/controllers/fcPayOneBasketViewTest.php index 6d703430..d34fb2fd 100755 --- a/tests/unit/fcPayOne/extend/application/controllers/fcPayOneBasketViewTest.php +++ b/tests/unit/fcPayOne/extend/application/controllers/fcPayOneBasketViewTest.php @@ -18,9 +18,11 @@ * @copyright (C) Payone GmbH * @version OXID eShop CE */ + +use OxidEsales\Eshop\Core\UtilsObject; + class Unit_fcPayOne_Extend_Application_Controllers_fcPayOneBasketView extends OxidTestCase { - /** * Call protected/private method of a class. * @@ -139,16 +141,18 @@ public function test__fcpoCheckForAmazonLogoff_Coverage() { */ public function test__fcpoIsPayPalExpressActive_Coverage() { - $oTestObject = oxNew('fcPayOneBasketView'); + fcpopaymenthelper::destroyInstance(); - $oMockBasket = $this->getMock('oxBasket', array('fcpoIsPayPalExpressActive')); - $oMockBasket->expects($this->any())->method('fcpoIsPayPalExpressActive')->will($this->returnValue(true)); + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isPaymentMethodActive')->willReturn(true); - $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); - $oHelper->expects($this->any())->method('getFactoryObject')->will($this->returnValue($oMockBasket)); - $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); + $oTestObject = oxNew('fcPayOneBasketView'); $this->assertEquals(true, $oTestObject->_fcpoIsPayPalExpressActive()); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); } /** @@ -177,8 +181,10 @@ public function test_fcpoGetPayPalExpressPic_Coverage() */ public function test__fcpoGetPayPalExpressPic_Coverage() { - $oMockBasket = $this->getMock('oxBasket', array('fcpoGetPayPalExpressPic')); - $oMockBasket->expects($this->any())->method('fcpoGetPayPalExpressPic')->will($this->returnValue('somePic.jpg')); + \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute('DELETE FROM fcpopayoneexpresslogos WHERE 1'); + + $expected = 'somePic.jpg'; + \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute('INSERT INTO fcpopayoneexpresslogos (oxid, fcpo_active, fcpo_langid, fcpo_logo, fcpo_default) VALUES ("unitTestLogo", 1, 0, "'.$expected.'", "1")'); $oMockConfig = $this->getMock('oxConfig', array('getCurrentShopUrl')); $oMockConfig->expects($this->any())->method('getCurrentShopUrl')->will($this->returnValue('http://someurl.com/')); @@ -187,16 +193,17 @@ public function test__fcpoGetPayPalExpressPic_Coverage() $oTestObject->expects($this->any())->method('getConfig')->will($this->returnValue($oMockConfig)); $oHelper = $this->getMock('fcpohelper', array('getFactoryObject', 'fcpoFileExists')); - $oHelper->expects($this->any())->method('getFactoryObject')->will($this->returnValue($oMockBasket)); $oHelper->expects($this->any())->method('fcpoFileExists')->will($this->returnValue(true)); $this->invokeSetAttribute($oTestObject, '_sPayPalExpressLogoPath', 'somePath/'); $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); $sResponse = $this->invokeMethod($oTestObject, '_fcpoGetPayPalExpressPic'); - $sExpect = 'http://someurl.com/somePath/somePic.jpg'; + $sExpect = 'http://someurl.com/somePath/'.$expected; $this->assertEquals($sExpect, $sResponse); + + \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute('DELETE FROM fcpopayoneexpresslogos WHERE oxid = "unitTestLogo"'); } /** diff --git a/tests/unit/fcPayOne/extend/application/controllers/fcPayOneOrderViewTest.php b/tests/unit/fcPayOne/extend/application/controllers/fcPayOneOrderViewTest.php index 8378ae65..baaaa33a 100755 --- a/tests/unit/fcPayOne/extend/application/controllers/fcPayOneOrderViewTest.php +++ b/tests/unit/fcPayOne/extend/application/controllers/fcPayOneOrderViewTest.php @@ -100,30 +100,30 @@ public function test_execute_Parent() $this->assertEquals($mExpect, $mResponse); } - + /** * Testing fcpoHandlePayPalExpress for PositiveCall - * + * * @param void * @return void */ - public function test_fcpoHandlePayPalExpress_PositiveCall() + public function test_fcpoHandlePayPalExpress_PositiveCall() { $oTestObject = $this->getMock('fcPayOneOrderView', array('_handlePayPalExpressCall')); $oTestObject->expects($this->any())->method('_handlePayPalExpressCall')->will($this->returnValue(true)); - + $oMockUtilsView = $this->getMock('oxUtilsView', array('addErrorToDisplay')); $oMockUtilsView->expects($this->any())->method('addErrorToDisplay')->will($this->returnValue(null)); - + $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); $oHelper->expects($this->any())->method('fcpoGetUtilsView')->will($this->returnValue($oMockUtilsView)); - + $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); - + $this->assertEquals(null, $oTestObject->fcpoHandlePayPalExpress()); + $this->assertEquals(null, $oTestObject->fcpoHandlePayPalExpressV2()); } - /** * Testing fcpoHandlePayPalExpress for Exception * @@ -148,6 +148,7 @@ public function test_fcpoHandlePayPalExpress_Exception() $sExpect = 'basket'; $this->assertEquals($sExpect, $oTestObject->fcpoHandlePayPalExpress()); + $this->assertEquals($sExpect, $oTestObject->fcpoHandlePayPalExpressV2()); } /** @@ -770,7 +771,7 @@ public function test__handlePayPalExpressCall_Coverage() $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); - $mResponse = $mExpect = $this->invokeMethod($oTestObject, '_handlePayPalExpressCall'); + $mResponse = $mExpect = $this->invokeMethod($oTestObject, '_handlePayPalExpressCall', [fcpopaypalhelper::PPE_EXPRESS]); $this->assertEquals($mExpect, $mResponse); } diff --git a/tests/unit/fcPayOne/extend/application/controllers/fcPayonePaymentViewTest.php b/tests/unit/fcPayOne/extend/application/controllers/fcPayonePaymentViewTest.php index 8c97cc74..f138bf76 100755 --- a/tests/unit/fcPayOne/extend/application/controllers/fcPayonePaymentViewTest.php +++ b/tests/unit/fcPayOne/extend/application/controllers/fcPayonePaymentViewTest.php @@ -18,6 +18,8 @@ * @version OXID eShop CE */ +use OxidEsales\Eshop\Core\UtilsObject; + class Unit_fcPayOne_Extend_Application_Controllers_fcPayOnePaymentView extends OxidTestCaseCompatibilityWrapper { @@ -3619,4 +3621,22 @@ public function test__fcpoGetUserFromSession_Coverage() { $this->assertEquals($oExpect, $oTestObject->_fcpoGetUserFromSession()); } + + public function testFcpoPaymentActive() + { + fcpopaymenthelper::destroyInstance(); + + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isPaymentMethodActive')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); + + $oTestObject = oxNew('fcPayOnePaymentView'); + $result = $oTestObject->fcpoPaymentActive('test'); + + $this->assertTrue($result); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); + } } diff --git a/tests/unit/fcPayOne/extend/application/models/fcPayOneOrderTest.php b/tests/unit/fcPayOne/extend/application/models/fcPayOneOrderTest.php index 70a4b659..ea169976 100755 --- a/tests/unit/fcPayOne/extend/application/models/fcPayOneOrderTest.php +++ b/tests/unit/fcPayOne/extend/application/models/fcPayOneOrderTest.php @@ -1576,11 +1576,11 @@ public function test_debitNeedsBankData_Coverage() /** * Testing isDetailedProductInfoNeeded for coverage - * + * * @param void * @return void */ - public function test_isDetailedProductInfoNeeded_Coverage() + public function test_isDetailedProductInfoNeeded_Coverage() { $oTestObject = oxNew('fcPayOneOrder'); $oTestObject->oxorder__oxpaymenttype = new oxField('somePaymentNotOnExceptionList'); @@ -1598,6 +1598,30 @@ public function test_isDetailedProductInfoNeeded_Coverage() $this->assertEquals(true, $oTestObject->isDetailedProductInfoNeeded()); } + /** + * Testing isDetailedProductInfoNeeded for coverage + * + * @param void + * @return void + */ + public function test_isDetailedProductInfoNeededFalse_Coverage() + { + $oTestObject = oxNew('fcPayOneOrder'); + $oTestObject->oxorder__oxpaymenttype = new oxField('somePaymentNotOnExceptionList'); + + $oMockConfig = $this->getMock('oxConfig', array('getConfigParam')); + $oMockConfig + ->expects($this->any()) + ->method('getConfigParam') + ->will($this->returnValue(false)); + + $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); + $oHelper->expects($this->any())->method('fcpoGetConfig')->will($this->returnValue($oMockConfig)); + $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + + $this->assertEquals(false, $oTestObject->isDetailedProductInfoNeeded()); + } + /** * Testing getSequenceNumber for coverage * diff --git a/tests/unit/fcPayOne/extend/core/fcPayOneViewConfTest.php b/tests/unit/fcPayOne/extend/core/fcPayOneViewConfTest.php index 4a5fed0b..d0196c08 100755 --- a/tests/unit/fcPayOne/extend/core/fcPayOneViewConfTest.php +++ b/tests/unit/fcPayOne/extend/core/fcPayOneViewConfTest.php @@ -17,8 +17,9 @@ * @copyright (C) Payone GmbH * @version OXID eShop CE */ - - + +use OxidEsales\Eshop\Core\UtilsObject; + class Unit_fcPayOne_Extend_Core_fcPayOneViewConf extends OxidTestCase { @@ -207,16 +208,18 @@ public function test_fcpoGetLangAbbrById_Coverage() * @throws exception */ public function test_fcpoCanDisplayAmazonPayButton_Coverage() { - $oTestObject = oxNew('fcPayOneViewConf'); - $oMockPayment = $this->getMock('oxPayment', array('load')); - $oMockPayment->expects($this->any())->method('load')->will($this->returnValue(true)); - $oMockPayment->oxpayments__oxactive = new oxField('1'); + fcpopaymenthelper::destroyInstance(); - $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); - $oHelper->expects($this->any())->method('getFactoryObject')->will($this->returnValue($oMockPayment)); - $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isPaymentMethodActive')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); + $oTestObject = oxNew('fcPayOneViewConf'); $this->assertEquals(true, $oTestObject->fcpoCanDisplayAmazonPayButton()); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); } /** @@ -227,18 +230,21 @@ public function test_fcpoCanDisplayAmazonPayButton_Coverage() { * @throws exception */ public function test_fcpoGetAmazonWidgetsUrl_Coverage() { + fcpopaymenthelper::destroyInstance(); + $oTestObject = oxNew('fcPayOneViewConf'); - $oMockPayment = $this->getMock('oxPayment', array('load')); - $oMockPayment->expects($this->any())->method('load')->will($this->returnValue(true)); - $oMockPayment->oxpayments__fcpolivemode = new oxField('1'); - $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); - $oHelper->expects($this->any())->method('getFactoryObject')->will($this->returnValue($oMockPayment)); - $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isLiveMode')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); $sExpect = 'https://static-eu.payments-amazon.com/OffAmazonPayments/eur/lpa/js/Widgets.js'; $this->assertEquals($sExpect, $oTestObject->fcpoGetAmazonWidgetsUrl()); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); } /** @@ -612,4 +618,111 @@ public function test__fcpoGetExpectedButtonAmount_Coverage() { $this->assertEquals(4, $oTestObject->_fcpoGetExpectedButtonAmount()); } + public function testFcpoCanDisplayPayPalExpressV2Button() + { + fcpopaymenthelper::destroyInstance(); + + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isPaymentMethodActive')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); + + $oTestObject = oxNew('fcPayOneViewConf'); + $result = $oTestObject->fcpoCanDisplayPayPalExpressV2Button(); + + $this->assertTrue($result); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); + } + + public function testFcpoGetPayPalExpressV2GetButtonId() + { + fcpopaypalhelper::destroyInstance(); + + $expected = "fcpoPayPalExpressV2PayLaterPosi"; + + $oPayPalHelper = $this->getMockBuilder(fcpopaypalhelper::class)->disableOriginalConstructor()->getMock(); + $oPayPalHelper->method('showBNPLButton')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaypalhelper::class, $oPayPalHelper); + + $oTestObject = oxNew('fcPayOneViewConf'); + $result = $oTestObject->fcpoGetPayPalExpressV2GetButtonId("Posi"); + + $this->assertEquals($expected, $result); + + UtilsObject::resetClassInstances(); + fcpopaypalhelper::destroyInstance(); + } + + public function testFcpoGetPayPalExpressV2Values() + { + fcpopaypalhelper::destroyInstance(); + + $expected = "stringValue"; + + $oPayPalHelper = $this->getMockBuilder(fcpopaypalhelper::class)->disableOriginalConstructor()->getMock(); + $oPayPalHelper->method('getJavascriptUrl')->willReturn($expected); + $oPayPalHelper->method('getButtonColor')->willReturn($expected); + $oPayPalHelper->method('getButtonShape')->willReturn($expected); + + UtilsObject::setClassInstance(fcpopaypalhelper::class, $oPayPalHelper); + + $oTestObject = oxNew('fcPayOneViewConf'); + + $result = $oTestObject->fcpoGetPayPalExpressV2JavascriptUrl(); + $this->assertEquals($expected, $result); + + $result = $oTestObject->fcpoGetPayPalExpressButtonColor(); + $this->assertEquals($expected, $result); + + $result = $oTestObject->fcpoGetPayPalExpressButtonShape(); + $this->assertEquals($expected, $result); + + $result = $oTestObject->fcpoGetPayPalExpressV2JavascriptUrl(); + $this->assertEquals($expected, $result); + + UtilsObject::resetClassInstances(); + fcpopaypalhelper::destroyInstance(); + } + + public function testFcpoGetPayPalExpressSuccessUrl() + { + fcporedirecthelper::destroyInstance(); + + $expected = "successUrl"; + + $oRedirectHelper = $this->getMockBuilder(fcporedirecthelper::class)->disableOriginalConstructor()->getMock(); + $oRedirectHelper->method('getSuccessUrl')->willReturn($expected); + + UtilsObject::setClassInstance(fcporedirecthelper::class, $oRedirectHelper); + + $oTestObject = oxNew('fcPayOneViewConf'); + $result = $oTestObject->fcpoGetPayPalExpressSuccessUrl(); + $this->assertEquals($expected, $result); + + UtilsObject::resetClassInstances(); + fcporedirecthelper::destroyInstance(); + } + + public function testFcpoGetPayoneSecureEnvironment() + { + fcpopaymenthelper::destroyInstance(); + + $expected = 'p'; + + $oPaymentHelper = $this->getMockBuilder(fcpopaymenthelper::class)->disableOriginalConstructor()->getMock(); + $oPaymentHelper->method('isLiveMode')->willReturn(true); + + UtilsObject::setClassInstance(fcpopaymenthelper::class, $oPaymentHelper); + + $oTestObject = oxNew('fcPayOneViewConf'); + $result = $oTestObject->fcpoGetPayoneSecureEnvironment('test'); + + $this->assertEquals($expected, $result); + + UtilsObject::resetClassInstances(); + fcpopaymenthelper::destroyInstance(); + } }