Commit a7179797 authored by Doris Tam's avatar Doris Tam 🌷
Browse files

Bug 1810990: blocktype: html

Change-Id: I602f9e0d48f2da117655ce97459e52d91f1827d6
parent 089d9fa5
Loading
Loading
Loading
Loading
+85 −64
Original line number Diff line number Diff line
@@ -762,29 +762,21 @@ EOD;

        foreach ($fields as $field) {
            list($key, $value) = explode('=', $field);
            $key = trim($key);
            $value = trim($value);
            if ($key == 'attachment') {

                // 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', $value, $ownertype, $ownerid)) {
                    $artefactid = TestingDataGenerator::create_file_artefact($file=$value, $ownertype, $ownerid, 'attachment');

                    // Create folder and file inside it. then write contents into it...
                    $filedir = get_config('dataroot') . ArtefactTypeFile::get_file_directory($artefactid);
                    if (!check_dir_exists($filedir, true, true)) {
                        throw new SystemException("Unable to create folder $filedir");
                    }
                    else {
                        // Write contents to a file...
                        $imagepath = $filedir . '/' . $artefactid;
                $path = get_mahararoot_dir() . '/test/behat/upload_files/' . $value;
                        copy($path, $imagepath);
                        chmod($imagepath, get_config('filepermissions'));
                    }
                    if (!$artefactid) {
                        throw new SystemException("Invalid attachment '" . $value . "'. No attachment by that name owned by " . $ownertype . " with id " . $ownerid);
                    }
                $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', $value, $ownertype, $ownerid)) {
                    $newvalue = TestingDataGenerator::create_file_artefact($value, $ownertype, $ownerid, $mediatype);
                    TestingDataGenerator::file_creation($newvalue, $value, $ownertype, $ownerid);
                }
                $configdata['artefactids'][] = $artefactid;
                $configdata['artefactids'][] = $newvalue;
            }
        }
        return $configdata;
@@ -808,6 +800,8 @@ EOD;

      foreach ($fields as $field) {
          list($key, $value) = explode('=', $field);
          $key=trim($key);
          $value=trim($value);

          if ($key == 'folder_name') {
              $foldername = $value;
@@ -815,11 +809,11 @@ EOD;
              $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);
@@ -827,8 +821,8 @@ EOD;

                  // 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)) {
                        $artefactid = TestingDataGenerator::create_file_artefact($file, $ownertype, $ownerid, $mediatype, $folderartefactid);
                        TestingDataGenerator::file_creation($artefactid, $file, $ownertype, $ownerid);
                      $newvalue = TestingDataGenerator::create_file_artefact($file, $ownertype, $ownerid, $mediatype, $folderartefactid);
                      TestingDataGenerator::file_creation($newvalue, $file, $ownertype, $ownerid);
                  }
              }
          }
@@ -853,11 +847,14 @@ EOD;
      foreach ($fields as $field) {

          list($key, $value) = explode('=', $field);
          $key=trim($key);
          $value=trim($value);

          if ($key == 'gallery_images') {
                $images = explode(',', $value);
              $galleryimages = explode(',', $value);
              $value = array();

                foreach ($images as $image) {
              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);
@@ -866,13 +863,37 @@ EOD;
              }
              $configdata['artefactids'] = $value;
          }
            if ($key == 'select' || $key == 'width' || $key == 'showdescription' || $key == 'style' || 'photoframe' ) {

          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;

        $fields = explode(';', $data);
        $configdata = array();

        foreach ($fields as $field) {
            list($key, $value) = explode('=', $field);
            $key = trim($key);
            $value = trim($value);
            if ($key == 'src') {
                //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
                    $artefactid = TestingDataGenerator::create_file_artefact($file=$value, $ownertype, $ownerid, 'attachment');
                    TestingDataGenerator::file_creation($artefactid, $file, $ownertype, $ownerid);
                }
                $configdata['artefactid'] = $artefactid;
            }
        }
        return $configdata;
    }


    /**
    * generate config data for the blocktype: image
+2 −1
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ Background:
    | 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 |
    | 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 |

Scenario: Create Page UserA_00 with text blocks
    Given I log in as "UserA" with password "Kupuh1pa!"