1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-17 07:10:48 +03:00
This commit is contained in:
vatseek 2013-03-01 14:58:34 +02:00
parent 5df5eadeef
commit 7449a692d4
3 changed files with 198 additions and 88 deletions

View file

@ -35,7 +35,7 @@ before_script:
- 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
- wget -O /tmp/selenium-server-standalone.jar http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
- java -jar /tmp/selenium-server-standalone.jar > /dev/null &
- sleep 5

View file

@ -946,98 +946,162 @@ class ActionBlog extends Action {
$this->Viewer_SetResponseAjax('json');
$this->SubmitComment();
}
/**
* Проверка на соответсвие коментария требованиям безопасности
*
* @param ModuleTopic_EntityTopic $oTopic
* @param string $sText
*
* @return bool result
*/
protected function CheckComment($oTopic, $sText) {
$bOk = true;
/**
* Проверям авторизован ли пользователь
*/
if (!$this->User_IsAuthorization()) {
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем топик
*/
if (!$oTopic) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Возможность постить коммент в топик в черновиках
*/
if (!$oTopic->getPublish() and $this->oUserCurrent->getId()!=$oTopic->getUserId() and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем разрешено ли постить комменты
*/
if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем разрешено ли постить комменты по времени
*/
if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем запрет на добавления коммента автором топика
*/
if ($oTopic->getForbidComment()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_notallow'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем текст комментария
*/
if (!func_check($sText,'text',2,10000)) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'),$this->Lang_Get('error'));
$bOk = false;
}
$this->Hook_Run('comment_check', array('oTopic'=>$oTopic, 'sText'=>$sText, 'bOk'=>&$bOk));
return $bOk;
}
/**
* Проверка на соответсвие коментария родительскому коментарию
*
* @param ModuleTopic_EntityTopic $oTopic
* @param string $sText
* @param ModuleComment_EntityComment $oCommentParent
*
* @return bool result
*/
protected function CheckParentComment($oTopic, $sText, $oCommentParent) {
$sParentId = (int)getRequest('reply');
$bOk = true;
/**
* Проверям на какой коммент отвечаем
*/
if (!func_check($sParentId,'id')) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
$bOk = false;
}
if ($sParentId) {
/**
* Проверяем существует ли комментарий на который отвечаем
*/
if (!($oCommentParent)) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
$bOk = false;
}
/**
* Проверяем из одного топика ли новый коммент и тот на который отвечаем
*/
if ($oCommentParent->getTargetId()!=$oTopic->getId()) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
$bOk = false;
}
}
/**
* Проверка на дублирующий коммент
*/
if ($this->Comment_GetCommentUnique($oTopic->getId(),'topic',$this->oUserCurrent->getId(),$sParentId,md5($sText))) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'),$this->Lang_Get('error'));
$bOk = false;
}
$this->Hook_Run('comment_check_parent', array('oTopic'=>$oTopic, 'sText'=>$sText, 'oCommentParent'=>$oCommentParent, 'bOk'=>&$bOk));
return $bOk;
}
/**
* Обработка добавление комментария к топику
*
*/
protected function SubmitComment() {
/**
* Проверям авторизован ли пользователь
*/
if (!$this->User_IsAuthorization()) {
$this->Message_AddErrorSingle($this->Lang_Get('need_authorization'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем топик
*/
if (!($oTopic=$this->Topic_GetTopicById(getRequestStr('cmt_target_id')))) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
/**
* Возможность постить коммент в топик в черновиках
*/
if (!$oTopic->getPublish() and $this->oUserCurrent->getId()!=$oTopic->getUserId() and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем разрешено ли постить комменты
*/
if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем разрешено ли постить комменты по времени
*/
if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем запрет на добавления коммента автором топика
*/
if ($oTopic->getForbidComment()) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_notallow'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем текст комментария
*/
$sText=$this->Text_Parser(getRequestStr('comment_text'));
if (!func_check($sText,'text',2,10000)) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'),$this->Lang_Get('error'));
return;
}
/**
* Проверям на какой коммент отвечаем
*/
$sParentId=(int)getRequest('reply');
if (!func_check($sParentId,'id')) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
$oCommentParent=null;
if ($sParentId!=0) {
/**
* Проверяем существует ли комментарий на который отвечаем
*/
if (!($oCommentParent=$this->Comment_GetCommentById($sParentId))) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
/**
* Проверяем из одного топика ли новый коммент и тот на который отвечаем
*/
if ($oCommentParent->getTargetId()!=$oTopic->getId()) {
$this->Message_AddErrorSingle($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
} else {
/**
* Корневой комментарий
*/
$sParentId=null;
}
/**
* Проверка на дублирующий коммент
*/
if ($this->Comment_GetCommentUnique($oTopic->getId(),'topic',$this->oUserCurrent->getId(),$sParentId,md5($sText))) {
$this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'),$this->Lang_Get('error'));
return;
}
$oTopic = $this->Topic_GetTopicById(getRequestStr('cmt_target_id'));
$sText = $this->Text_Parser(getRequestStr('comment_text'));
$sParentId = (int)getRequest('reply');
$oCommentParent = null;
if (!$sParentId) {
/**
* Корневой комментарий
*/
$sParentId=null;
}
else {
/**
* Родительский комментарий
*/
$oCommentParent=$this->Comment_GetCommentById($sParentId);
}
/**
* Проверка на соответсвие коментария требованиям безопасности
*/
if (!$this->CheckComment($oTopic, $sText)) {
return;
}
/**
* Проверка на соответсвие коментария родительскому коментарию
*/
if (!$this->CheckParentComment($oTopic, $sText, $oCommentParent)) {
return;
}
/**
* Создаём коммент
*/

View file

@ -0,0 +1,46 @@
Feature: Test Base comment functionality (!!!SELENIUM NEEDED)
Test base functionality of Comments
@mink:selenium2
Scenario: Adding the comment
Given I am on "/login"
Then I want to login as "admin"
Given I am on homepage
Then I follow "Sony MicroVault Mach USB 3.0 flash drive"
Then I wait "1000"
Then I follow "Add comment"
And I fill in "test comment" for "comment_text"
And I press "Preview"
Then I wait "1000"
Then I should see in element by css "content .comment-preview" values:
| value |
| test comment |
And I press "Add"
Then I wait "1000"
Then I should see in element by css "content .comment-content" values:
| value |
| test comment |
Then I should see in element by css "content .comment-info" values:
| value |
| /profile/admin/">admin</a> |
| Reply |
| Delete |
#create subcomment
And I follow "Reply"
Then I wait "1000"
And I fill in "test subcomment" for "comment_text"
And I press "Add"
Then I wait "1000"
Then I should see in element by css "comment_wrapper_id_2" values:
| value |
| test subcomment |