Commit 9cf3d8eb authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1813987: Behat - block creation

- Data generator creates blocks for new gridstack layout
- we don't look for nodes inside script elements

behatnotneeded

Change-Id: I0e791c431ab6b80e75ae397290a20b3ec9fba836
parent ccc2446d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2256,7 +2256,7 @@ class View {
            }
            else {
                $result = $blockinstance->render_viewing($exporting, $versioning);
                if (call_static_method(generate_class_name('blocktype', $blockinstance->get('blocktype')), 'has_static_content')) {
                if (call_static_method(generate_class_name('blocktype', $blockinstance->get('blocktype')), 'has_static_content') && !defined('BEHAT_TEST')) {
                    $block['class'] = 'staticblock';
                }
            }
+25 −8
Original line number Diff line number Diff line
@@ -738,7 +738,8 @@ EOD;
        $viewid = $this->get_view_id($view);

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

        $ids = get_records_sql_array($sql, array($page));
@@ -804,26 +805,42 @@ EOD;
     * @param View $view object of the current view
     * @param int $viewid of the View
     * @param string $title of the block instance to be created
     * @param int $viewcolcounts the current count of 1,2,3 column to create next block instance
     * @param int $viewcolcounts the current count of 0,1,2,.. column and 0,1,2,.. row to create next block instance
     * @param array $configdata holding data for new block instance
     * @param int $maxcols ~ 3
     * @param int $maxcols ~ 3 (1,2,3,4,6)
     * @param View $otherview for situations such as navigation where a block is related to another view
     */
    public static function create_new_block_instance($blocktype, $view, $viewid, $title, $viewcolcounts, $configdata, $maxcols, $otherview = null) {
        safe_require('blocktype', $blocktype);

        if (!in_array($maxcols, array(1,2,3,4,6))) $maxcols = 3;
        $blockwidth = 12/$maxcols;

        $bi = new BlockInstance(0,
            array(
                'blocktype'  => $blocktype,
                'title'      => $title,
                'view'       => $viewid,
                'row'        => 1,
            )
        );
        if (!isset(self::$viewcolcounts[$viewid])) self::$viewcolcounts[$viewid] = 0;
        $bi->set('order', $view->get_current_max_order(1, self::$viewcolcounts[$viewid]) + 1);


        if (!isset(self::$viewcolcounts[$viewid])) {
            self::$viewcolcounts[$viewid]['x'] = 0;
            self::$viewcolcounts[$viewid]['y'] = 0;
        }
        $bi->set('configdata', $configdata);
        $bi->set('column', self::$viewcolcounts[$viewid]);
        self::$viewcolcounts[$viewid] = ((self::$viewcolcounts[$viewid]+1) % $maxcols) ? (self::$viewcolcounts[$viewid]+1) % $maxcols : $maxcols;
        $bi->set('positionx', self::$viewcolcounts[$viewid]['x'] * $blockwidth);
        $bi->set('positiony', self::$viewcolcounts[$viewid]['y'] * 3);
        $bi->set('height', 3);
        $bi->set('width', $blockwidth);
        if ($newcol = (self::$viewcolcounts[$viewid]['x']+1) % $maxcols) {
            self::$viewcolcounts[$viewid]['x'] = $newcol;
        }
        else {
            self::$viewcolcounts[$viewid]['x'] = 0;
            self::$viewcolcounts[$viewid]['y']++;
        }

        //in cases such as navigation where we want to add a block to a different view than the current.
        if ($otherview) {
+8 −2
Original line number Diff line number Diff line
@@ -98,8 +98,14 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
    protected function find($selector, $locator, $exception = false, $node = false) {

        // Returns the first match.
        $items = $this->find_all($selector, $locator, $exception, $node);
        return count($items) ? reset($items) : null;
        if ($items = $this->find_all($selector, $locator, $exception, $node)) {
            foreach ($items as $key => $value) {
                if ($value->getTagName() != 'script') {
                    $returnitems[] = $value;
                }
            }
        }
        return count($returnitems) ? reset($returnitems) : null;
    }

    /**
+0 −1
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ Scenario: Testing that views & collections are collated properly

    Given I log in as "admin" with password "Kupuh1pa!"
    And I am on homepage
    And I scroll to the id 'bottom-pane'
    Then should see "(Author's name hidden)"
    And I follow "(Author's name hidden)"
    Then I should see "UserA"
+0 −2
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ Scenario: Viewing a list of pages I watch from the dashboard (Bug 1444784)
 And I select "Email" from "Watchlist"
 And I press "Save"
 And I am on homepage
 And I scroll to the id 'bottom-pane'
 And I follow "Page UserA_01"
 And I press "More options"
 And I follow "Add page to watchlist"
@@ -36,7 +35,6 @@ Scenario: Viewing a list of pages I watch from the dashboard (Bug 1444784)
 And I unsubscribe from "Page UserA_01" owned by "UserB"
 And I should see "You have unsubscribed successfully"
 And I am on homepage
 And I scroll to the id 'bottom-pane'
 And I follow "Page UserA_01"
 And I press "More options"
 And I should see "Add page to watchlist"
Loading