Commit f91d852f authored by Doris Tam's avatar Doris Tam
Browse files

Bug 1810990: behat table: field names data section

    additional:
        - rearrange order of functions folder, filedownload, gallery

Change-Id: Id6a095bacb4b312c8ffd84660d55cc9f6956ce39
parent a7179797
......@@ -722,7 +722,7 @@ EOD;
if (!$data) return;
list($key, $value) = explode('=', $data);
if ($key == 'feed_location') {
if ($key == 'source') {
$wheredata = array('url' => $value);
$feeddata = PluginBlocktypeExternalfeed::parse_feed($value);
$feeddata->content = serialize($feeddata->content);
......@@ -741,7 +741,7 @@ EOD;
if (!$data) return;
list($key, $value) = explode('=', $data);
if ($key == 'video_location') {
if ($key == 'source') {
$sourceinfo = PluginBlocktypeExternalvideo::process_url($value);
return $sourceinfo;
}
......@@ -755,34 +755,37 @@ EOD;
* @return array configdata of key and values for db table
**/
public static function generate_configdata_filedownload($data, $ownertype, $ownerid) {
if (!$data) return;
$fields = explode(';', $data);
$configdata = array();
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
if ($key == 'attachment') {
if (!$data) return;
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $value;
$mimetype = mime_content_type($path);
list($media, $ext) = explode('/', $mimetype);
$mediatype = $media == 'application' ? 'attachment' : $media;
$fields = explode(';', $data);
$configdata = array();
// we need to find the id of the item we are trying to attach and save it as artefactid
if (!$newvalue = get_field('artefact', 'id', 'title', $value, $ownertype, $ownerid)) {
$newvalue = TestingDataGenerator::create_file_artefact($value, $ownertype, $ownerid, $mediatype);
TestingDataGenerator::file_creation($newvalue, $value, $ownertype, $ownerid);
}
$configdata['artefactids'][] = $newvalue;
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
if ($key == 'attachments') {
$key = 'artefactids';
$attachments = explode(',',$value);
foreach ($attachments as $attachment) {
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $attachment;
$mimetype = mime_content_type($path);
list($media, $ext) = explode('/', $mimetype);
$mediatype = $media == 'application' ? 'attachment' : $media;
// 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', $attachment, $ownertype, $ownerid)) {
$artefactid = TestingDataGenerator::create_file_artefact($file=$attachment, $ownertype, $ownerid, $mediatype);
TestingDataGenerator::file_creation($artefactid, $attachment, $ownertype, $ownerid);
}
$configdata['artefactids'][] = $artefactid;
}
}
return $configdata;
}
return $configdata;
}
/**
* generate config data for the blocktype folder, which dealts with creating a folder artefact_type
* as well as file artefacts and connecting them parent ids.
......@@ -799,33 +802,31 @@ EOD;
$foldername;
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
if ($key == 'folder_name') {
$foldername = $value;
$folderartefactid = ArtefactTypeFolder::get_folder_id($foldername, $foldername, null, true, $ownerid);
$configdata['artefactid'] = $folderartefactid;
}
if ($key == 'folder_files') {
$files = explode(',', $value);
// upload each image and put into a folder
foreach($files as $file) {
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $file;
$mimetype = mime_content_type($path);
list($media, $ext) = explode('/', $mimetype);
$mediatype = $media == 'application' ? 'attachment' : $media;
// we need to find the id of the item we are trying to attach and save it as artefactid
if (!$newvalue = get_field('artefact', 'id', 'title', $file, 'parent', $folderartefactid)) {
$newvalue = TestingDataGenerator::create_file_artefact($file, $ownertype, $ownerid, $mediatype, $folderartefactid);
TestingDataGenerator::file_creation($newvalue, $file, $ownertype, $ownerid);
}
}
list($key, $value) = explode('=', $field);
if ($key == 'dirname') {
$foldername = $value;
$folderartefactid = ArtefactTypeFolder::get_folder_id($foldername, $foldername, null, true, $ownerid);
$configdata['artefactid'] = $folderartefactid;
}
if ($key == 'folder_files') {
$files = explode(',', $value);
// upload each image and put into a folder
foreach($files as $file) {
$path = get_mahararoot_dir() . '/test/behat/upload_files/' . $file;
$mimetype = mime_content_type($path);
list($media, $ext) = explode('/', $mimetype);
$mediatype = $media == 'application' ? 'attachment' : $media;
// 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', $file, 'parent', $folderartefactid)) {
$artefactid = TestingDataGenerator::create_file_artefact($file, $ownertype, $ownerid, $mediatype, $folderartefactid);
TestingDataGenerator::file_creation($artefactid, $file, $ownertype, $ownerid);
}
}
}
}
return $configdata;
}
......@@ -838,39 +839,38 @@ EOD;
* @return array configdata of key and values for db table
**/
public static function generate_configdata_gallery($data, $ownertype, $ownerid) {
if (!$data) return;
if (!$data) return;
$configdata = array();
$configdata = array();
//separate gallery_images, select, width, style etc.
$fields = explode(';', $data);
foreach ($fields as $field) {
//separate gallery_images, select, width, style etc.
$fields = explode(';', $data);
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
list($key, $value) = explode('=', $field);
$key=trim($key);
$value=trim($value);
if ($key == 'gallery_images') {
$galleryimages = explode(',', $value);
$value = array();
if ($key == 'attachments') {
$galleryimages = explode(',', $value);
$value = array();
foreach ($galleryimages as $image) {
if (!$newvalue = get_field('artefact','id', 'title', $image)) {
$newvalue = TestingDataGenerator::create_file_artefact($image, $ownertype, $ownerid, 'image');
TestingDataGenerator::file_creation($newvalue, $image, $ownertype, $ownerid);
foreach ($galleryimages as $image) {
if (!$artefactid = get_field('artefact','id', 'title', $image)) {
$artefactid = TestingDataGenerator::create_file_artefact($image, $ownertype, $ownerid, 'image');
TestingDataGenerator::file_creation($artefactid, $image, $ownertype, $ownerid);
}
$configdata['artefactids'][] = $artefactid;
}
$value[] = $newvalue;
}
$configdata['artefactids'] = $value;
}
if ($key == 'select' || $key == 'width' || $key == 'showdescription' || $key == 'style' || $key == 'photoframe' ) {
$configdata[$key] = $value;
}
}
return $configdata;
}
if ($key == 'select' || $key == 'width' || $key == 'showdescription' || $key == 'style' || $key == 'photoframe' ) {
$configdata[$key] = $value;
}
}
return $configdata;
}
public static function generate_configdata_html($data, $ownertype, $ownerid) {
if (!$data) return;
......@@ -881,7 +881,7 @@ EOD;
list($key, $value) = explode('=', $field);
$key = trim($key);
$value = trim($value);
if ($key == 'src') {
if ($key == 'source') {
//retrieve/create and retrieve artefactid of artefact we are attaching to the block
if (!$artefactid = get_field('artefact', 'id', 'title', $value)) {
//we must create the file artefact as it doesn't exist in the table
......@@ -894,7 +894,6 @@ EOD;
return $configdata;
}
/**
* generate config data for the blocktype: image
* @param string $data inside data column in behat test
......@@ -910,7 +909,7 @@ EOD;
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
if ($key == 'image') {
if ($key == 'attachment') {
// we need to find the id of the item we are trying to attach and save it as artefactid
if (!$artefactimageid = get_field('artefact', 'id', 'title', $value, $ownertype, $ownerid)) {
......@@ -934,7 +933,7 @@ EOD;
if (!$data) return;
list($key, $value) = explode('=', $data);
if ($key == 'social_profile') {
if ($key == 'sns') {
//split the values for multiple social profile creation
$medialist = explode(',', $value);
$value = array();
......@@ -959,20 +958,9 @@ EOD;
**/
public static function generate_configdata_text($data) {
if (!$data) return;
$fields = explode(';', $data);
$configdata = array();
foreach ($fields as $field) {
list($key, $value) = explode('=', $field);
if ($key == 'text') {
$configdata[$key] = $value;
}
return $configdata;
}
return $configdata = array('text' => $data);
}
/**
* Copies file from /test/behat/upload_files folder and places it in the dataroot folder of the site.
* Then write contents into it given the artefact id
......
......@@ -23,22 +23,22 @@ Background:
And the following "blocks" exist:
| title | type | page | row | column | order |retractable | data |
| My text 1 | text | Page UserA_00 | 1 | 1 | 1 | yes | text=This is sometext one |
| image jpg | image | Page UserA_00 | 1 | 1 | 2 | no | image=Image1.jpg |
| image png | image | Page UserA_00 | 1 | 1 | 3 | no | image=Image2.png |
| My files 1 | filedownload | Page UserA_00 | 1 | 2 | 1 | auto | attachment=mahara_about.pdf |
| My files 2 | filedownload | Page UserA_00 | 1 | 2 | 2 | no | attachment=mahara_about.pdf;attachment=Image2.png |
| Rss news | externalfeed | Page UserA_00 | 1 | 3 | 1 | no | feed_location=http://rss.nzherald.co.nz/rss/xml/nzhtsrsscid_000000698.xml |
| Rss food | externalfeed | Page UserA_00 | 1 | 3 | 2 | no | feed_location=http://www.thekitchenmaid.com/feed |
| G image 3 | image | Page Grp1 | 1 | 1 | 1 | no | image=Image3.png |
| G files 2 | filedownload | Page Grp1 | 1 | 1 | 2 | no | attachment=mahara_about.pdf;attachment=Image2.png |
| nzslang | externalvideo| Page Grp1 | 1 | 1 | 3 | no | video_location=https://youtu.be/yRxFm70nOrY |
| my social | socialprofile| Page UserB_00 | 1 | 1 | 1 | no | social_profile=instagram,twitter,facebook,tumblr,pinterest |
| gall style1 | gallery | Page UserB_00 | 1 | 2 | 1 | no | gallery_images=Image1.jpg,Image3.png,Image3.png,Image2.png;select=1;showdescription=1;width=75;style=0;photoframe=1 |
| gall style2 | gallery | Page UserB_00 | 1 | 2 | 2 | no | gallery_images=Image3.png,Image2.png,Image1.jpg;select=1;showdescription=1;width=75;style=1 |
| gall style3 | gallery | Page UserB_00 | 1 | 2 | 3 | no | gallery_images=Image3.png,Image2.png,Image1.jpg;select=1;showdescription=1;style=2;photoframe=0|
| myfolder | folder | Page UserB_00 | 1 | 2 | 4 | no | folder_name=myfolder;folder_files=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png |
| my html | html | Page UserB_00 | 1 | 3 | 1 | yes | src=test_html.html |
| My text 1 | text | Page UserA_00 | 1 | 1 | 1 | yes | This is some text one |
| image jpg | image | Page UserA_00 | 1 | 1 | 2 | no | attachment=Image1.jpg |
| image png | image | Page UserA_00 | 1 | 1 | 3 | no | attachment=Image2.png |
| My files 1 | filedownload | Page UserA_00 | 1 | 2 | 1 | auto | attachments=mahara_about.pdf |
| My files 2 | filedownload | Page UserA_00 | 1 | 2 | 2 | no | attachments=mahara_about.pdf,Image2.png |
| Rss news | externalfeed | Page UserA_00 | 1 | 3 | 1 | no | source=http://rss.nzherald.co.nz/rss/xml/nzhtsrsscid_000000698.xml |
| Rss food | externalfeed | Page UserA_00 | 1 | 3 | 2 | no | source=http://www.thekitchenmaid.com/feed |
| G image 3 | image | Page Grp1 | 1 | 1 | 1 | no | attachment=Image3.png |
| G files 2 | filedownload | Page Grp1 | 1 | 1 | 2 | no | attachments=mahara_about.pdf,Image2.png |
| nzslang | externalvideo| Page Grp1 | 1 | 1 | 3 | no | source=https://youtu.be/yRxFm70nOrY |
| my social | socialprofile| Page UserB_00 | 1 | 1 | 1 | no | sns=instagram,twitter,facebook,tumblr,pinterest |
| gall style1 | gallery | Page UserB_00 | 1 | 2 | 1 | no | attachments=Image1.jpg,Image3.png,Image3.png,Image2.png;select=1;showdescription=1;width=75;style=0;photoframe=1 |
| gall style2 | gallery | Page UserB_00 | 1 | 2 | 2 | no | attachments=Image3.png,Image2.png,Image1.jpg;select=1;showdescription=1;width=75;style=1 |
| gall style3 | gallery | Page UserB_00 | 1 | 2 | 3 | no | attachments=Image3.png,Image2.png,Image1.jpg;select=1;showdescription=1;style=2;photoframe=0|
| myfolder | folder | Page UserB_00 | 1 | 2 | 4 | no | dirname=myfolder;folder_files=mahara_about.pdf,Image2.png,Image1.jpg,Image3.png |
| my html | html | Page UserB_00 | 1 | 3 | 1 | yes | source=test_html.html |
Scenario: Create Page UserA_00 with text blocks
Given I log in as "UserA" with password "Kupuh1pa!"
......
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