Commit 0e99bd47 authored by Rebecca Blundell's avatar Rebecca Blundell Committed by Robert Lyon
Browse files

Bug 1755688: Behat: Share page with different groups

includes changes to i_click_on_element function

Change-Id: I5ab31daa968839709e1b7729da6536adbfe59b44
parent fd9bee31
......@@ -718,4 +718,25 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
return false;
}
/**
* @param string $element - thing to look for
* @param string $selectortype - e.g. css/xpath
*/
protected function i_click_on_element($element, $selectortype='css_element') {
// Getting Mink selector and locator.
list($selector, $locator) = $this->transform_selector($selectortype, $element);
// Will throw an ElementNotFoundException if it does not exist.
$this->find($selector, $locator);
$page = $this->getSession()->getPage();
$element = $page->find($selector , $locator);
if (empty($element)) {
throw new Exception("No html element found for the selector ('$element')");
}
$element->click();
}
}
......@@ -178,6 +178,46 @@ class BehatForms extends BehatBase {
$this->getSession()->wait(10000, "(jQuery('#select2-{$field}-results .loading-results').length === 0)");
}
/**
*
* Open select2 share menu and choose item by value from optgroup label
*
* @When I select :value from :label in shared with select2 box
* @When /^I select "(?P<value>(?:[^"]|\\")*)" from "(?P<label>(?:[^"]|\\")*)" in shared with select2 box$/
* @param string $value
* @param string $label
*/
public function share_with_select2($value, $label) {
//make select2 list visible on page
$this->i_click_on_element("span.picker.input-short", "css_element");
//set id for option list
$locator = "";
$selectortype = "css_element";
switch ($label) {
case "Search for...":
$id = substr($value, 0, -1);
$locator = "#$id";
break;
case "General":
$value = strtolower($value);
$id = "#potentialpresetitemssharewith";
$value = ($value == "registered users" ? "loggedin" : $value);
break;
//works on name, not display name
case "Institutions":
$id = "#potentialpresetitemsinstitutions";
break;
case "Groups":
$id = "potentialpresetitemsgroups";
$selectortype = "xpath_element";
$locator = "//*[@id=\"$id\"]/option[contains(., \"$value\")]";
break;
}
//set css to find
$locator = (empty($locator) ? "$id>option[value='$value']" : $locator);
$this->i_click_on_element($locator, $selectortype);
}
/**
* Select value in choice list
*
......
......@@ -364,21 +364,6 @@ class BehatGeneral extends BehatBase {
$node->keyPress($key_press);
}
/**
* @Given I click on the :selector element
* @param string $selector - css selector
*/
public function i_click_on_the($selector) {
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
if (empty($element)) {
throw new Exception("No html element found for the selector ('$selector')");
}
$element->click();
}
/**
* Click on the link or button which is located inside the second element.
*
......@@ -686,6 +671,18 @@ class BehatGeneral extends BehatBase {
$this->getSession()->executeScript($jscode);
}
/**
* @Given /^I click on the "(?P<element>(?:[^"]|\\")*)" "(?P<tselectortype>[^"]*)"$/
*
* calls function in parent class
*
* @param string $element - thing to look for
* @param string $selectortype - e.g. css/xpath
*/
public function i_click_on_element($element, $selectortype='css_element') {
parent::i_click_on_element($element, $selectortype);
}
/**
* Click on the delete button inside a list/table row containing the specified text.
*
......@@ -882,7 +879,7 @@ class BehatGeneral extends BehatBase {
*/
public function click_on_property($property) {
$property = get_property($property);
$this->i_click_on_the($property[0]);
$this->i_click_on_element($property[0], $property[1]);
}
/**
......
@javascript @core
Feature: Share page with different people (Bug 1755688)
As a user
I want to control access to my pages
So that people I choose can see them
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| UserA | Kupuh1pa! | UserA@example.org | Angela | User | mahara | internal | member |
| UserB | Kupuh1pa! | UserB@example.org | Bob | User | mahara | internal | member |
| UserC | Kupuh1pa! | UserC@example.org | Cecilia | User | mahara | internal | member |
And the following "groups" exist:
| name | owner | description | grouptype | open | invitefriends | editroles | submittableto | allowarchives | members | staff |
| GroupA | UserA | GroupA owned by UserA | standard | ON | OFF | all | OFF | OFF | UserB | |
| GroupB | admin | GroupB owned by admin | standard | ON | ON | all | ON | ON | UserA, UserB, UserC | |
And the following "pages" exist:
| title | description | ownertype | ownername |
| Page UserA_01 | Page 01 | user | UserA |
| Page UserB_02 | Page 02 | user | UserB |
| Page UserA_03 | Page 03 | user | UserA |
| Page UserA_04 | Page 04 | user | UserA |
Scenario: Check share page with friends
# Log in as a normal userA
Given I log in as "UserA" with password "Kupuh1pa!"
# Edit access for Page 03
And I choose "Find people" in "Groups" from main menu
And I click on "Send friend request" in "Bob User" row
And I set the field "Message" to "Love me, love me, say you do!"
And I press "Request friendship"
And I log out
And I log in as "UserB" with password "Kupuh1pa!"
And I follow "pending friend"
And I click on "Approve request"
And I choose "Pages and collections" in "Portfolio" from main menu
And I click on "Manage access" in "Page UserB_02" panel access menu
And I select "Friends" from "General" in shared with select2 box
And I press "Save"
And I log out
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Shared with me" in "Portfolio" from main menu
And I check "Friends"
And I uncheck "Me"
And I uncheck "My groups"
And I press "Search"
Then I should see "Page UserB_02"
Scenario: Check share page with Registered Users
# Log in as a normal userA
Given I log in as "UserA" with password "Kupuh1pa!"
# Edit access for Page 03
And I choose "Pages and collections" in "Portfolio" from main menu
And I click on "Manage access" in "Page UserA_03" panel access menu
And I select "Registered users" from "General" in shared with select2 box
And I press "Save"
And I log out
And I log in as "UserB" with password "Kupuh1pa!"
And I choose "Shared with me" in "Portfolio" from main menu
And I check "Registered users"
And I uncheck "Me"
And I uncheck "Friends"
And I uncheck "My groups"
And I uncheck "Public"
And I press "Search"
Then I should see "Page UserA_03"
Scenario: Check share page with groups and that copy options works
# Log in as a normal userA
Given I log in as "UserA" with password "Kupuh1pa!"
# Edit access for Page 03
And I choose "Pages and collections" in "Portfolio" from main menu
And I click on "Manage access" in "Page UserA_03" panel access menu
And I select "GroupA" from "Groups" in shared with select2 box
And I select "GroupB" from "Groups" in shared with select2 box
And I expand "Advanced options" node
# enable copy switch
And I enable the switch "Allow copying"
And I should see "Retain view access on copied pages or collections"
And I press "Save"
And I log out
And I log in as "UserB" with password "Kupuh1pa!"
And I choose "Shared with me" in "Portfolio" from main menu
And I check "My groups"
And I uncheck "Me"
And I uncheck "Friends"
And I press "Search"
And I follow "Page UserA_03"
# check copy option is available
Then I should see "Copy"
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