Minor - Update from 1.11.x

pull/3016/head
Julio Montoya 5 years ago
parent 79a014d6dc
commit 5f14b9defb
  1. 31
      tests/behat/features/bootstrap/FeatureContext.php
  2. 15
      tests/behat/features/toolExercise.feature
  3. 79
      tests/scripts/fix_documents_path.php

@ -274,6 +274,24 @@ class FeatureContext extends MinkContext
); );
} }
/**
* @Then /^I fill the only ckeditor in the page with "([^"]*)"$/
*/
public function iFillTheOnlyEditorInThePage($value)
{
// Just in case wait that ckeditor is loaded
$this->getSession()->wait(2000);
$this->getSession()->executeScript(
"
var textarea = $('textarea');
var id = textarea.attr('id');
CKEDITOR.instances[id].setData(\"$value\");
"
);
}
/** /**
* @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/ * @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/
*/ */
@ -367,6 +385,19 @@ class FeatureContext extends MinkContext
"); ");
} }
/**
* @When /^(?:|I )fill in select "(?P<field>(?:[^"]|\\")*)" with option value "(?P<value>(?:[^"]|\\")*)" with class "(?P<id>(?:[^"]|\\")*)"$/
*/
public function iFillInSelectWithOptionValue($field, $value, $class)
{
$this->getSession()->wait(1000);
$this->getSession()->executeScript("
var input = $('$field').filter('$class');
var id = input.attr('id');
var input = $('#'+id);
input.val($value);
");
}
/** /**
* @When /^wait for the page to be loaded$/ * @When /^wait for the page to be loaded$/

@ -291,7 +291,8 @@ Feature: Exercise tool
Then I select "B" from "choice_id_4_2" Then I select "B" from "choice_id_4_2"
Then I press "Next question" Then I press "Next question"
# Question 5 - Open question # Question 5 - Open question
#Then I fill in ckeditor field "<string>" with "<string>" Then wait for the page to be loaded
Then I fill the only ckeditor in the page with "Hello you"
Then wait for the page to be loaded Then wait for the page to be loaded
Then I press "Next question" Then I press "Next question"
# Question 6 - Oral question # Question 6 - Oral question
@ -314,6 +315,7 @@ Feature: Exercise tool
# Question 11 - Global multiple answer # Question 11 - Global multiple answer
Then I check "Answer true" Then I check "Answer true"
Then I press "End test" Then I press "End test"
Then I should see "Hello you"
Then I should see "Score for the test: 83 / 117" Then I should see "Score for the test: 83 / 117"
Scenario: Check exercise result Scenario: Check exercise result
@ -322,9 +324,18 @@ Feature: Exercise tool
And I follow "Edit" And I follow "Edit"
And I follow "Results and feedback" And I follow "Results and feedback"
Then I should see "Learner score" Then I should see "Learner score"
And wait for the page to be loaded And wait very long for the page to be loaded
And I follow "Grade activity" And I follow "Grade activity"
Then I should see "Score for the test: 83 / 117" Then I should see "Score for the test: 83 / 117"
And I press "Edit individual feedback and grade the open question"
And I should see "Assign a grade"
And I fill the only ckeditor in the page with "open question teacher answer"
And I fill in select "select[name=marks]" with option value "10" with class ".grade_select"
Then I press "Correct test"
And wait very long for the page to be loaded
And I follow "Edit"
Then I should see "open question teacher answer"
And I should see "Score for the test: 93 / 117"
Scenario: Create a session "Session Exercise" and add user "acostea" Scenario: Create a session "Session Exercise" and add user "acostea"
Given I am on "/main/session/session_add.php" Given I am on "/main/session/session_add.php"

@ -32,7 +32,17 @@ $courses = CourseManager::get_courses_list();
$newUrlAppend = '/NEWFOLDER'; // Url append of new portal $newUrlAppend = '/NEWFOLDER'; // Url append of new portal
$slashes = '/../../../../../../../'; $slashes = '/../../../../../../../';
$pathToSearch = '#http(.*)://(.*)'.$slashes.'([^/]+)/(.*)#'; //$pathToSearch = '#http(.*)://(.*)'.$slashes.'([^/]+)/(.*)/#';
$pathToSearch = '#(http:\/\/\s*|https:\/\/\s*)?(www\s*)?(?(1)([.]\s*))?(?(2)([.]\s*))?([a-zA-Z0-9.-]{2,256})(\s*[.]\s*)(com|fr|)('.$slashes.')(.*?)/(.*?)/(.*?)/#';
$pathToReplace = $newUrlAppend.'/courses/${10}/${11}/';
// tests
/*
$contents = 'http://something.fr/../../../../../../../courses-lt-marie-chamilo/ABC/document/images/gallery/science.jpg';
$contents .= '<br />http://something.something.fr/../../../../../../../courses-lt-marie-chamilo/CDE/document/science.jpg';
$newContent = preg_replace($pathToSearch, $pathToReplace, $contents);
echo $newContent;
exit;*/
$courseSysPath = api_get_path(SYS_COURSE_PATH); $courseSysPath = api_get_path(SYS_COURSE_PATH);
foreach ($courses as $course) { foreach ($courses as $course) {
@ -47,7 +57,7 @@ foreach ($courses as $course) {
foreach ($finder as $file) { foreach ($finder as $file) {
echo $file->getRealPath().'<br />'; echo $file->getRealPath().'<br />';
$contents = file_get_contents($file->getRealPath()); $contents = file_get_contents($file->getRealPath());
$newContent = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $contents); $newContent = preg_replace($pathToSearch, $pathToReplace, $contents);
file_put_contents($file->getRealPath(), $newContent); file_put_contents($file->getRealPath(), $newContent);
} }
@ -57,7 +67,7 @@ foreach ($courses as $course) {
$items = Database::store_result($result); $items = Database::store_result($result);
foreach ($items as $item) { foreach ($items as $item) {
$id = $item['iid']; $id = $item['iid'];
$newContent = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); $newContent = preg_replace($pathToSearch, $pathToReplace, $item['description']);
$newContent = Database::escape_string($newContent); $newContent = Database::escape_string($newContent);
$sql = "UPDATE c_quiz SET description = '$newContent' WHERE iid = $id"; $sql = "UPDATE c_quiz SET description = '$newContent' WHERE iid = $id";
Database::query($sql); Database::query($sql);
@ -69,13 +79,13 @@ foreach ($courses as $course) {
$items = Database::store_result($result); $items = Database::store_result($result);
foreach ($items as $item) { foreach ($items as $item) {
$id = $item['iid']; $id = $item['iid'];
$description = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); $description = preg_replace($pathToSearch, $pathToReplace, $item['description']);
$description = Database::escape_string($description); $description = Database::escape_string($description);
$question = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['question']); $question = preg_replace($pathToSearch, $pathToReplace, $item['question']);
$question = Database::escape_string($question); $question = Database::escape_string($question);
$sql = "UPDATE c_quiz_question SET $sql = "UPDATE c_quiz_question SET
description = '$description', description = '$description',
question = '$question' question = '$question'
WHERE iid = $id"; WHERE iid = $id";
@ -88,13 +98,13 @@ foreach ($courses as $course) {
$items = Database::store_result($result); $items = Database::store_result($result);
foreach ($items as $item) { foreach ($items as $item) {
$id = $item['iid']; $id = $item['iid'];
$answer = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['answer']); $answer = preg_replace($pathToSearch, $pathToReplace, $item['answer']);
$answer = Database::escape_string($answer); $answer = Database::escape_string($answer);
$comment = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['comment']); $comment = preg_replace($pathToSearch, $pathToReplace, $item['comment']);
$comment = Database::escape_string($comment); $comment = Database::escape_string($comment);
$sql = "UPDATE c_quiz_answer SET $sql = "UPDATE c_quiz_answer SET
answer = '$answer', answer = '$answer',
comment = '$comment' comment = '$comment'
WHERE iid = $id"; WHERE iid = $id";
@ -107,7 +117,7 @@ foreach ($courses as $course) {
$items = Database::store_result($result); $items = Database::store_result($result);
foreach ($items as $item) { foreach ($items as $item) {
$id = $item['iid']; $id = $item['iid'];
$text = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['intro_text']); $text = preg_replace($pathToSearch, $pathToReplace, $item['intro_text']);
$text = Database::escape_string($text); $text = Database::escape_string($text);
$sql = "UPDATE c_tool_intro SET $sql = "UPDATE c_tool_intro SET
@ -122,13 +132,58 @@ foreach ($courses as $course) {
$items = Database::store_result($result); $items = Database::store_result($result);
foreach ($items as $item) { foreach ($items as $item) {
$id = $item['iid']; $id = $item['iid'];
$gdescription = preg_replace($pathToSearch, $newUrlAppend.'/courses/${4}', $item['description']); $gdescription = preg_replace($pathToSearch, $pathToReplace, $item['description']);
$gdescription = Database::escape_string($gdescription); $gdescription = Database::escape_string($gdescription);
$sql = "UPDATE c_glossary SET description = '$gdescription' WHERE iid = $id"; $sql = "UPDATE c_glossary SET description = '$gdescription' WHERE iid = $id";
Database::query($sql); Database::query($sql);
} }
// Updating forums
$sql = "SELECT iid, forum_comment FROM c_forum_forum WHERE c_id = $courseId";
$result = Database::query($sql);
$items = Database::store_result($result);
foreach ($items as $item) {
$id = $item['iid'];
$text = preg_replace($pathToSearch, $pathToReplace, $item['forum_comment']);
$text = Database::escape_string($text);
$sql = "UPDATE c_forum_forum SET
forum_comment = '$text'
WHERE iid = $id";
Database::query($sql);
}
// Updating posts
$sql = "SELECT iid, post_text FROM c_forum_post WHERE c_id = $courseId";
$result = Database::query($sql);
$items = Database::store_result($result);
foreach ($items as $item) {
$id = $item['iid'];
$text = preg_replace($pathToSearch, $pathToReplace, $item['post_text']);
$text = Database::escape_string($text);
$sql = "UPDATE c_forum_post SET
post_text = '$text'
WHERE iid = $id";
Database::query($sql);
}
// Updating forum cats
$sql = "SELECT iid, cat_comment FROM c_forum_category WHERE c_id = $courseId";
$result = Database::query($sql);
$items = Database::store_result($result);
foreach ($items as $item) {
$id = $item['iid'];
$text = preg_replace($pathToSearch, $pathToReplace, $item['cat_comment']);
$text = Database::escape_string($text);
$sql = "UPDATE c_forum_category SET
cat_comment = '$text'
WHERE iid = $id";
Database::query($sql);
}
} else { } else {
echo "<h4>Path doesn't exist</h4>".'<br />'; echo "<h4>Path doesn't exist</h4>".'<br />';
} }
} }

Loading…
Cancel
Save