diff --git a/.gitignore b/.gitignore index 6b30f0f9..d277ae83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -/uploads/ -/templates/cache/ -/templates/compiled/ -/logs/ -/tmp/ -/config/config.local.php +config/config.local.php +config/config.test.php +logs/* +plugins/* +templates/cache/* +templates/compiled/* +tmp/* +uploads/* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..a85a93ca --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +language: php + +php: + - 5.3 + +before_script: + # export virtual display + - export DISPLAY=:99 + + # change application working folders for write access + - chmod -R 0777 ./tmp + - chmod -R 0777 ./uploads + - chmod -R 0777 ./templates/cache/ + - chmod -R 0777 ./templates/compiled/ + + # install required PHP stuff + - sudo apt-get install php5 php5-cli php5-mysql php5-mcrypt php5-xsl php5-xdebug php-apc php5-gd php5-curl php5-intl + + # launch apache, MySQL and PHPUnit Selenium installers + - ./tests/travis/apache_setup.sh + - ./tests/travis/mysql_setup.sh + - mysql -u root -e "USE social_test; SHOW TABLES;" + - cp ./config/config.test.php.dist config/config.test.php + - cp ./config/config.test.php.dist config/config.local.php + - sudo sed -i s/sql-mode/#sql-mode/ /etc/mysql/my.cnf + - sudo /etc/init.d/mysql restart + - sleep 5 + + # get HTML of main page (for debug) + - firefox --version + - wget -O /tmp/livestreet.test http://livestreet.test + - cat /tmp/livestreet.test + + # start virtual display + - sh -e /etc/init.d/xvfb start + - sleep 5 + + # download and launch Selenium + - wget -O /tmp/selenium-server-standalone.jar http://selenium.googlecode.com/files/selenium-server-standalone-2.25.0.jar + - java -jar /tmp/selenium-server-standalone.jar > /dev/null & + - sleep 5 + + # goto test's folder + - cd tests/behat/ + +script: HTTP_APP_ENV=test php behat.phar diff --git a/README.md b/README.md new file mode 100644 index 00000000..a9edbc5e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +[![Build Status](https://secure.travis-ci.org/stfalcon-studio/livestreet.png?branch=master)](https://travis-ci.org/stfalcon-studio/livestreet) + +Documentation +------------- + +* [English README](https://github.com/livestreet/livestreet/blob/master/Readme.EN.txt) +* [Russian README](https://github.com/livestreet/livestreet/blob/master/Readme.RU.txt) diff --git a/classes/hooks/HookMain.class.php b/classes/hooks/HookMain.class.php index bd27340d..217642e1 100644 --- a/classes/hooks/HookMain.class.php +++ b/classes/hooks/HookMain.class.php @@ -35,7 +35,7 @@ class HookMain extends Hook { /** * Проверяем наличие директории install */ - if(is_dir(rtrim(Config::Get('path.root.server'),'/').'/install')){ + if(is_dir(rtrim(Config::Get('path.root.server'),'/').'/install') && $_SERVER['HTTP_APP_ENV']!='test'){ $this->Message_AddErrorSingle($this->Lang_Get('install_directory_exists')); Router::Action('error'); } 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 new file mode 100644 index 00000000..34cb2888 --- /dev/null +++ b/config/config.test.php.dist @@ -0,0 +1,43 @@ + diff --git a/config/loader.php b/config/loader.php index 2d419ed6..9bdc89fa 100644 --- a/config/loader.php +++ b/config/loader.php @@ -48,7 +48,7 @@ if ($hDirConfig = opendir($sDirConfig)) { // то сливаем старые и новое значения ассоциативно Config::Set( $sKey, - func_array_merge_assoc(Config::Get($sKey), $aConfig) + func_array_merge_assoc(Config::Get($sKey), $aConfig) ); } } @@ -114,7 +114,7 @@ if ($hDirConfig = opendir($sDirConfig)) { // то сливаем старые и новое значения ассоциативно Config::Set( $sKey, - func_array_merge_assoc(Config::Get($sKey), $aConfig) + func_array_merge_assoc(Config::Get($sKey), $aConfig) ); } } @@ -124,14 +124,27 @@ if ($hDirConfig = opendir($sDirConfig)) { closedir($hDirConfig); } -/** - * Подгружаем файлы локального и продакшн-конфига - */ -if(file_exists(Config::Get('path.root.server').'/config/config.local.php')) { - Config::LoadFromFile(Config::Get('path.root.server').'/config/config.local.php',false); -} -if(file_exists(Config::Get('path.root.server').'/config/config.stable.php')) { - Config::LoadFromFile(Config::Get('path.root.server').'/config/config.stable.php',false); +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 { + /** + * Подгружаем файлы локального и продакшн-конфига + */ + if(file_exists(Config::Get('path.root.server').'/config/config.local.php')) { + Config::LoadFromFile(Config::Get('path.root.server').'/config/config.local.php',false); + } + if(file_exists(Config::Get('path.root.server').'/config/config.stable.php')) { + Config::LoadFromFile(Config::Get('path.root.server').'/config/config.stable.php',false); + } } /** @@ -157,7 +170,7 @@ if($aPluginsList=@file($sPluginsListFile)) { // то сливаем старые и новое значения ассоциативно Config::Set( $sKey, - func_array_merge_assoc(Config::Get($sKey), $aConfig) + func_array_merge_assoc(Config::Get($sKey), $aConfig) ); } } @@ -170,7 +183,7 @@ if($aPluginsList=@file($sPluginsListFile)) { if($aIncludeFiles and count($aIncludeFiles)) { foreach ($aIncludeFiles as $sPath) { require_once($sPath); - } + } } } } diff --git a/tests/.htaccess b/tests/.htaccess new file mode 100644 index 00000000..c3c2d19d --- /dev/null +++ b/tests/.htaccess @@ -0,0 +1,2 @@ +Order Deny,Allow +Deny from all diff --git a/tests/AbstractFixtures.php b/tests/AbstractFixtures.php new file mode 100644 index 00000000..bb931c26 --- /dev/null +++ b/tests/AbstractFixtures.php @@ -0,0 +1,87 @@ +oEngine = $oEngine; + $this->aReferences = $aReferences; + } + + /** + * Add reference + * + * @param string $name + * @param array $data + * @return void + */ + public function addReference($name, $data) + { + $this->aReferences[$name] = $data; + } + + /** + * Get reference by key + * + * @param string $key + * @throws Exception if reference is not exist + * @return array aReferences + * @return void + */ + public function getReference($key) + { + if (isset($this->aReferences[$key])) { + return $this->aReferences[$key]; + } + + throw new Exception("Fixture reference \"$key\" is not exist"); + } + + /** + * Get all references + * + * @return array aReferences + */ + public function getReferences() + { + return $this->aReferences; + } + + /** + * Creating entities and saving them to DB + * + * @return void + */ + abstract public function load(); + + /** + * Get order number for fixture + * + * @return int + */ + public static function getOrder() { + return 0; + } +} + diff --git a/tests/LoadFixtures.php b/tests/LoadFixtures.php new file mode 100644 index 00000000..97ef4ee1 --- /dev/null +++ b/tests/LoadFixtures.php @@ -0,0 +1,161 @@ +oEngine = Engine::getInstance(); + $this->oEngine->Init(); + $this->sDirFixtures = realpath((dirname(__FILE__)) . "/fixtures/"); + } + + public function load() { + $this->loadFixtures(); + } + + /** + * Recreate database from SQL dumps + * + * @return bool + */ + public function purgeDB() { + $sDbname = Config::Get('db.params.dbname'); + + if (mysql_select_db($sDbname)) { + + $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 sql.sql + $result = $this->oEngine->Database_ExportSQL(dirname(__FILE__) . '/fixtures/sql/sql.sql'); + + if (!$result['result']) { + // exception + throw new Exception("DB is not exported with file sql.sql"); + return $result['errors']; + } + echo "ExportSQL DATABASE $sDbname -> sql.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"; + + } + } + return true; + } + + /** + * Function of loading fixtures from tests/fixtures/ + * + * @var array $aFiles + * @var array $iOrder + * @return void + */ + private function loadFixtures() { + $aFiles = glob("{$this->sDirFixtures}/*Fixtures.php"); + $aFixtures = array(); + foreach ($aFiles as $sFilePath) { + require_once "{$sFilePath}"; + $iOrder = BlogFixtures::getOrder(); + + preg_match("/([a-zA-Z]+Fixtures).php$/", $sFilePath, $matches); + $sClassName = $matches[1]; + $iOrder = forward_static_call(array($sClassName, 'getOrder')); + $aFixtures[$iOrder][] = $sClassName; + } + ksort($aFixtures); + + if (count($aFixtures)) { + 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); + } + } + } + } + + /** + * Function of loading plugin fixtures + * + * @param string $plugin + * @return void + */ + 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); + } + + $this->sDirFixtures = $sPath; + $this->loadFixtures(); + } + + /** + * Function of activate plugin + * + * @param string $plugin + */ + public function activationPlugin($plugin){ + $this->oEngine->ModulePlugin_Toggle($plugin,'Activate'); + } + +} + diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..d21255b9 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,49 @@ +Запуск функциональных тестов +============================ + +Для запуска тестов проекта нужно: + +1) Переименовать файл config/config.test.php.dist в config/config.test.php и изменить настройки подключения к тестовой БД. +ВАЖНО! Информация в этой БД будет перезаписываться при каждом запуске теста. + +2) В конфиге для Behat (tests/behat/behat.yml) сменить значение опции base_url на хост, под которым проект доступен локально. + +3) Выполнить команду ```HTTP_APP_ENV=test php tests/behat/behat.phar -c tests/behat/behat.yml```. Примерный вывод результата работы команды: + +``` +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 + + Scenario: See main page # features/base.feature:4 + Given I am on homepage # FeatureContext::iAmOnHomepage() + When I press "Войти" # FeatureContext::pressButton() + Then the response status code should be 200 # FeatureContext::assertResponseStatus() + + Scenario: See Colective Blog # features/base.feature:9 + Given I am on "/blog/gadgets" # FeatureContext::visit() + Then I should see "Gadgets" # FeatureContext::assertPageContainsText() + Then I should see "Offers latest gadget reviews" # FeatureContext::assertPageContainsText() + + Scenario: See list of blogs # features/base.feature:14 + Given I am on "/blogs/" # FeatureContext::visit() + Then I should see "Gadgets" # FeatureContext::assertPageContainsText() + + Scenario: See All Topic # features/base.feature:18 + Given I am on "/index/newall/" # FeatureContext::visit() + Then I should see "iPad 3 rumored to come this March with quad-core chip and 4G LTE " # FeatureContext::assertPageContainsText() + Then I should see "Toshiba unveils 13.3-inch AT330 Android ICS 4.0 tablet" # FeatureContext::assertPageContainsText() + + Scenario: See User Profile # features/base.feature:23 + Given I am on "/profile/Golfer/" # FeatureContext::visit() + Then I should see "Sergey Doryba" # FeatureContext::assertPageContainsText() + Then I should see "... Sergey Doryba profile description" # FeatureContext::assertPageContainsText() + +5 scenarios (5 passed) +14 steps (14 passed) +0m2.225s +``` diff --git a/tests/behat/behat.phar b/tests/behat/behat.phar new file mode 100644 index 00000000..53c93748 Binary files /dev/null and b/tests/behat/behat.phar differ diff --git a/tests/behat/behat.yml b/tests/behat/behat.yml new file mode 100644 index 00000000..a2830cd6 --- /dev/null +++ b/tests/behat/behat.yml @@ -0,0 +1,13 @@ +# behat.yml +default: + extensions: + mink_extension.phar: + base_url: http://livestreet.test/ + default_session: goutte + mink_loader: mink.phar + goutte: + server_parameters: + APP_ENV: test + selenium2: + wd_host: 'http://127.0.0.1:4444/wd/hub' + capabilities: { "browser": "firefox", "browserVersion": "10", "browserName": "firefox", "version": "10"} diff --git a/tests/behat/features/base.feature b/tests/behat/features/base.feature new file mode 100644 index 00000000..ecdabe86 --- /dev/null +++ b/tests/behat/features/base.feature @@ -0,0 +1,42 @@ +Feature: LiveStreet standart features + Test base functionality of LiveStreet + + Scenario: See main page + Given I am on homepage + Then the response status code should be 200 + + Then I should see "Sony MicroVault Mach USB 3.0 flash drive" + Then I should see "Blogger's name golfer" + + Then I should see "iPad 3 rumored to come this March with quad-core chip and 4G LTE " + Then I should see "Toshiba unveils 13.3-inch AT330 Android ICS 4.0 tablet" + Then I should see "Gadgets" + + Scenario: See colective blog + Given I am on "/blog/gadgets" + Then the response status code should be 200 + + Then I should see "Gadgets" + Then I should see "Offers latest gadget reviews" + + Scenario: See list of all blogs + Given I am on "/blogs/" + Then the response status code should be 200 + + Then I should see "Gadgets" + Then I should see "golfer" + + Scenario: See all new topics + Given I am on "/index/newall/" + Then the response status code should be 200 + + Then I should see "Sony MicroVault Mach USB 3.0 flash drive" + Then I should see "iPad 3 rumored to come this March with quad-core chip and 4G LTE " + Then I should see "Toshiba unveils 13.3-inch AT330 Android ICS 4.0 tablet" + + Scenario: See user profile + Given I am on "/profile/Golfer/" + Then the response status code should be 200 + + Then I should see "Sergey Doryba" + Then I should see "... Sergey Doryba profile description" diff --git a/tests/behat/features/bootstrap/BaseFeatureContext.php b/tests/behat/features/bootstrap/BaseFeatureContext.php new file mode 100644 index 00000000..871ca3eb --- /dev/null +++ b/tests/behat/features/bootstrap/BaseFeatureContext.php @@ -0,0 +1,77 @@ +purgeDB(); + $fixturesLoader->load(); + } + + /** + * Loading fixture for plugin + * + * @Given /^I load fixtures for plugin "([^"]*)"$/ + */ + public function loadFixturesForPlugin($plugin) + { + $fixturesLoader = $this->getFixturesLoader(); + $fixturesLoader->loadPluginFixtures($plugin); + } + + + /** + * @Given /^I am activated plugin "([^"]*)"$/ + */ + public function ActivatedPlugin($plugin) + { + $pluginActivation = new LoadFixtures(); + $pluginActivation->activationPlugin($plugin); + } + + /** + * @Then /^I wait "([^"]*)"$/ + */ + public function iWait($time_wait) + { + $this->getSession()->wait($time_wait); + } + +} diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000..4ddf1abc --- /dev/null +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -0,0 +1,11 @@ +getReference('user-golfer'); + + /* @var $oBlogGadgets ModuleBlog_EntityBlog */ + $oBlogGadgets = Engine::GetEntity('Blog'); + $oBlogGadgets->setOwnerId($oUserStfalcon->getId()); + $oBlogGadgets->setTitle("Gadgets"); + $oBlogGadgets->setDescription('Offers latest gadget reviews'); + $oBlogGadgets->setType('open'); + $oBlogGadgets->setDateAdd(date("Y-m-d H:i:s")); // @todo freeze + $oBlogGadgets->setUrl('gadgets'); + $oBlogGadgets->setLimitRatingTopic(0); + + $this->oEngine->Blog_AddBlog($oBlogGadgets); + + $this->addReference('blog-gadgets', $oBlogGadgets); + } +} + diff --git a/tests/fixtures/TopicFixtures.php b/tests/fixtures/TopicFixtures.php new file mode 100644 index 00000000..ddfde830 --- /dev/null +++ b/tests/fixtures/TopicFixtures.php @@ -0,0 +1,78 @@ +getReference('user-golfer'); + $oBlogGadgets = $this->getReference('blog-gadgets'); + + $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', '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', '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', '2012-10-21 2:30:40'); + $this->addReference('topic-sony', $oTopicSony); + } + + /** + * Create topic with default values + * + * @param int $iBlogId + * @param int $iUserId + * @param string $sTitle + * @param string $sText + * @param string $sTags + * @param string $sDate + * + * @return ModuleTopic_EntityTopic + */ + private function _createTopic($iBlogId, $iUserId, $sTitle, $sText, $sTags, $sDate) + { + $oTopic = Engine::GetEntity('Topic'); + /* @var $oTopic ModuleTopic_EntityTopic */ + $oTopic->setBlogId($iBlogId); + $oTopic->setUserId($iUserId); + $oTopic->setUserIp('127.0.0.1'); + $oTopic->setForbidComment(false); + $oTopic->setType('topic'); + $oTopic->setTitle($sTitle); + $oTopic->setPublish(true); + $oTopic->setPublishIndex(true); + $oTopic->setPublishDraft(true); + $oTopic->setDateAdd($sDate); + $oTopic->setTextSource($sText); + list($sTextShort, $sTextNew, $sTextCut) = $this->oEngine->Text_Cut($oTopic->getTextSource()); + + $oTopic->setCutText($sTextCut); + $oTopic->setText($this->oEngine->Text_Parser($sTextNew)); + $oTopic->setTextShort($this->oEngine->Text_Parser($sTextShort)); + + $oTopic->setTextHash(md5($oTopic->getType() . $oTopic->getTextSource() . $oTopic->getTitle())); + $oTopic->setTags($sTags); + + $this->oEngine->Topic_AddTopic($oTopic); + + return $oTopic; + } +} \ No newline at end of file diff --git a/tests/fixtures/UserFixtures.php b/tests/fixtures/UserFixtures.php new file mode 100644 index 00000000..ad510383 --- /dev/null +++ b/tests/fixtures/UserFixtures.php @@ -0,0 +1,36 @@ +setLogin('golfer'); + $oUserGolfer->setPassword(md5('qwerty')); + $oUserGolfer->setMail('golfer@gmail.com'); + + $oUserGolfer->setUserDateRegister(date("Y-m-d H:i:s")); // @todo freeze + $oUserGolfer->setUserIpRegister('127.0.0.1'); + $oUserGolfer->setUserActivate('1'); + $oUserGolfer->setUserActivateKey('0'); + + $this->oEngine->User_Add($oUserGolfer); + + $oUserGolfer->setProfileName('Sergey Doryba'); + $oUserGolfer->setProfileAbout('... Sergey Doryba profile description'); + $oUserGolfer->setProfileSex('man'); + + $this->oEngine->User_Update($oUserGolfer); + $this->addReference('user-golfer', $oUserGolfer); + } + +} + diff --git a/tests/fixtures/sql/geo_base.sql b/tests/fixtures/sql/geo_base.sql new file mode 120000 index 00000000..200d2737 --- /dev/null +++ b/tests/fixtures/sql/geo_base.sql @@ -0,0 +1 @@ +../../../install/geo_base.sql \ No newline at end of file diff --git a/tests/fixtures/sql/sql.sql b/tests/fixtures/sql/sql.sql new file mode 120000 index 00000000..a3b0f474 --- /dev/null +++ b/tests/fixtures/sql/sql.sql @@ -0,0 +1 @@ +../../../install/sql.sql \ No newline at end of file diff --git a/tests/travis/apache_setup.sh b/tests/travis/apache_setup.sh new file mode 100755 index 00000000..a26ce801 --- /dev/null +++ b/tests/travis/apache_setup.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +sudo apt-get install apache2 libapache2-mod-php5 curl +sudo a2enmod rewrite +echo "$(curl -fsSL https://raw.github.com/stfalcon-studio/livestreet/master/tests/travis/configs/apache_vhost)" | sed -e "s,PATH,`pwd`,g" | sudo tee -a /etc/apache2/sites-available/default > /dev/null +echo "$(curl -fsSL https://raw.github.com/stfalcon-studio/livestreet/master/tests/travis/configs/hosts)" | sudo tee -a /etc/hosts > /dev/null +sudo service apache2 restart diff --git a/tests/travis/configs/apache_vhost b/tests/travis/configs/apache_vhost new file mode 100644 index 00000000..a8fc5a07 --- /dev/null +++ b/tests/travis/configs/apache_vhost @@ -0,0 +1,29 @@ + + ServerAdmin webmaster@localhost + + DocumentRoot PATH + ServerName livestreet.test + + ErrorLog ${APACHE_LOG_DIR}/livestreet.log + + # Possible values include: debug, info, notice, warn, error, crit, + # alert, emerg. + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/livestreet.log combined + + + + ServerAdmin webmaster@localhost + + DocumentRoot PATH + ServerName livestreet.test + + ErrorLog ${APACHE_LOG_DIR}/livestreet.log + + # Possible values include: debug, info, notice, warn, error, crit, + # alert, emerg. + LogLevel warn + + CustomLog ${APACHE_LOG_DIR}/livestreet.log combined + diff --git a/tests/travis/configs/hosts b/tests/travis/configs/hosts new file mode 100644 index 00000000..1dba4f49 --- /dev/null +++ b/tests/travis/configs/hosts @@ -0,0 +1 @@ +127.0.0.1 livestreet.test diff --git a/tests/travis/mysql_setup.sh b/tests/travis/mysql_setup.sh new file mode 100755 index 00000000..665a41be --- /dev/null +++ b/tests/travis/mysql_setup.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +sudo apt-get install mysql-server mysql-client +mysql -u root -e 'CREATE DATABASE social_test;' +mysql -u root -B social_test < ./tests/fixtures/sql/sql.sql +mysql -u root -B social_test < ./tests/fixtures/sql/geo_base.sql