diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d21b32e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,24 @@ +# Change Log for OE Tags Module + +All notable changes to this project will be documented in this file. +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + +## [Unreleased] + +### Added + +### Changed +- Adapted the module to be compatible with OXID eShop 6. + +### Deprecated + +### Removed + +### Fixed + +### Security + + +[Unreleased]: https://github.com/OXIDprojects/captcha-module/compare/HEAD...HEAD diff --git a/views/admin/de/module_options.php b/application/views/admin/de/module_options.php similarity index 100% rename from views/admin/de/module_options.php rename to application/views/admin/de/module_options.php diff --git a/views/admin/en/module_options.php b/application/views/admin/en/module_options.php similarity index 100% rename from views/admin/en/module_options.php rename to application/views/admin/en/module_options.php diff --git a/views/blocks/captcha_form.tpl b/application/views/blocks/captcha_form.tpl similarity index 100% rename from views/blocks/captcha_form.tpl rename to application/views/blocks/captcha_form.tpl diff --git a/core/oecaptcha.php b/core/oecaptcha.php index 88ef8b8..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); @@ -110,10 +112,14 @@ class oeCaptcha extends oxSuperCfg */ public function getImageUrl() { - $url = $this->getConfig()->getCurrentShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac='; - $key = $this->getConfig()->getConfigParam('oecaptchakey'); - $key = empty($key) ? null : $key; - $url .= oxRegistry::getUtils()->strMan($this->getText(), $key); + $config = \OxidEsales\Eshop\Core\Registry::getConfig(); + $url = $config->getCurrentShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac='; + $key = $config->getConfigParam('oecaptchakey'); + + $key = $key ? $key : $config->getConfigParam('sConfigKey'); + + $encryptor = new \OxidEsales\Eshop\Core\Encryptor(); + $url .= $encryptor->encrypt($this->getText(), $key); return $url; } @@ -213,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/core/utils/verificationimg.php b/core/utils/verificationimg.php index b47a476..769931e 100644 --- a/core/utils/verificationimg.php +++ b/core/utils/verificationimg.php @@ -62,8 +62,6 @@ if (!function_exists('generateVerificationImg')) { if (!function_exists('strRem')) { - require_once getShopBasePath() . '/core/oxdecryptor.php'; - /** * OXID specific string manipulation method * @@ -73,10 +71,10 @@ if (!function_exists('strRem')) { */ function strRem($value) { - $decryptor = new oxDecryptor; - - $key = oxRegistry::getConfig()->getConfigParam('oecaptchakey'); + $decryptor = new \OxidEsales\Eshop\Core\Decryptor(); + $config = oxRegistry::getConfig(); + $key = $config->getConfigParam('oecaptchakey'); if (empty($key)) { $key = getOxConfKey(); } @@ -94,10 +92,9 @@ if (!function_exists('getOxConfKey')) { */ function getOxConfKey() { - $fileName = getShopBasePath() . '/core/oxconfk.php'; - $configFile = new oxConfigFile($fileName); - - return $configFile->getVar("sConfigKey"); + $config = oxRegistry::getConfig(); + $configKey = $config->getConfigParam('sConfigKey') ?: \OxidEsales\Eshop\Core\Config::DEFAULT_CONFIG_KEY; + return $configKey; } } diff --git a/metadata.php b/metadata.php index 2b11c23..3256dc1 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' => '', @@ -49,10 +49,10 @@ $aModule = array( ), 'templates' => array(), 'blocks' => array( - array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'file'=>'/views/blocks/captcha_form.tpl'), - array('template' => 'form/invite.tpl', 'block'=>'captcha_form', 'file'=>'/views/blocks/captcha_form.tpl'), - array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/views/blocks/captcha_form.tpl'), - array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/views/blocks/captcha_form.tpl'), + array('template' => 'form/contact.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/privatesales/invite.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/pricealarm.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), + array('template' => 'form/suggest.tpl', 'block'=>'captcha_form', 'file'=>'/application/views/blocks/captcha_form.tpl'), ), 'settings' => array( array('group' => 'main', 'name' => 'oecaptchakey', 'type' => 'str', 'value' => ''), diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 0000000..a9b2bc2 --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1,30 @@ + + + + ../ + + ../tests + ../translations + ../views + ../metadata.php + + + + \ No newline at end of file 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/application/component/widget/oeCaptchaWArticleDetailsTest.php b/tests/unit/application/component/widget/oeCaptchaWArticleDetailsTest.php new file mode 100644 index 0000000..9ac8dc5 --- /dev/null +++ b/tests/unit/application/component/widget/oeCaptchaWArticleDetailsTest.php @@ -0,0 +1,16 @@ +getCaptcha(); + $this->assertInstanceOf("oeCaptcha", $captcha); + } +} 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 fb7bd44..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); } /** @@ -78,7 +83,7 @@ class Unit_Core_oecaptchaTest extends CaptchaTestCase */ public function testGetImageUrl() { - $this->setConfigParam('oecaptchakey', 'someTestCaptchaKey'); + $this->getConfig()->setConfigParam("oecaptchakey", 'someTestCaptchaKey'); $this->captcha->setNonPublicVar('text', 'test1'); $expected = $this->getConfig()->getShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac=ox_MAsbCBYgVBoQ'; @@ -90,7 +95,7 @@ class Unit_Core_oecaptchaTest extends CaptchaTestCase */ public function testGetImageUrlFallbackKey() { - $this->setConfigParam('oecaptchakey', ''); + $this->getConfig()->setConfigParam("oecaptchakey", ''); $this->captcha->setNonPublicVar('text', 'test1'); $expected = $this->getConfig()->getShopUrl() . 'modules/oe/captcha/core/utils/verificationimg.php?e_mac=ox_MB4FUUYlYlld'; @@ -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(); }