Commit 19bad994 authored by Doris Tam's avatar Doris Tam
Browse files

Bug 1810990: blocktypes: profile information and others for get_field checks

    additional:
        - added tabledata for all file information for table artefact_files_file
        - profileicon set for user acccording to latest block (will move to create_user later)
        - found bugs after testing with logging in different users, small bug fixes here and there

Change-Id: Icedfc86ded96de53c6de2823b226c3d9c361444b
parent b0778db2
......@@ -1035,7 +1035,7 @@ EOD;
}
if ($key == 'imagesel' || $key == 'width' || $key == 'showdesc' || $key == 'imagestyle' || $key == 'photoframe' ) {
//imageselection options are 0,1,2 in the table, changed for tester -_-
//imageselection options are 0,1,2 in the table
if ($key == 'imagesel') {
$value -= 1;
$configdata['select'] = $value;
......@@ -1130,7 +1130,8 @@ EOD;
$ext = end($filenameparts);
// we need to find the id of the item we are trying to attach and save it as artefactid
if (!$artefactid = get_field('artefact', 'id', 'title', $filename)) {
if (!$artefactid = get_field('artefact', 'id', 'title', $filename, 'owner', $ownerid)) {
if ($ext == 'wmv' || $ext == 'webm' || $ext == 'mov'|| $ext == 'ogv' || $ext == 'mpeg' || $ext == 'mp4' || $ext == 'flv' || $ext == 'avi' || $ext == '3gp') {
$artefactid = TestingDataGenerator::create_artefact($filename, $ownertype, $ownerid, 'video');
TestingDataGenerator::file_creation($artefactid, $filename, $ownertype, $ownerid);
......@@ -1235,11 +1236,14 @@ EOD;
}
/**
* generate configdata for the blocktype: plans
* @param string $data inside data column in blocktype tables
* @return array $configdata of key and values of db table
* generate configdata for the blocktype: plans
*
* @param string $data inside data column in blocktype tables
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_plans($data) {
public static function generate_configdata_plans($data, $ownertype, $ownerid) {
if (!$data) return;
$configdata = array();
......@@ -1253,7 +1257,7 @@ EOD;
if ($key == 'plans') {
$plans = explode(',',$value);
foreach ($plans as $plan) {
if (!$planid = get_field('artefact', 'id', 'title', $plan, 'artefacttype', 'plan')) {
if (!$planid = get_field('artefact', 'id', 'title', $plan, 'artefacttype', 'plan', 'owner', $ownerid)) {
throw new SystemException("Invalid Plan '" . $plan . "'");
}
$configdata['artefactids'][] = $planid;
......@@ -1266,6 +1270,64 @@ EOD;
return $configdata;
}
/**
* generate configdata for the blocktype: profileinformation
*
* As well as going thorugh the general fields in the data column of the table,
* an ArtefactTypeProfileIcon is created as there are none created in bulk.
*
* @param string $data inside data column in blocktype tables
* @param string $ownertype of user
* @param string $ownerid of the user
* @return array $configdata of key and values of db table
*/
public static function generate_configdata_profileinfo($data, $ownertype, $ownerid) {
if (!$data) return;
$configdata = array();
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
if ($key == 'introtext') {
require_once('embeddedimage.php');
$newtext = EmbeddedImage::prepare_embedded_images($value, 'introtext', 0);
$configdata['introtext'] = $newtext;
}
if ($key == 'profileicon') {
if (!$artefactprofileiconid = get_field('artefact', 'id', 'title', $value, 'owner', $ownerid, 'artefacttype', 'profileicon')) {
$folderartefactid = ArtefactTypeFolder::get_folder_id(get_string('imagesdir', 'artefact.file'), get_string('imagesdirdesc', 'artefact.file'), null, true, $ownerid);
$artefactprofileiconid = self::create_artefact($value, $ownertype, $ownerid, 'profileicon', $folderartefactid);
self::file_creation($artefactprofileiconid, $value, $ownertype, $ownerid, true);
execute_sql("UPDATE {usr}
SET profileicon = $artefactprofileiconid
WHERE id = $ownerid");
}
$configdata['profileicon'] = $artefactprofileiconid;
}
}
// gather the user's social profiles data
safe_require('artefact', 'internal');
$element_list = ArtefactTypeProfile::get_all_fields();
foreach ($element_list as $element=>$type) {
if ($artefactid = get_field('artefact', 'id', 'artefacttype', $element, 'owner', $ownerid)) {
$configdata['artefactids'][] = $artefactid;
}
else if ($element == 'socialprofile') {
$artefacttypes = ArtefactTypeSocialprofile::$socialnetworks;
foreach ($artefacttypes as $type) {
if ($artefactid = get_field('artefact', 'id', 'artefacttype', 'socialprofile', 'owner', $ownerid, 'note', $type)) {
$configdata['artefactids'][] = $artefactid;
}
}
}
}
return $configdata;
}
/**
* generate configdata for blocktype: recentforumposts
*
......@@ -1482,7 +1544,7 @@ EOD;
* @param int $ownertype of the user
* @param int $ownerid of the user
**/
public static function file_creation($artefactid, $file, $ownertype, $ownerid, $foldername='upload_files') {
public static function file_creation($artefactid, $file, $ownertype, $ownerid, $profilepic=false) {
// get the path of the file artefact from given artefactid
$filedir = get_config('dataroot') . ArtefactTypeFile::get_file_directory($artefactid);
......@@ -1495,6 +1557,15 @@ EOD;
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $file;
copy($path, $filepath);
chmod($filepath, get_config('filepermissions'));
if ($profilepic) {
// Move the profile file into the correct place.
$directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . ($artefactid % 256) . '/';
if (!check_dir_exists($directory, true, true)) {
throw new SystemException("Unable to create folder $directory");
}
$result2 = copy($path, $directory . $artefactid);
}
}
if (!$artefactid) {
throw new SystemException("Invalid attachment '" . $file . "'. No attachment by that name owned by " . $ownertype . " with id " . $ownerid);
......@@ -1524,23 +1595,32 @@ EOD;
* @return int artefactid
**/
public static function create_artefact($file, $ownertype, $ownerid, $filetype, $parentfolderid=null) {
$ext = explode('.', $file);
$now = date("Y-m-d H:i:s");
$artefactid = null;
$artefact = new stdClass();
$artefact->title = $file;
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $file;
$ext = explode('.', $file);
$artefact->oldextension = end($ext);
$artefact->title = $file;
$artefact->$ownertype = $ownerid;
$artefact->author = $ownerid;
$artefact->atime = $now;
$artefact->ctime = $now;
$artefact->mtime = $now;
// table artefact_file_files needs this information
$artefact->contenthash = ArtefactTypeFile::generate_content_hash($path);
$artefact->filetype = mime_content_type($path);
$now = date("Y-m-d H:i:s");
$artefact->atime = $artefact->ctime = $artefact->mtime =$now;
$imagefilesize = filesize($path);
$filesize = get_real_size($imagefilesize);
$artefact->size = $filesize;
// if file belongs inside a folder
if ($parentfolderid) {
$artefact->parent = $parentfolderid;
}
$artefactid = null;
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $file;
if ($filetype == 'image') {
$imageinfo = getimagesize($path);
......@@ -1553,20 +1633,48 @@ EOD;
}
if ($filetype == 'attachment') {
$artobj = new ArtefactTypeFile(0, $artefact);
$artobj->commit();
$artefactid = $artobj->get('id');
}
if ($filetype == 'audio') {
$artefact->filetype = 'audio';
$artobj = ArtefactTypeFile::new_file($path, $artefact);
$artobj->commit();
$artefactid = $artobj->get('id');
}
if ($filetype == 'profileicon') {
$imageinfo = getimagesize($path);
$artefact->width = $imageinfo[0];
$artefact->height = $imageinfo[1];
$artefact->description = get_string('uploadedprofileicon', 'artefact.file');
$artefact->note = $file;
// validate the upload as done in Pieform (profileicons.php)
if (!$imageinfo || !is_image_type($imageinfo[2])) {
throw new SystemException(get_string('filenotimage'));
}
// maximum of five profile pics per user
if (get_field('artefact', 'COUNT(*)', 'artefacttype', 'profileicon', 'owner', $ownerid) >= 5) {
throw new SystemException(get_string('onlyfiveprofileicons', 'artefact.file'));
}
// by adding new pic, quota isn't exceeded
$user = new User();
$user->find_by_id($ownerid);
if (!$user->quota_allowed($artefact->size)) {
throw new SystemException(get_string('profileiconuploadexceedsquota', 'artefact.file', get_config('wwwroot')));
}
$profileiconartefact = new ArtefactTypeProfileIcon(0, $artefact);
$profileiconartefact->commit();
$artefactid = $profileiconartefact->get('id');
}
if ($filetype == 'video') {
//this function from artefact/file/lib.php creates the specific ArtefactType[]
$artobj = ArtefactTypeFile::new_file($path, $artefact);
$artobj->commit();
$artefactid = $artobj->get('id');
......
......@@ -262,10 +262,10 @@ class BehatDataGenerators extends BehatBase {
foreach ($record as &$value) {
$value = trim($value);
// Normalise boolean values
if (strtolower($value) == 'on' || $value == '1' || $value == 'yes' || $value == 'true') {
if (strtolower($value) == 'on' || $value == '1' || $value == 'true') {
$value = true;
}
else if (strtolower($value) == 'off' || $value == '0' || $value == 'no' || $value == 'false') {
else if (strtolower($value) == 'off' || $value == '0' || $value == 'false') {
$value = false;
}
}
......
......@@ -26,16 +26,17 @@ Background:
| Group1 | unicorns! | topic one | cheer on | woo! mahara unicorns unite! | UserB |
| Group1 | | topic one | cheer on | 10 papercranes, let's go! | UserB |
| Group1 | unicorns! | topic one | extra subj | 100 papercranes, let's go! | UserB |
| Group1 | unicorns! | |origami | 1000 papercranes, let's go! | UserB |
| Group1 | unicorns! | | origami | 1000 papercranes, let's go! | UserB |
And the following "pages" exist:
| title | description | ownertype | ownername |
| Page UserA_00 | Page 01 | user | UserA |
| Page UserB_00 | Page 01 | user | UserA |
| Page UserA | Page 01 | user | UserA |
| Page UserB | Page 01 | user | UserB |
| Page Grp1 | Page 01 | group | Group1 |
| Page One | test 01 | user | UserA |
| Page Two | test 01 | user | UserA |
| Page Three | test 01 | user | UserA |
| Page Four | test 01 | user | UserA |
And the following "collections" exist:
| title | ownertype | ownername | description | pages |
......@@ -63,38 +64,39 @@ Background:
| Group1 | group | Group Plan | This is my group plan | unicorn |
And the following "tasks" exist:
| owner | ownertype | plan | title | description | completiondate | completed | tags |
| UserA | user | Plan One | Task One| Task One Description | 12/12/19 | no | cats,dogs |
| UserA | user | Plan One | Task Two| Task Two Description | 12/01/19 | yes | cats,dogs |
| UserA | user | Plan Two | Task 2a | Task 2a Description | 12/10/19 | yes | cats,dogs |
| UserA | user | Plan Two | Task 2b | Task 2b Description | 11/05/19 | yes | cats,dogs |
| UserA | user | Plan Two | Task 2c | Task 2c Description | 22/02/19 | yes | cats,dogs |
| owner | ownertype | plan | title | description | completiondate | completed | tags |
| UserA | user | Plan One | Task One a | Task 1a Description | 12/12/19 | false | cats,dogs |
| UserA | user | Plan One | Task One b | Task 1b Description | 12/01/19 | true | cats,dogs |
| UserA | user | Plan Two | Task Two a | Task 2a Description | 12/10/19 | true | cats,dogs |
| UserA | user | Plan Two | Task Two b | Task 2b Description | 11/01/19 | true | cats,dogs |
| UserA | user | Plan Two | Task Two c | Task 2c Description | 22/02/19 | true | cats,dogs |
And the following "blocks" exist:
| title | type | page |retractable | data |
| Text | text | Page UserA_00 | yes | This is some text |
| Image JPG | image | Page UserA_00 | no | attachment=Image1.jpg; width=100 |
| Image PNG | image | Page UserA_00 | no | attachment=Image2.png |
| Files to download | filedownload | Page UserA_00 | auto | attachments=mahara_about.pdf |
| Files to download | filedownload | Page UserA_00 | no | attachments=mahara_about.pdf,Image2.png |
| External Feed - News | externalfeed | Page UserA_00 | No | source=http://rss.nzherald.co.nz/rss/xml/nzhtsrsscid_000000698.xml;count=5 |
| External Feed - Food | externalfeed | Page UserA_00 | no | source=http://www.thekitchenmaid.com/feed;count=3 |
| Image | image | Page Grp1 | no | attachment=Image3.png |
| Files to download | filedownload | Page Grp1 | no | attachments=mahara_about.pdf,Image2.png,testvid3.mp4,mahara.mp3 |
| External Video | externalvideo | Page Grp1 | no | source=https://youtu.be/yRxFm70nOrY |
| Social Media | socialprofile | Page UserB_00 | no | sns=instagram,twitter,facebook,tumblr,pinterest,mysocialmedia |
| Gallery - style 1 | gallery | Page UserB_00 | no | attachments=Image1.jpg,Image3.png,Image3.png,Image2.png;imagesel=2;showdesc=yes;width=75;imagestyle=1;photoframe=1 |
| Gallery - style 2 | gallery | Page UserB_00 | yes | attachments=Image3.png,Image2.png,Image1.jpg;imagesel=2;showdesc=yes;width=75;imagestyle=2 |
| Gallery - style 3 | gallery | Page UserB_00 | yes | attachments=Image3.png,Image2.png,Image1.jpg;imagesel=2;showdesc=no;imagestyle=3;photoframe=0|
| Folder | folder | Page UserB_00 | no | dirname=myfolder;attachments=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png,mahara.mp3 |
| Some HTML | html | Page UserB_00 | yes | attachment=test_html.html |
| Text | text | Page UserA | yes | This is some text |
| Image JPG | image | Page UserA | no | attachment=Image1.jpg; width=100 |
| Image PNG | image | Page UserA | no | attachment=Image2.png |
| Files to download | filedownload | Page UserA | auto | attachments=mahara_about.pdf |
| Files to download | filedownload | Page UserA | no | attachments=mahara_about.pdf,Image2.png |
| External Feed - News | externalfeed | Page UserA | No | source=http://rss.nzherald.co.nz/rss/xml/nzhtsrsscid_000000698.xml;count=5 |
| External Feed - Food | externalfeed | Page UserA | no | source=http://www.thekitchenmaid.com/feed;count=3 |
| Social Media | socialprofile | Page UserA | no | sns=instagram,twitter,facebook,tumblr,pinterest,mysocialmedia |
| Image | image | Page Grp1 | no | attachment=Image3.png |
| Files to download | filedownload | Page Grp1 | no | attachments=mahara_about.pdf,Image2.png,testvid3.mp4,mahara.mp3 |
| External Video | externalvideo | Page Grp1 | no | source=https://youtu.be/yRxFm70nOrY |
| Navigation | navigation | Page Grp1 | no | collection=collection one;copytoall=yes |
| Social Media | socialprofile | Page UserB | no | sns=instagram,twitter,facebook,tumblr,pinterest,mysocialmedia |
| Gallery - style 1 | gallery | Page UserB | no | attachments=Image1.jpg,Image3.png,Image3.png,Image2.png,Image1.jpg;imagesel=2;showdesc=yes;width=75;imagestyle=1;photoframe=1 |
| Gallery - style 2 | gallery | Page UserB | yes | attachments=Image3.png,Image2.png,Image1.jpg,Image1.jpg;imagesel=2;showdesc=yes;width=75;imagestyle=2 |
| Gallery - style 3 | gallery | Page UserB | yes | attachments=Image3.png,Image2.png,Image3.png,Image1.jpg,Image1.jpg;imagesel=2;showdesc=no;imagestyle=3;photoframe=0|
| Folder | folder | Page UserB | no | dirname=myfolder;attachments=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png,mahara.mp3 |
| Some HTML | html | Page UserB | yes | attachment=test_html.html |
| Profile Information | profileinfo | Page UserB | no | introtext =Mahara unicorn here! Nice to meet you :);profileicon=Image3.png |
| Blog/Journal | blog | Page One | no | copytype=nocopy;count=5;journaltitle=journal1 |
| Blogpost/JournalEntry| blogpost | Page One | no | copytype=nocopy;journaltitle=journal1;entrytitle=Entry Two |
| Comments | comment | Page One | | no configdata |
| Comments | comment | Page One | no | no configdata |
| Peer Assessment | peerassessment | Page One | auto | no configdata |
| Creative Commons | creativecommons| Page One | no | commercialuse=yes;license=3.0;allowmods=no |
......@@ -106,9 +108,12 @@ Background:
| Pdf | pdf | Page Three | no | attachment=mahara_about.pdf |
| Recent Forum Posts |recentforumposts| Page Three | no | groupname=Group1;maxposts=3 |
| External Video | externalvideo | Page Three | no | source=https://youtu.be/yRxFm70nOrY |
| Note/Textbox 1 | textbox | Page Three | no | notetitle=secretnote;text=ma ha ha ha ra!;tags=mahara,araham;attachments=Image3.png,Image2.png,Image1.jpg;allowcomments=yes |
| Note/textbox ref:1 | textbox | Page Three | no | existingnote=secretnote |
| Note/Textbox copy:1 | textbox | Page Three | no | existingnote=secretnote;allowcomments=yes;copynote=true;notetitle=newsecretnote |
| Profile Information | profileinfo | Page Two | no | introtext =Mahara unicorn here! Nice to meet you :);profileicon=Image1.jpg |
| Profile Information | profileinfo | Page Two | no | introtext =Mahara unicorn here! Nice to meet you :);profileicon=Image2.png |
Scenario: Login as admin to change upload settings
......@@ -131,9 +136,11 @@ Scenario: Login as admin to change upload settings
And I press "Save"
And I log out
Then I log in as "UserA" with password "Kupuh1pa!"
And I go to portfolio page "Page UserA_00"
And I go to portfolio page "Page UserA"
And I go to portfolio page "Page Grp1"
And I go to portfolio page "Page UserB_00"
And I go to portfolio page "Page One"
And I go to portfolio page "Page Two"
And I go to portfolio page "Page Three"
And I log out
And I log in as "UserB" with password "Kupuh1pa!"
Then I go to portfolio page "Page UserB"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment