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#
*/
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);

View File

@ -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);
}
/**

View File

@ -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' => '',

View File

@ -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();
}

View File

@ -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`");
}
/**

View File

@ -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));
}

View File

@ -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);
}

View File

@ -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();
}