Commit 20452b45 authored by Aatharsh Girishwar Vijaya Sugumar's avatar Aatharsh Girishwar Vijaya Sugumar Committed by Robert Lyon
Browse files

Bug 1879410: Add a text block in Dashboard page using TestingDataGenerator.php



Modified create_block() functionality of TestingDataGenerator.php to generate
blocks in the Dashboard page

Modified code based on review comments - moved sql query to else block, used list
instead of array and added type='dashboard' in sql query, modified dashboard
str match from preg match

Change-Id: I8880226008217b0bc3ed9b97301ad060c998d058
Signed-off-by: default avatarAatharsh Girishwar Vijaya Sugumar <aatharshsugumar@catalyst.net.nz>
(cherry picked from commit d811cd3c)
parent c0b6d664
Loading
Loading
Loading
Loading
+35 −5
Original line number Diff line number Diff line
@@ -156,6 +156,20 @@ EOD;
        return false;
    }

    /**
     * Gets the view id from it's title and owner.
     * @param string $viewtitle
     * @param int $ownerid
     * @return int the view id
     *     = false if not exists
     */
    protected function get_view_id_by_owner($viewtitle, $ownerid) {
        if ($res = get_record('view', 'title', $viewtitle, 'owner', $ownerid)) {
            return $res->id;
        }
        return false;
    }

    /**
     * Gets the id of one site administrator.
     * @return int the admin id
@@ -731,18 +745,34 @@ EOD;
     */
    public function create_block($record) {
        global $USER;
        $sql = $page = $ownerid = $view = $viewid = null;

        if (preg_match('/^Dashboard page\:/', $record['page'])) {
            list($record['page'], $ownername) = explode(":", $record['page']);
            $ownerid = get_field('usr', 'id', 'username', $ownername);
            $sql = "SELECT id FROM {view} WHERE type = 'dashboard' AND LOWER(TRIM(title)) = ? AND \"owner\" = ?";
            $page = strtolower(trim($record['page']));
            $view = trim($record['page']);
            $viewid = $this->get_view_id_by_owner($view, $ownerid);
        }
        else {
            $sql = "SELECT id FROM {view} WHERE LOWER(TRIM(title)) = ?";
            $page = strtolower(trim($record['page']));

            $view = trim($record['page']);
            $viewid = $this->get_view_id($view);
        }

        if (!isset(self::$viewcolcounts[$viewid])) {
          self::$viewcolcounts[$viewid]['x'] = 0;
          self::$viewcolcounts[$viewid]['y'] = 0;
        }

        if ($ownerid != null) {
            $ids = get_records_sql_array($sql, array($page,$ownerid));
        }
        else {
            $ids = get_records_sql_array($sql, array($page));
        }
        if (!$ids || count($ids) > 1) {
            throw new SystemException("Invalid page name '" . $record['page'] . "'. The page title does not exist, or is duplicated.");
        }
+2 −1
Original line number Diff line number Diff line
@@ -37,5 +37,6 @@ Scenario:
    And I should not see "<h1>Mahara does HTML</h1>"
    And I should see images within the block "Some HTML"
    And I follow "mahara manual"
    And I wait "3" seconds
    And I switch to the new window
    And I wait "2" seconds
    Then I should see "This is the manual for Mahara"