From 112aded810ae1c729aa2347a3cbc3e4f509473ef Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Thu, 9 Nov 2017 16:48:24 +0200 Subject: [PATCH 1/8] OXDEV-338 Add phpunit config for possibility to generate coverage --- tests/phpunit.xml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/phpunit.xml 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 From 8ea9c5db5d8ae0c96e49822fccb885374fc54446 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 09:30:52 +0200 Subject: [PATCH 2/8] OXDEV-338 Add test for articleDetails getCaptcha method --- .../widget/oeCaptchaWArticleDetailsTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/unit/application/component/widget/oeCaptchaWArticleDetailsTest.php 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); + } +} From c32f94a359dc322a8c9ae5af556d33575f0900f2 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 10:26:32 +0200 Subject: [PATCH 3/8] OXDEV-338 Fix removed strMan method usage --- core/oecaptcha.php | 12 ++++++++---- tests/unit/core/oecaptchaTest.php | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/oecaptcha.php b/core/oecaptcha.php index 88ef8b8..d086d25 100644 --- a/core/oecaptcha.php +++ b/core/oecaptcha.php @@ -110,10 +110,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; } diff --git a/tests/unit/core/oecaptchaTest.php b/tests/unit/core/oecaptchaTest.php index fb7bd44..12f2b30 100644 --- a/tests/unit/core/oecaptchaTest.php +++ b/tests/unit/core/oecaptchaTest.php @@ -78,7 +78,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 +90,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'; From 623bf060dad237828d8a9f772e076f78f4143ae4 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 14:36:09 +0200 Subject: [PATCH 4/8] 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(); } From e6b3ad312b02b071857534cacb0c2866c3d030f9 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 16:22:54 +0200 Subject: [PATCH 5/8] OXDEV-338 Fix config access in verification image generation --- core/utils/verificationimg.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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; } } From 8a650bf954aa5765856e36526dfb9fc39e10ab58 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Fri, 10 Nov 2017 16:23:33 +0200 Subject: [PATCH 6/8] OXDEV-338 Extend correct invite.tpl --- metadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.php b/metadata.php index 2f0a473..21b08aa 100755 --- a/metadata.php +++ b/metadata.php @@ -50,7 +50,7 @@ $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/privatesales/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'), ), From 47f8fcd8aef8a1b62923ec99cabda645dd374bb9 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Tue, 14 Nov 2017 13:07:34 +0200 Subject: [PATCH 7/8] OXDEV-338 Add changelog --- CHANGELOG.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CHANGELOG.md 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 From 985eb413d7f7735fef851a7fa0e6270348643093 Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Tue, 14 Nov 2017 14:46:36 +0200 Subject: [PATCH 8/8] OXDEV-338 Move views directory under application * If application directory exists, module translation loader looks for translations inside application/... directory. --- {views => application/views}/admin/de/module_options.php | 0 {views => application/views}/admin/en/module_options.php | 0 {views => application/views}/blocks/captcha_form.tpl | 0 metadata.php | 8 ++++---- 4 files changed, 4 insertions(+), 4 deletions(-) rename {views => application/views}/admin/de/module_options.php (100%) rename {views => application/views}/admin/en/module_options.php (100%) rename {views => application/views}/blocks/captcha_form.tpl (100%) 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/metadata.php b/metadata.php index 21b08aa..3256dc1 100755 --- a/metadata.php +++ b/metadata.php @@ -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/privatesales/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' => ''),