From 09d5118e9b1a9e00e6c5fffae32ce94c652bfdb7 Mon Sep 17 00:00:00 2001 From: Andre Herrmann Date: Fri, 19 May 2017 13:48:49 +0200 Subject: [PATCH] OXID-123: Simplified handling of fetching ratepayprofiles --- application/models/fcporatepay.php | 11 ++++------- lib/fcpohelper.php | 14 +++++++------- .../application/models/fcporatepayTest.php | 5 ++++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/application/models/fcporatepay.php b/application/models/fcporatepay.php index 66fbff46..339e196c 100644 --- a/application/models/fcporatepay.php +++ b/application/models/fcporatepay.php @@ -77,6 +77,7 @@ public function fcpoInsertProfile($sOxid, $aRatePayData) */ public function fcpoGetRatePayProfiles($sPaymentId = null) { + $oDb = $this->_oFcpoHelper->fcpoGetDb(true); $aReturn = array(); $sFilterPaymentId = ""; @@ -85,15 +86,11 @@ public function fcpoGetRatePayProfiles($sPaymentId = null) } $sQuery = "SELECT * FROM fcporatepay {$sFilterPaymentId}"; - $aRatePayProfiles = $this->_oFcpoDb->getAll($sQuery); - $aFields = $this->fcpoGetFields(); + $aRatePayProfiles = $oDb->getAll($sQuery); foreach ($aRatePayProfiles as $aRatePayProfile) { - $sOxid = $aRatePayProfile[0]; - foreach ($aRatePayProfile as $iIndex=>$sValue) { - $aRow[$aFields[$iIndex][0]] = $sValue; - } - $aReturn[$sOxid] = $aRow; + $sOxid = $aRatePayProfile['OXID']; + $aReturn[$sOxid] = $aRatePayProfile; } return $aReturn; } diff --git a/lib/fcpohelper.php b/lib/fcpohelper.php index 3593d5e9..6daf9777 100644 --- a/lib/fcpohelper.php +++ b/lib/fcpohelper.php @@ -203,9 +203,9 @@ public function fcpoGetSession() public function fcpoGetDb($blAssoc = false) { if ($blAssoc) { - return ( $this->_fcUseDeprecatedInstantiation ) ? oxDb::getDb(true) : oxDb::getDb(oxDB::FETCH_MODE_ASSOC); + return ($this->_fcUseDeprecatedInstantiation()) ? oxDb::getDb(true) : oxDb::getDb(oxDB::FETCH_MODE_ASSOC); } else { - return ( $this->_fcUseDeprecatedInstantiation ) ? oxDb::getDb() : oxDb::getDb(oxDb::FETCH_MODE_NUM); + return ($this->_fcUseDeprecatedInstantiation()) ? oxDb::getDb() : oxDb::getDb(oxDb::FETCH_MODE_NUM); } } @@ -507,7 +507,7 @@ public function fcpoGetPayoneStatusList() 'vsettlement', 'transfer', 'invoice', - ); + ); } /** @@ -540,10 +540,10 @@ public function fcpoGetIntegratorId() protected function _fcUseDeprecatedInstantiation() { $oConfig = $this->getConfig(); - if (( version_compare($oConfig->getVersion(), "4.8.0") < 1 && $oConfig->getEdition() == "CE" ) - || ( version_compare($oConfig->getVersion(), "4.8.0") < 1 && $oConfig->getEdition() == "PE" ) - || ( version_compare($oConfig->getVersion(), "5.1.0") < 1 && $oConfig->getEdition() == "EE" ) - ) { + if ((version_compare($oConfig->getVersion(), "4.8.0") < 1 && $oConfig->getEdition() == "CE") + || (version_compare($oConfig->getVersion(), "4.8.0") < 1 && $oConfig->getEdition() == "PE") + || (version_compare($oConfig->getVersion(), "5.1.0") < 1 && $oConfig->getEdition() == "EE") + ) { return true; } else { return false; diff --git a/tests/unit/fcPayOne/application/models/fcporatepayTest.php b/tests/unit/fcPayOne/application/models/fcporatepayTest.php index 67e6608e..5aac9743 100644 --- a/tests/unit/fcPayOne/application/models/fcporatepayTest.php +++ b/tests/unit/fcPayOne/application/models/fcporatepayTest.php @@ -127,7 +127,10 @@ public function test_fcpoGetRatePayProfiles_Coverage() $oMockDatabase = $this->getMock('oxDb', array('getAll', 'quote')); $oMockDatabase->expects($this->atLeastOnce())->method('getAll')->will($this->returnValue($aMockResult)); $oMockDatabase->expects($this->any())->method('quote')->will($this->returnValue(null)); - $this->invokeSetAttribute($oTestObject, '_oFcpoDb', $oMockDatabase); + + $oHelper = $this->getMockBuilder('fcpohelper')->disableOriginalConstructor()->getMock(); + $oHelper->expects($this->any())->method('fcpoGetDb')->will($this->returnValue($oMockDatabase)); + $this->invokeSetAttribute($oTestObject, '_oFcpoHelper', $oHelper); $aExpect = array( 'someValue' => array(''=>'someValue'),