OXDEV-338 Change oxDb to DatabaseProvider

This commit is contained in:
Anton Fedurtsya 2017-11-10 14:36:09 +02:00
parent c32f94a359
commit 623bf060da
8 changed files with 36 additions and 18 deletions

View File

@ -3,6 +3,8 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\Eshop\Core\DatabaseProvider;
/** /**
* Class handling CAPTCHA image * Class handling CAPTCHA image
* This class requires utility file utils/verificationimg.php as image generator * This class requires utility file utils/verificationimg.php as image generator
@ -76,7 +78,7 @@ class oeCaptcha extends oxSuperCfg
$hashArray[$hash] = array($textHash => $time); $hashArray[$hash] = array($textHash => $time);
$session->setVariable('captchaHashes', $hashArray); $session->setVariable('captchaHashes', $hashArray);
} else { } else {
$database = oxDb::getDb(); $database = DatabaseProvider::getDb();
$query = "insert into oecaptcha (oxhash, oxtime) values (" . $query = "insert into oecaptcha (oxhash, oxtime) values (" .
$database->quote($textHash) . ", " . $database->quote($time) . ")"; $database->quote($textHash) . ", " . $database->quote($time) . ")";
$database->execute($query); $database->execute($query);
@ -217,7 +219,7 @@ class oeCaptcha extends oxSuperCfg
*/ */
protected function passFromDb($macHash, $hash, $time) protected function passFromDb($macHash, $hash, $time)
{ {
$database = oxDb::getDb(); $database = DatabaseProvider::getDb();
$where = "where oxid = " . $database->quote($macHash) . " and oxhash = " . $database->quote($hash); $where = "where oxid = " . $database->quote($macHash) . " and oxhash = " . $database->quote($hash);
$query = "select 1 from oecaptcha " . $where; $query = "select 1 from oecaptcha " . $where;
$pass = (bool) $database->getOne($query, false, false); $pass = (bool) $database->getOne($query, false, false);

View File

@ -3,6 +3,7 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\Eshop\Core\DatabaseProvider;
/** /**
* Class defines what module does on Shop events. * Class defines what module does on Shop events.
@ -24,8 +25,7 @@ class oeCaptchaEvents
"KEY `OXTIME` (`OXTIME`) " . "KEY `OXTIME` (`OXTIME`) " .
") ENGINE=MEMORY AUTO_INCREMENT=1 COMMENT 'If session is not available, this is where captcha information is stored';"; ") 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`"; $query = "DROP TABLE IF EXISTS `oecaptcha`";
oxDb::getDb()->execute($query); DatabaseProvider::getDb()->execute($query);
} }
/** /**

View File

@ -33,7 +33,7 @@ $aModule = array(
'en' => 'OXID eSales Simple Captcha Module', 'en' => 'OXID eSales Simple Captcha Module',
), ),
'thumbnail' => 'out/pictures/picture.png', 'thumbnail' => 'out/pictures/picture.png',
'version' => '1.0.0', 'version' => '2.0.0',
'author' => 'OXID eSales AG', 'author' => 'OXID eSales AG',
'url' => 'http://www.oxid-esales.com/', 'url' => 'http://www.oxid-esales.com/',
'email' => '', 'email' => '',

View File

@ -3,7 +3,9 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
abstract class CaptchaTestCase extends OxidTestCase use OxidEsales\EshopCommunity\Core\DatabaseProvider;
abstract class CaptchaTestCase extends \OxidEsales\TestingLibrary\UnitTestCase
{ {
/** /**
* Fixture set up. * 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'; ) 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() protected function tearDown()
{ {
$query = "DROP TABLE `oecaptcha`"; $query = "DROP TABLE `oecaptcha`";
oxDb::getDb()->execute($query); DatabaseProvider::getDb()->execute($query);
parent::tearDown(); parent::tearDown();
} }

View File

@ -3,6 +3,8 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\EshopCommunity\Core\DatabaseProvider;
require_once __DIR__ . '/../CaptchaTestCase.php'; require_once __DIR__ . '/../CaptchaTestCase.php';
class Unit_Core_oecaptchaEventsTest extends CaptchaTestCase class Unit_Core_oecaptchaEventsTest extends CaptchaTestCase
@ -15,7 +17,7 @@ class Unit_Core_oecaptchaEventsTest extends CaptchaTestCase
parent::setUp(); parent::setUp();
//Drop captcha table //Drop captcha table
oxDb::getDB()->execute("DROP TABLE IF EXISTS `oecaptcha`"); DatabaseProvider::getDB()->execute("DROP TABLE IF EXISTS `oecaptcha`");
} }
/** /**

View File

@ -3,6 +3,8 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\EshopCommunity\Core\DatabaseProvider;
require_once __DIR__ . '/../CaptchaTestCase.php'; require_once __DIR__ . '/../CaptchaTestCase.php';
class Unit_Core_oecaptchaTest extends CaptchaTestCase 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)); $captcha->expects($this->once())->method('getSession')->will($this->returnValue($session));
$hash = $captcha->getHash('test'); $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->setSession($session);
$captcha->getHash('3at8u'); $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)); $this->assertTrue($captcha->pass('3at8u', $hash));
} }

View File

@ -3,6 +3,8 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\EshopCommunity\Core\DatabaseProvider;
require_once __DIR__ . '/../CaptchaTestCase.php'; require_once __DIR__ . '/../CaptchaTestCase.php';
class Unit_pricealarmTest extends CaptchaTestCase class Unit_pricealarmTest extends CaptchaTestCase
@ -33,7 +35,7 @@ class Unit_pricealarmTest extends CaptchaTestCase
$this->assertEquals(2, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus')); $this->assertEquals(2, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus'));
$query = 'select count(oxid) from oxpricealarm'; $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')); $this->assertEquals(0, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus'));
$query = 'select count(oxid) from oxpricealarm'; $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')); $this->assertEquals(999, $priceAlarm->getNonPublicVar('_iPriceAlarmStatus'));
$query = 'select * from oxpricealarm'; $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['email'], $alarm['OXEMAIL']);
$this->assertEquals($parameters['aid'], $alarm['OXARTID']); $this->assertEquals($parameters['aid'], $alarm['OXARTID']);
@ -103,7 +105,7 @@ class Unit_pricealarmTest extends CaptchaTestCase
$priceAlarm->addme(); $priceAlarm->addme();
$query = 'select oxlang from oxpricealarm'; $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); $this->assertEquals(1, $language);
} }

View File

@ -3,6 +3,8 @@
* #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION# * #PHPHEADER_OECAPTCHA_LICENSE_INFORMATION#
*/ */
use OxidEsales\EshopCommunity\Core\DatabaseProvider;
require_once __DIR__ . '/../CaptchaTestCase.php'; require_once __DIR__ . '/../CaptchaTestCase.php';
class Unit_suggestTest extends CaptchaTestCase class Unit_suggestTest extends CaptchaTestCase
@ -15,10 +17,10 @@ class Unit_suggestTest extends CaptchaTestCase
protected function tearDown() protected function tearDown()
{ {
$sDelete = "delete from oxrecommlists where oxid like 'testlist%'"; $sDelete = "delete from oxrecommlists where oxid like 'testlist%'";
oxDb::getDB()->execute($sDelete); DatabaseProvider::getDB()->execute($sDelete);
$sDelete = "delete from oxobject2list where oxlistid like 'testlist%'"; $sDelete = "delete from oxobject2list where oxlistid like 'testlist%'";
oxDb::getDB()->execute($sDelete); DatabaseProvider::getDB()->execute($sDelete);
parent::tearDown(); parent::tearDown();
} }