From 6a0f3524da845ce563d1875d2dd541c2a9d362e2 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 6 Apr 2018 08:32:38 +0200 Subject: [PATCH] Minor - add tests files from 1.11.x --- .../features/course_user_registration.feature | 23 ++ tests/behat/features/createUserViaCSV.feature | 11 + tests/behat/features/toolDocument.feature | 53 +++++ tests/datafiller/generate_users.php | 15 ++ tests/scripts/fix_lp_id_to_iid.php | 205 ++++++++++++++++++ 5 files changed, 307 insertions(+) create mode 100644 tests/behat/features/course_user_registration.feature create mode 100644 tests/behat/features/createUserViaCSV.feature create mode 100644 tests/behat/features/toolDocument.feature create mode 100644 tests/datafiller/generate_users.php create mode 100644 tests/scripts/fix_lp_id_to_iid.php diff --git a/tests/behat/features/course_user_registration.feature b/tests/behat/features/course_user_registration.feature new file mode 100644 index 0000000000..3326e874eb --- /dev/null +++ b/tests/behat/features/course_user_registration.feature @@ -0,0 +1,23 @@ +Feature: Subscribe users to the course + + Background: + Given I am a platform administrator + + Scenario: Subscribe "amann" as student to the course "TEMP" + Given I am on "/main/user/subscribe_user.php?keyword=amann&type=5&cidReq=TEMP" + Then I should see "Aimee" + Then I follow "Register" + Then I should see "Aimee Mann has been registered to your course" + + Scenario: Unsubscribe user "amann" the course "TEMP" + Given I am on "/main/user/user.php?cidReq=TEMP" + Then I should see "Aimee" + Then I follow "Unsubscribe" + And I confirm the popup + Then I should see "User is now unsubscribed" + + Scenario: Subscribe "acostea" as student to the course "TEMP" (leave it subscribed for further tests) + Given I am on "/main/user/subscribe_user.php?keyword=acostea&type=5&cidReq=TEMP" + Then I should see "Andrea" + Then I follow "Register" + Then I should see "Andrea Costea has been registered to your course" \ No newline at end of file diff --git a/tests/behat/features/createUserViaCSV.feature b/tests/behat/features/createUserViaCSV.feature new file mode 100644 index 0000000000..19e1dde327 --- /dev/null +++ b/tests/behat/features/createUserViaCSV.feature @@ -0,0 +1,11 @@ +@administration +Feature: Users creation via CSV + + Scenario: Import user via CSV + Given I am a platform administrator + And I am on "/main/admin/user_import.php" + Then I attach the file "/main/admin/example.csv" to "import_file" + Then I press "Import" + Then I should see "File imported" + Then I am on "main/admin/user_list.php?keyword=drbrown@example.net" + Then I should see "emmert" diff --git a/tests/behat/features/toolDocument.feature b/tests/behat/features/toolDocument.feature new file mode 100644 index 0000000000..6b67129f31 --- /dev/null +++ b/tests/behat/features/toolDocument.feature @@ -0,0 +1,53 @@ +Feature: Document tool + In order to use the document tool + The teachers should be able to create and upload files + + Background: + Given I am a platform administrator + + Scenario: Create a folder + Given I am on "/main/document/document.php?cidReq=TEMP&createdir=1" + Then I should see "Create folder" + And I fill in the following: + | dirname | My new directory | + And I press "Create the folder" + Then I should see "Folder created" + + Scenario: Create a folder that already exists + Given I am on "/main/document/document.php?cidReq=TEMP&createdir=1" + Then I should see "Create folder" + And I fill in the following: + | dirname | My new directory | + And I press "Create the folder" + Then I should see "Unable to create the folder" + + Scenario: Create a HTML document + Given I am on "/main/document/create_document.php?cidReq=TEMP" + Then I should see "Create a rich media page / activity" + Then I fill in the following: + | create_document_title | My first document | + And I fill in ckeditor field "content" with "This is my first document!!!" + And I press "Create a rich media page / activity" + Then I should see "Item added" + And I should see "My first document" + Then I follow "My first document" + And wait for the page to be loaded + Then I should see "My first document" + + Scenario: Upload a document + Given I am on "/main/document/upload.php?cidReq=TEMP" + Then I should see "Upload documents" + Then I follow "Upload (Simple)" + Then I attach the file "web/css/base.css" to "file" + When I press "Upload file" + And wait for the page to be loaded + Then I should see "File upload succeeded" + +# Scenario: Create cloud link +# Given I am on "/main/document/add_link.php?cidReq=TEMP" +# Then I should see "Add a link" +# And I fill in the following: +# | name | My dropbox link | +# | url | http://dropbox.com/sh/loremipsum/loremipsum?dl=0 | +# And I press "Add link to Cloud file" +# Then I should see "Cloud link added" diff --git a/tests/datafiller/generate_users.php b/tests/datafiller/generate_users.php new file mode 100644 index 0000000000..6fc24d508f --- /dev/null +++ b/tests/datafiller/generate_users.php @@ -0,0 +1,15 @@ + 'aaaX', 'pass' => 'aaaX', 'firstname' => 'AAAX', 'lastname' => 'BBBX', 'status' => 5, 'auth_source' => 'platform', 'email' => 'aaaX@example.com', 'creator_id' => 1, 'active' => 1);\n"; +$output = ''; +$outputFile = '/tmp/data_users.php'; +$fh = fopen($outputFile, 'a+'); +for ($i=1; $i < 5000; $i++) { + fwrite($fh, str_replace('X', $i, $string)); +} +fclose($fh); diff --git a/tests/scripts/fix_lp_id_to_iid.php b/tests/scripts/fix_lp_id_to_iid.php new file mode 100644 index 0000000000..808462d050 --- /dev/null +++ b/tests/scripts/fix_lp_id_to_iid.php @@ -0,0 +1,205 @@ + id ORDER by iid"; + echo 'Select all lps'; + var_dump($sql); + $result = Database::query($sql); + + $myOnlyLpList = []; + if (Database::num_rows($result)) { + while ($lpInfo = Database::fetch_array($result, 'ASSOC')) { + $lpIid = $lpInfo['iid']; + $oldId = $lpInfo['id']; + $sql = "SELECT * FROM $tblCLpItem + WHERE c_id = $courseId AND lp_id = $oldId ORDER by iid"; + echo "

