diff --git a/classes/modules/user/entity/User.entity.class.php b/classes/modules/user/entity/User.entity.class.php index 4d061df7..a1f0d356 100644 --- a/classes/modules/user/entity/User.entity.class.php +++ b/classes/modules/user/entity/User.entity.class.php @@ -22,6 +22,19 @@ * @since 1.0 */ class ModuleUser_EntityUser extends Entity { + /** + * Определяем дополнительные правила валидации + * + * @param array + */ + public function __construct($aParam = false) { + if (Config::Get('module.user.captcha_use_registration')) { + $this->aValidateRules[] = array('captcha', 'captcha', 'on' => array('registration')); + } + + parent::__construct($aParam); + } + /** * Определяем правила валидации * @@ -32,7 +45,6 @@ class ModuleUser_EntityUser extends Entity { array('login','login_exists','on'=>array('registration')), array('mail','email','allowEmpty'=>false,'on'=>array('registration','')), array('mail','mail_exists','on'=>array('registration')), - array('captcha','captcha','on'=>array('registration')), array('password','string','allowEmpty'=>false,'min'=>5,'on'=>array('registration')), array('password_confirm','compare','compareField'=>'password','on'=>array('registration')), ); diff --git a/config/config.php b/config/config.php index 367bc402..4ef783c1 100644 --- a/config/config.php +++ b/config/config.php @@ -58,7 +58,12 @@ $config['pagination']['pages']['count'] = 4; // количес * и возможно придёться увеличить значение $config['path']['offset_request_url'] на число вложенных директорий, * например, для директории первой вложенности www.site.ru/livestreet/ поставить значение равное 1 */ -$config['path']['root']['web'] = 'http://'.$_SERVER['HTTP_HOST']; // полный WEB адрес сайта +if (isset($_SERVER['HTTP_HOST'])) { + $config['path']['root']['web'] = 'http://'.$_SERVER['HTTP_HOST']; // полный WEB адрес сайта +} else { + // for CLI scripts. or you can append "HTTP_HOST=http://yoursite.url" before script run command + $config['path']['root']['web'] = null; +} $config['path']['root']['server'] = dirname(dirname(__FILE__)); // полный путь до сайта в файловой системе /** * Для CLI режима использовать @@ -205,6 +210,8 @@ $config['module']['user']['usernote_per_page'] = 20; // Число зам $config['module']['user']['userfield_max_identical'] = 2; // Максимальное число контактов одного типа $config['module']['user']['profile_photo_width'] = 250; // ширина квадрата фотографии в профиле, px $config['module']['user']['name_max'] = 30; // максимальная длинна имени в профиле пользователя +$config['module']['user']['captcha_use_registration'] = true; // проверять поле капчи при регистрации пользователя + // Модуль Comment $config['module']['comment']['per_page'] = 20; // Число комментариев на одну страницу(это касается только полного списка комментариев прямого эфира) $config['module']['comment']['bad'] = -5; // Рейтинг комментария, начиная с которого он будет скрыт @@ -524,7 +531,7 @@ $config['head']['default']['js'] = array( $config['head']['default']['css'] = array( "___path.static.skin___/css/reset.css", "___path.root.engine_lib___/external/jquery/markitup/skins/simple/style.css", - "___path.root.engine_lib___/external/jquery/markitup/sets/default/style.css", + "___path.root.engine_lib___/external/jquery/markitup/sets/default/style.css", "___path.root.engine_lib___/external/jquery/jcrop/jquery.Jcrop.css", "___path.root.engine_lib___/external/prettify/prettify.css", "___path.static.skin___/css/main.css", diff --git a/config/config.test.php.dist b/config/config.test.php.dist index 61ea5301..93be5981 100644 --- a/config/config.test.php.dist +++ b/config/config.test.php.dist @@ -34,5 +34,7 @@ $config['db']['table']['prefix'] = 'prefix_'; $config['sys']['cache']['use'] = false; // использовать кеширование или нет $config['sys']['cache']['solid'] = false; +$config['module']['user']['captcha_use_registration'] = false; // проверять поле капчи при регистрации пользователя + return $config; ?> \ No newline at end of file diff --git a/config/loader.php b/config/loader.php index 1ff19fdc..9bdc89fa 100644 --- a/config/loader.php +++ b/config/loader.php @@ -130,6 +130,10 @@ if(isset($_SERVER['HTTP_APP_ENV']) && $_SERVER['HTTP_APP_ENV']=='test') { */ if(file_exists(Config::Get('path.root.server').'/config/config.test.php')) { Config::LoadFromFile(Config::Get('path.root.server').'/config/config.test.php',false); + } else { + throw new Exception("Config for test envirenment is not found. + Rename /config/config.test.php.dist to /config/config.test.php and rewrite DB settings. + After that check base_url in /test/behat/behat.yml it option must be correct site url."); } } else { /** diff --git a/tests/LoadFixtures.php b/tests/LoadFixtures.php index 73f57b7f..4f77e609 100644 --- a/tests/LoadFixtures.php +++ b/tests/LoadFixtures.php @@ -17,8 +17,8 @@ class LoadFixtures private $aReferences = array(); /** - * @var Engine - */ + * @var Engine + */ private $oEngine; /** @@ -29,10 +29,6 @@ class LoadFixtures private $sDirFixtures; public function __construct() { - if (file_exists(Config::Get('path.root.server') . '/config/config.test.php')) { - Config::LoadFromFile(Config::Get('path.root.server') . '/config/config.test.php', false); - } - $this->oEngine = Engine::getInstance(); $this->oEngine->Init(); $this->sDirFixtures = realpath((dirname(__FILE__)) . "/fixtures/"); @@ -47,40 +43,58 @@ class LoadFixtures * * @return bool */ - public function purgeDB() { + public function purgeDB() { $sDbname = Config::Get('db.params.dbname'); if (mysql_select_db($sDbname)) { - mysql_query("DROP DATABASE $sDbname"); - echo "DROP DATABASE $sDbname \n"; + + $result = mysql_query("SELECT concat('TRUNCATE TABLE ', TABLE_NAME) + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA = '" . $sDbname . "'"); + + mysql_query('SET FOREIGN_KEY_CHECKS = 0'); + echo "TRUNCATE TABLE FROM TEST BASE"; + while ($row = mysql_fetch_row($result)) { + if (!mysql_query($row[0])) { + // exception + throw new Exception("TRUNCATE TABLE FROM TEST BASE - Exception"); + } + } + mysql_query('SET FOREIGN_KEY_CHECKS = 1'); + + mysql_free_result($result); + } else { + + if (mysql_query("CREATE DATABASE IF NOT EXISTS $sDbname") === false) { + // exception + throw new Exception("DB \"$sDbname\" is not Created"); + echo "CREATE DATABASE $sDbname \n"; + return mysql_error(); + } else { + + mysql_select_db($sDbname); + + // Load dump from install_base.sql + $result = $this->oEngine->Database_ExportSQL(dirname(__FILE__) . '/fixtures/sql/install_base.sql'); + + if (!$result['result']) { + // exception + throw new Exception("DB is not exported with file install_base.sql"); + return $result['errors']; + } + echo "ExportSQL DATABASE $sDbname -> install_base.sql \n"; + // Load dump from geo_base.sql + $result = $this->oEngine->Database_ExportSQL(dirname(__FILE__) . '/fixtures/sql/geo_base.sql'); + + if (!$result['result']) { + // exception + throw new Exception("DB is not exported with file geo_base.sql"); + return $result['errors']; + } + echo "ExportSQL DATABASE $sDbname -> geo_base \n"; + + } } - - if (mysql_query("CREATE DATABASE $sDbname") === false) { - return mysql_error(); - } - echo "CREATE DATABASE $sDbname \n"; - - if (mysql_select_db($sDbname) === false) { - return mysql_error(); - } - - echo "SELECTED DATABASE $sDbname \n"; - // Load dump from install_base.sql - $result = $this->oEngine->Database_ExportSQL(dirname(__FILE__) . '/fixtures/sql/install_base.sql'); - - if (!$result['result']) { - return $result['errors']; - } - // Load dump from geo_base.sql - $result = $this->oEngine->Database_ExportSQL(dirname(__FILE__) . '/fixtures/sql/geo_base.sql'); - - if (!$result['result']) { - return $result['errors']; - } - - echo "ExportSQL DATABASE $sDbname \n"; - echo "ExportSQL DATABASE $sDbname -> geo_base \n"; - return true; } @@ -101,22 +115,19 @@ class LoadFixtures preg_match("/([a-zA-Z]+Fixtures).php$/", $sFilePath, $matches); $sClassName = $matches[1]; $iOrder = forward_static_call(array($sClassName, 'getOrder')); - if (!array_key_exists($iOrder, $aFixtures)) { - $aFixtures[$iOrder] = $sClassName; - } else { - //@todo разруливание одинаковых ордеров - throw new Exception("Duplicated order number $iOrder in $sClassName"); - } + $aFixtures[$iOrder][] = $sClassName; } ksort($aFixtures); if (count($aFixtures)) { - foreach ($aFixtures as $iOrder => $sClassName) { - // @todo референсы дублируются в каждом объекте фиксту + в этом объекте - $oFixtures = new $sClassName($this->oEngine, $this->aReferences); - $oFixtures->load(); - $aFixtureReference = $oFixtures->getReferences(); - $this->aReferences = array_merge($this->aReferences, $aFixtureReference); + foreach ($aFixtures as $iOrder => $aClassNames) { + foreach ($aClassNames as $sClassName) { + // @todo референсы дублируются в каждом объекте фиксту + в этом объекте + $oFixtures = new $sClassName($this->oEngine, $this->aReferences); + $oFixtures->load(); + $aFixtureReference = $oFixtures->getReferences(); + $this->aReferences = array_merge($this->aReferences, $aFixtureReference); + } } } } @@ -127,8 +138,8 @@ class LoadFixtures * @param string $plugin * @return void */ - public function loadPluginFixtures($plugin){ - $sPath = Config::Get('path.root.server').'/plugins/' . $plugin . '/tests/fixtures'; + public function loadPluginFixtures($plugin) { + $sPath = Config::Get('path.root.server') . '/plugins/' . $plugin . '/tests/fixtures'; if (!is_dir($sPath)) { throw new InvalidArgumentException('Plugin not found by LS directory: ' . $sPath, 10); } @@ -137,5 +148,14 @@ class LoadFixtures $this->loadFixtures(); } + /** + * Function of activate plugin + * + * @param string $plugin + */ + public function activationPlugin($plugin){ + $this->oEngine->ModulePlugin_Toggle($plugin,'Activate'); + } + } diff --git a/tests/Readme.RU.md b/tests/Readme.RU.md index eb3d2b66..31cc675e 100644 --- a/tests/Readme.RU.md +++ b/tests/Readme.RU.md @@ -8,14 +8,14 @@ 2) В конфиге для Behat (tests/behat/behat.yml) сменить значение опции base_url на хост, под которым проект доступен локально. -3) Выполнить команду ```cd tests/behat; php behat.phar```. Примерный вывод результата работы команды: +3) Выполнить команду ```cd tests/behat; HTTP_APP_ENV=test php behat.phar```. Примерный вывод результата работы команды: ``` -DROP DATABASE social_test -CREATE DATABASE social_test -SELECTED DATABASE social_test -ExportSQL DATABASE social_test -ExportSQL DATABASE social_test -> geo_base +DROP DATABASE social_test +CREATE DATABASE social_test +SELECTED DATABASE social_test +ExportSQL DATABASE social_test +ExportSQL DATABASE social_test -> geo_base Feature: LiveStreet standart features Test base functionality of LiveStreet diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 39676f9f..912ba237 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -37,7 +37,7 @@ class FeatureContext extends MinkContext /** * Purge DB and load fixtures before running each test * - * @BeforeSuite + * @BeforeScenario */ public static function prepare($event){ $fixturesLoader = self::getFixturesLoader(); @@ -56,4 +56,14 @@ class FeatureContext extends MinkContext $fixturesLoader->loadPluginFixtures($plugin); } + + /** + * @Given /^I am activated plugin "([^"]*)"$/ + */ + public function ActivatedPlugin($plugin) + { + $pluginActivation = new LoadFixtures(); + $pluginActivation->activationPlugin($plugin); + } + } diff --git a/tests/fixtures/TopicFixtures.php b/tests/fixtures/TopicFixtures.php index 9c91f375..ddfde830 100644 --- a/tests/fixtures/TopicFixtures.php +++ b/tests/fixtures/TopicFixtures.php @@ -18,20 +18,20 @@ class TopicFixtures extends AbstractFixtures $oTopicToshiba = $this->_createTopic($oBlogGadgets->getBlogId(), $oUserGolfer->getId(), 'Toshiba unveils 13.3-inch AT330 Android ICS 4.0 tablet', 'Toshiba is to add a new Android 4.0 ICS to the mass which is known as Toshiba AT330. The device is equipped with a multi-touch capacitive touch display that packs a resolution of 1920 x 1200 pixels. The Toshiba AT330 tablet is currently at its prototype stage. We have very little details about the tablet, knowing that it’ll come equipped with HDMI port, on-board 32GB storage that’s expandable via an full-sized SD card slot. It’ll also have a built-in TV tuner and a collapsible antenna.It’ll also run an NVIDIA Tegra 3 quad-core processor. Other goodies will be a 1.3MP front-facing camera and a 5MP rear-facing camera. Currently, there is no information about its price and availability. A clip is included below showing it in action.', - 'gadget'); + 'gadget', '2012-10-21 00:10:20'); $this->addReference('topic-toshiba', $oTopicToshiba); $oTopicIpad = $this->_createTopic($oBlogGadgets->getBlogId(), $oUserGolfer->getId(), 'iPad 3 rumored to come this March with quad-core chip and 4G LTE', 'Another rumor for the iPad 3 has surfaced with some details given by Bloomberg, claiming that the iPad 3 production is already underway and will be ready for a launch as early as March.', - 'apple, ipad'); + 'apple, ipad', '2012-10-21 1:20:30'); $this->addReference('topic-ipad', $oTopicIpad); $oPersonalBlogGolfer = $this->oEngine->Blog_GetPersonalBlogByUserId($oUserGolfer->getId()); $oTopicSony = $this->_createTopic($oPersonalBlogGolfer->getBlogId(), $oUserGolfer->getId(), 'Sony MicroVault Mach USB 3.0 flash drive', 'Want more speeds and better protection for your data? The Sony MicroVault Mach flash USB 3.0 drive is what you need. It offers the USB 3.0 interface that delivers data at super high speeds of up to 5Gbps. It’s also backward compatible with USB 2.0.', - 'sony, flash, gadget'); + 'sony, flash, gadget', '2012-10-21 2:30:40'); $this->addReference('topic-sony', $oTopicSony); } @@ -43,10 +43,11 @@ class TopicFixtures extends AbstractFixtures * @param string $sTitle * @param string $sText * @param string $sTags + * @param string $sDate * * @return ModuleTopic_EntityTopic */ - private function _createTopic($iBlogId, $iUserId, $sTitle, $sText, $sTags) + private function _createTopic($iBlogId, $iUserId, $sTitle, $sText, $sTags, $sDate) { $oTopic = Engine::GetEntity('Topic'); /* @var $oTopic ModuleTopic_EntityTopic */ @@ -59,7 +60,7 @@ class TopicFixtures extends AbstractFixtures $oTopic->setPublish(true); $oTopic->setPublishIndex(true); $oTopic->setPublishDraft(true); - $oTopic->setDateAdd(date("Y-m-d H:i:s")); // @todo freeze + $oTopic->setDateAdd($sDate); $oTopic->setTextSource($sText); list($sTextShort, $sTextNew, $sTextCut) = $this->oEngine->Text_Cut($oTopic->getTextSource()); @@ -74,5 +75,4 @@ class TopicFixtures extends AbstractFixtures return $oTopic; } -} - +} \ No newline at end of file