From 623bf060dad237828d8a9f772e076f78f4143ae4 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 14:36:09 +0200 Subject: [PATCH] OXDEV-338 Change oxDb to DatabaseProvider --- core/oecaptcha.php | 6 ++++-- core/oecaptchaevents.php | 6 +++--- metadata.php | 2 +- tests/unit/CaptchaTestCase.php | 8 +++++--- tests/unit/core/oecaptchaEventsTest.php | 4 +++- tests/unit/core/oecaptchaTest.php | 12 ++++++++++-- tests/unit/views/pricealarmTest.php | 10 ++++++---- tests/unit/views/suggestTest.php | 6 ++++-- 8 files changed, 36 insertions(+), 18 deletions(-) diff --git a/core/oecaptcha.php b/core/oecaptcha.php index d086d25..ff615d2 100644 --- a/core/oecaptcha.php +++ b/core/oecaptcha.php @@ -3,6 +3,8 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\Eshop\Core\DatabaseProvider; + /** * Class handling CAPTCHA image * This class requires utility file utils/verificationimg.php as image generator @@ -76,7 +78,7 @@ class oeCaptcha extends oxSuperCfg $hashArray[$hash] = array($textHash => $time); $session->setVariable('captchaHashes', $hashArray); } else { - $database = oxDb::getDb(); + $database = DatabaseProvider::getDb(); $query = "insert into oecaptcha (oxhash, oxtime) values (" . $database->quote($textHash) . ", " . $database->quote($time) . ")"; $database->execute($query); @@ -217,7 +219,7 @@ class oeCaptcha extends oxSuperCfg */ protected function passFromDb($macHash, $hash, $time) { - $database = oxDb::getDb(); + $database = DatabaseProvider::getDb(); $where = "where oxid = " . $database->quote($macHash) . " and oxhash = " . $database->quote($hash); $query = "select 1 from oecaptcha " . $where; $pass = (bool) $database->getOne($query, false, false); diff --git a/core/oecaptchaevents.php b/core/oecaptchaevents.php index 948dce1..f647ee6 100644 --- a/core/oecaptchaevents.php +++ b/core/oecaptchaevents.php @@ -3,6 +3,7 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\Eshop\Core\DatabaseProvider; /** * Class defines what module does on Shop events. @@ -24,8 +25,7 @@ class oeCaptchaEvents "KEY `OXTIME` (`OXTIME`) " . ") ENGINE=MEMORY AUTO_INCREMENT=1 COMMENT 'If session is not available, this is where captcha information is stored';"; - oxDb::getDb()->execute($query); - + DatabaseProvider::getDb()->execute($query); } /** @@ -37,7 +37,7 @@ class oeCaptchaEvents { $query = "DROP TABLE IF EXISTS `oecaptcha`"; - oxDb::getDb()->execute($query); + DatabaseProvider::getDb()->execute($query); } /** diff --git a/metadata.php b/metadata.php index 2b11c23..2f0a473 100755 --- a/metadata.php +++ b/metadata.php @@ -33,7 +33,7 @@ $aModule = array( 'en' => 'OXID eSales Simple Captcha Module', ), 'thumbnail' => 'out/pictures/picture.png', - 'version' => '1.0.0', + 'version' => '2.0.0', 'author' => 'OXID eSales AG', 'url' => 'http://www.oxid-esales.com/', 'email' => '', diff --git a/tests/unit/CaptchaTestCase.php b/tests/unit/CaptchaTestCase.php index b378e19..c64c17e 100644 --- a/tests/unit/CaptchaTestCase.php +++ b/tests/unit/CaptchaTestCase.php @@ -3,7 +3,9 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ -abstract class CaptchaTestCase extends OxidTestCase +use OxidEsales\EshopCommunity\Core\DatabaseProvider; + +abstract class CaptchaTestCase extends \OxidEsales\TestingLibrary\UnitTestCase { /** * Fixture set up. @@ -23,7 +25,7 @@ abstract class CaptchaTestCase extends OxidTestCase ) ENGINE=MEMORY AUTO_INCREMENT=1 COMMENT 'If session is not available, this is where captcha information is stored'; "; - oxDb::getDb()->execute($query); + DatabaseProvider::getDb()->execute($query); } /** @@ -32,7 +34,7 @@ abstract class CaptchaTestCase extends OxidTestCase protected function tearDown() { $query = "DROP TABLE `oecaptcha`"; - oxDb::getDb()->execute($query); + DatabaseProvider::getDb()->execute($query); parent::tearDown(); } diff --git a/tests/unit/core/oecaptchaEventsTest.php b/tests/unit/core/oecaptchaEventsTest.php index d527557..bfe2eb7 100644 --- a/tests/unit/core/oecaptchaEventsTest.php +++ b/tests/unit/core/oecaptchaEventsTest.php @@ -3,6 +3,8 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\EshopCommunity\Core\DatabaseProvider; + require_once __DIR__ . '/../CaptchaTestCase.php'; class Unit_Core_oecaptchaEventsTest extends CaptchaTestCase @@ -15,7 +17,7 @@ class Unit_Core_oecaptchaEventsTest extends CaptchaTestCase parent::setUp(); //Drop captcha table - oxDb::getDB()->execute("DROP TABLE IF EXISTS `oecaptcha`"); + DatabaseProvider::getDB()->execute("DROP TABLE IF EXISTS `oecaptcha`"); } /** diff --git a/tests/unit/core/oecaptchaTest.php b/tests/unit/core/oecaptchaTest.php index 12f2b30..1fa2cb6 100644 --- a/tests/unit/core/oecaptchaTest.php +++ b/tests/unit/core/oecaptchaTest.php @@ -3,6 +3,8 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\EshopCommunity\Core\DatabaseProvider; + require_once __DIR__ . '/../CaptchaTestCase.php'; class Unit_Core_oecaptchaTest extends CaptchaTestCase @@ -50,7 +52,10 @@ class Unit_Core_oecaptchaTest extends CaptchaTestCase $captcha->expects($this->once())->method('getSession')->will($this->returnValue($session)); $hash = $captcha->getHash('test'); - $this->assertEquals(oxDb::getDb()->getOne('select LAST_INSERT_ID()', false, false), $hash); + $this->assertEquals(DatabaseProvider::getDb()->getOne( + 'select LAST_INSERT_ID()', + false + ), $hash); } /** @@ -127,7 +132,10 @@ class Unit_Core_oecaptchaTest extends CaptchaTestCase $captcha->setSession($session); $captcha->getHash('3at8u'); - $hash = oxDb::getDb()->getOne('select LAST_INSERT_ID()', false, false); + $hash = DatabaseProvider::getDb()->getOne( + 'select LAST_INSERT_ID()', + false + ); $this->assertTrue($captcha->pass('3at8u', $hash)); } diff --git a/tests/unit/views/pricealarmTest.php b/tests/unit/views/pricealarmTest.php index a192f33..dff9e8e 100644 --- a/tests/unit/views/pricealarmTest.php +++ b/tests/unit/views/pricealarmTest.php @@ -3,6 +3,8 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\EshopCommunity\Core\DatabaseProvider; + require_once __DIR__ . '/../CaptchaTestCase.php'; class Unit_pricealarmTest extends CaptchaTestCase @@ -33,7 +35,7 @@ class Unit_pricealarmTest extends CaptchaTestCase $this->assertEquals(2, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus')); $query = 'select count(oxid) from oxpricealarm'; - $this->assertEquals(0, oxDb::getDb()->getOne($query)); + $this->assertEquals(0, DatabaseProvider::getDb()->getOne($query)); } /** @@ -50,7 +52,7 @@ class Unit_pricealarmTest extends CaptchaTestCase $this->assertEquals(0, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus')); $query = 'select count(oxid) from oxpricealarm'; - $this->assertEquals(0, oxDb::getDb()->getOne($query)); + $this->assertEquals(0, DatabaseProvider::getDb()->getOne($query)); } /** @@ -75,7 +77,7 @@ class Unit_pricealarmTest extends CaptchaTestCase $this->assertEquals(999, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus')); $query = 'select * from oxpricealarm'; - $alarm = oxDb::getDb(oxDB::FETCH_MODE_ASSOC)->getRow($query); + $alarm = DatabaseProvider::getDb(oxDB::FETCH_MODE_ASSOC)->getRow($query); $this->assertEquals($parameters['email'], $alarm['OXEMAIL']); $this->assertEquals($parameters['aid'], $alarm['OXARTID']); @@ -103,7 +105,7 @@ class Unit_pricealarmTest extends CaptchaTestCase $priceAlarm->addme(); $query = 'select oxlang from oxpricealarm'; - $language = oxDb::getDb(oxDB::FETCH_MODE_ASSOC)->getOne($query); + $language = DatabaseProvider::getDb(oxDB::FETCH_MODE_ASSOC)->getOne($query); $this->assertEquals(1, $language); } diff --git a/tests/unit/views/suggestTest.php b/tests/unit/views/suggestTest.php index c28a415..3324996 100644 --- a/tests/unit/views/suggestTest.php +++ b/tests/unit/views/suggestTest.php @@ -3,6 +3,8 @@ * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# */ +use OxidEsales\EshopCommunity\Core\DatabaseProvider; + require_once __DIR__ . '/../CaptchaTestCase.php'; class Unit_suggestTest extends CaptchaTestCase @@ -15,10 +17,10 @@ class Unit_suggestTest extends CaptchaTestCase protected function tearDown() { $sDelete = "delete from oxrecommlists where oxid like 'testlist%'"; - oxDb::getDB()->execute($sDelete); + DatabaseProvider::getDB()->execute($sDelete); $sDelete = "delete from oxobject2list where oxlistid like 'testlist%'"; - oxDb::getDB()->execute($sDelete); + DatabaseProvider::getDB()->execute($sDelete); parent::tearDown(); }