$sql

"; + echo "New lp.iid $lpIid / old lp.id $oldId"; + $items = Database::store_result(Database::query($sql),'ASSOC'); + $lpInfo['lp_list'] = $items; + $myOnlyLpList[] = $lpInfo; + } + } + + if (!empty($myOnlyLpList)) { + foreach ($myOnlyLpList as $lpInfo) { + $lpIid = $lpInfo['iid']; + $oldId = $lpInfo['id']; + + if (!empty($lpId)) { + if ($lpId != $oldId) { + continue; + } + } + + if (empty($lpInfo['lp_list'])) { + continue; + } + + $items = $lpInfo['lp_list']; + $itemList = []; + foreach ($items as $subItem) { + $itemList[$subItem['id']] = $subItem['iid']; + } + + $variablesToFix = [ + 'parent_item_id', + 'next_item_id', + 'prerequisite', + 'previous_item_id' + ]; + + foreach ($sessions as $sessionId) { + $correctLink = "lp/lp_controller.php?action=view&lp_id=$lpIid&id_session=$sessionId"; + $link = "newscorm/lp_controller.php?action=view&lp_id=$oldId&id_session=$sessionId"; + $secondLink = "lp/lp_controller.php?action=view&lp_id=$oldId&id_session=$sessionId"; + $sql = "UPDATE $toolTable + SET link = '$correctLink' + WHERE c_id = $courseId AND (link = '$link' OR link ='$secondLink')"; + Database::query($sql); + } + + foreach ($items as $item) { + $itemIid = $item['iid']; + $itemId = $item['id']; + + foreach ($variablesToFix as $variable) { + if (!empty($item[$variable]) && isset($itemList[$item[$variable]])) { + $newId = $itemList[$item[$variable]]; + $sql = "UPDATE $tblCLpItem SET $variable = $newId + WHERE iid = $itemIid AND c_id = $courseId AND lp_id = $oldId"; + Database::query($sql); + var_dump($sql); + } + } + + if ($item['item_type'] == 'document' && !empty($item['path'])) { + $oldDocumentId = $item['path']; + $sql = "SELECT * FROM c_document WHERE c_id = $courseId AND id = $oldDocumentId"; + $resultDocument = Database::query($sql); + if (Database::num_rows($resultDocument)) { + $document = Database::fetch_array($resultDocument, 'ASSOC'); + $newDocumentId = $document['iid']; + if (!empty($newDocumentId)) { + $sql = "UPDATE $tblCLpItem SET path = $newDocumentId + WHERE iid = $itemIid AND c_id = $courseId"; + Database::query($sql); + var_dump($sql); + } + } + } + + // c_lp_view + $sql = "UPDATE c_lp_view SET last_item = $itemIid + WHERE c_id = $courseId AND last_item = $itemId AND lp_id = $oldId"; + Database::query($sql); + var_dump($sql); + + // c_lp_item_view + $sql = "UPDATE c_lp_item_view SET lp_item_id = $itemIid + WHERE c_id = $courseId AND lp_item_id = $itemId "; + Database::query($sql); + var_dump($sql); + + // Update track_exercises + $sql = "UPDATE track_e_exercises SET orig_lp_item_id = $itemIid + WHERE c_id = $courseId AND orig_lp_id = $oldId AND orig_lp_item_id = $itemId"; + Database::query($sql); + var_dump($sql); + + // c_forum_thread + $sql = "UPDATE c_forum_thread SET lp_item_id = $itemIid + WHERE c_id = $courseId AND lp_item_id = $itemId"; + Database::query($sql); + var_dump($sql); + + // orig_lp_item_view_id + $sql = "SELECT * FROM c_lp_view + WHERE c_id = $courseId AND lp_id = $oldId"; + $itemViewList = Database::store_result(Database::query($sql),'ASSOC'); + if ($itemViewList) { + foreach ($itemViewList as $itemView) { + $userId = $itemView['user_id']; + $oldItemViewId = $itemView['id']; + $newItemView = $itemView['iid']; + if (empty($oldItemViewId)) { + continue; + } + + $sql = "UPDATE track_e_exercises + SET orig_lp_item_view_id = $newItemView + WHERE + c_id = $courseId AND + orig_lp_id = $oldId AND + orig_lp_item_id = $itemIid AND + orig_lp_item_view_id = $oldItemViewId AND + exe_user_id = $userId + "; + Database::query($sql); + var_dump($sql); + } + } + + $sql = "UPDATE $tblCLpItem SET lp_id = $lpIid + WHERE c_id = $courseId AND lp_id = $oldId AND id = $itemId"; + Database::query($sql); + var_dump($sql); + + $sql = "UPDATE $tblCLpItem SET id = iid + WHERE c_id = $courseId AND lp_id = $oldId AND id = $itemId"; + Database::query($sql); + var_dump($sql); + } + + $sql = "UPDATE c_lp_view SET lp_id = $lpIid WHERE c_id = $courseId AND lp_id = $oldId"; + Database::query($sql); + var_dump($sql); + + $sql = "UPDATE c_forum_forum SET lp_id = $lpIid WHERE c_id = $courseId AND lp_id = $oldId"; + Database::query($sql); + var_dump($sql); + + // Update track_exercises + $sql = "UPDATE track_e_exercises SET orig_lp_id = $lpIid + WHERE c_id = $courseId AND orig_lp_id = $oldId"; + Database::query($sql); + var_dump($sql); + + $sql = "UPDATE $tblCLp SET id = iid WHERE c_id = $courseId AND id = $oldId "; + Database::query($sql); + var_dump($sql); + } + } +} + +echo 'finished';