Skip to content

Commit

Permalink
Merge pull request #29323 from owncloud/stable10-fix-grpname-0
Browse files Browse the repository at this point in the history
[stable10] allow group named "0" to be deleted
  • Loading branch information
phil-davis authored Oct 23, 2017
2 parents 9c5ea40 + 479aa5b commit 5e29c03
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 33 deletions.
3 changes: 2 additions & 1 deletion settings/js/users/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GroupList = {
var $li = $userGroupList.find('.isgroup:last-child').clone();
$li
.data('gid', gid)
.attr('data-gid', gid)
.find('.groupname').text(gid);
GroupList.setUserCount($li, usercount);

Expand Down Expand Up @@ -294,7 +295,7 @@ GroupList = {
},

getElementGID: function (element) {
return ($(element).closest('li').data('gid') || '').toString();
return ($(element).closest('li').attr('data-gid') || '').toString();
},
getEveryoneCount: function () {
$.ajax({
Expand Down
7 changes: 7 additions & 0 deletions tests/TestHelpers/SetupHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public static function deleteGroup($groupName) {
return self::runOcc(['group:delete', $groupName]);
}

/**
*
* @return string[]
*/
public static function getGroups() {
return json_decode(self::runOcc(['group:list', '--output=json'])['stdOut']);
}
/**
*
* @param HookScope $scope
Expand Down
16 changes: 15 additions & 1 deletion tests/ui/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,25 @@ public function addUserToCreatedUsersList(
* @return void
*/
public function addGroupToCreatedGroupsList($group) {
if (!in_array($group, $this->createdGroupNames)) {
if (!in_array($group, $this->createdGroupNames, true)) {
array_push($this->createdGroupNames, $group);
}
}

/**
* deletes a group from the lists of groups that were created during test runs
* useful if a group got created during the setup phase but got deleted in a
* test run. We don't want to try to delete this group again in the tear-down phase
*
* @param string $group
* @return void
*/
public function deleteGroupFromCreatedGroupsList($group) {
if (($key = array_search($group, $this->createdGroupNames, true)) !== false) {
unset($this->createdGroupNames[$key]);
}
}

/**
*
* @param string $username
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Page\OwncloudPage;
use Page\LoginPage;
use TestHelpers\SetupHelper;
use OC\Setup;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -136,6 +137,37 @@ public function iShouldBeRedirectedToAPageWithTheTitle($title) {
PHPUnit_Framework_Assert::assertEquals($title, trim($actualTitle));
}

/**
* @Then the group named :name should not exist
* @return void
*/
public function theGroupNamedShouldNotExist($name) {
if (in_array($name, SetupHelper::getGroups(), true)) {
throw new Exception("group '" . $name . "' exists but should not");
}
}

/**
* @Then /^these groups should (not|)\s?exist:$/
* expects a table of groups with the heading "groupname"
* @param string $shouldOrNot (not|)
* @param TableNode $table
* @return void
*/
public function theseGroupsShouldNotExist($shouldOrNot, TableNode $table) {
$should = ($shouldOrNot !== "not");
$groups = SetupHelper::getGroups();
foreach ($table as $row) {
if (in_array($row['groupname'], $groups, true) !== $should) {
throw new Exception(
"group '" . $row['groupname'] .
"' does" . ($should ? " not" : "") .
" exist but should" . ($should ? "" : " not")
);
}
}
}

/**
* @BeforeScenario
* @param BeforeScenarioScope $scope
Expand Down
57 changes: 57 additions & 0 deletions tests/ui/features/bootstrap/UsersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class UsersContext extends RawMinkContext implements Context {


private $usersPage;
/**
*
* @var FeatureContext
*/
private $featureContext;

/**
Expand Down Expand Up @@ -109,6 +113,59 @@ public function iCreateAUserInTheGUI(
}
}

/**
* @When I delete the group named :name
* @return void
*/
public function iDeleteTheGroupNamed($name) {
$this->usersPage->deleteGroup($name, $this->getSession());
$this->featureContext->deleteGroupFromCreatedGroupsList($name);
}

/**
* @When I delete these groups:
* expects a table of groups with the heading "groupname"
* @param TableNode $table
* @return void
*/
public function iDeleteTheseGroups(TableNode $table) {
foreach ($table as $row) {
$this->iDeleteTheGroupNamed($row['groupname']);
}
}

/**
* @Then the group named :name should not be listed
* @param string $name
* @return void
*/
public function theGroupNamedShouldNotBeListed($name) {
if (in_array($name, $this->usersPage->getAllGroups(), true)) {
throw new Exception("group '" . $name . "' is listed but should not");
}
}

/**
* @Then /^these groups should (not|)\s?be listed:$/
* expects a table of groups with the heading "groupname"
* @param string $shouldOrNot (not|)
* @param TableNode $table
* @return void
*/
public function theseGroupsShouldBeListed($shouldOrNot, TableNode $table) {
$should = ($shouldOrNot !== "not");
$groups = $this->usersPage->getAllGroups();
foreach ($table as $row) {
if (in_array($row['groupname'], $groups, true) !== $should) {
throw new Exception(
"group '" . $row['groupname'] .
"' is" . ($should ? " not" : "") .
" listed but should" . ($should ? "" : " not") . " be"
);
}
}
}

/**
* @When the users page is reloaded
* @return void
Expand Down
29 changes: 0 additions & 29 deletions tests/ui/features/lib/FilesPageBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,6 @@ public function getSizeOfFileFolderList() {
);
}

/**
* Surround the text with single or double quotes, whichever does not
* already appear in the text. If the text contains both single and
* double quotes, then throw an InvalidArgumentException.
*
* The returned string is intended for use as part of an xpath (v1).
* xpath (v1) has no way to escape the quote character within a string
* literal. So there is no way to directly use a string containing
* both single and double quotes.
*
* @param string $text
* @return string the text surrounded by single or double quotes
* @throws \InvalidArgumentException
*/
public function quotedText($text) {
if (strstr($text, "'") === false) {
return "'" . $text . "'";
} else if (strstr($text, '"') === false) {
return '"' . $text . '"';
} else {
// The text contains both single and double quotes.
// With current xpath v1 there is no way to encode that.
throw new \InvalidArgumentException(
"mixing both single and double quotes is unsupported - '"
. $text . "'"
);
}
}

/**
* @param int $number
* @return \Behat\Mink\Element\NodeElement|null
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/features/lib/OwncloudPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,33 @@ protected function cleanInputAndSetValue(NodeElement $inputField, $value) {
throw new \Exception("value of input field is not what we expect");
}
}

/**
* Surround the text with single or double quotes, whichever does not
* already appear in the text. If the text contains both single and
* double quotes, then throw an InvalidArgumentException.
*
* The returned string is intended for use as part of an xpath (v1).
* xpath (v1) has no way to escape the quote character within a string
* literal. So there is no way to directly use a string containing
* both single and double quotes.
*
* @param string $text
* @return string the text surrounded by single or double quotes
* @throws \InvalidArgumentException
*/
public function quotedText($text) {
if (strstr($text, "'") === false) {
return "'" . $text . "'";
} else if (strstr($text, '"') === false) {
return '"' . $text . '"';
} else {
// The text contains both single and double quotes.
// With current xpath v1 there is no way to encode that.
throw new \InvalidArgumentException(
"mixing both single and double quotes is unsupported - '"
. $text . "'"
);
}
}
}
107 changes: 107 additions & 0 deletions tests/ui/features/lib/UserPageElement/GroupList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @copyright 2017 Artur Neumann artur@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace Page\UserPageElement;

use Behat\Mink\Element\NodeElement;
use Page\OwncloudPage;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;

/**
* The list of groups
*
*/
class GroupList extends OwncloudPage {

/**
* @var NodeElement of this element
*/
protected $groupListElement;
protected $allGroupsXpath = "//li[@class='isgroup']";
protected $groupLiXpath = "//li[@data-gid=%s]";
protected $deleteBtnXpath = "//a[@class='action delete']";

/**
* sets the NodeElement for the current group list
* a little bit like __construct() but as we access this "sub-page-object"
* from an other Page Object by $this->getPage("OwncloudPageElement\\GroupList")
* there is no real __construct() that can take arguments
*
* @param \Behat\Mink\Element\NodeElement $groupListElement
* @return void
*/
public function setElement(NodeElement $groupListElement) {
$this->groupListElement = $groupListElement;
}

/**
*
* @param string $name
* @throws ElementNotFoundException
* @return \Behat\Mink\Element\NodeElement
*/
public function selectGroup($name) {
$name = $this->quotedText($name);
$groupLi = $this->groupListElement->find(
"xpath", sprintf($this->groupLiXpath, $name)
);
if ($groupLi === null) {
throw new ElementNotFoundException("cannot find group list element");
}
$groupLi->click();
return $groupLi;
}

/**
* deletes a group in the UI
*
* @param string $name
* @throws ElementNotFoundException
* @return void
*/
public function deleteGroup($name) {
$groupLi = $this->selectGroup($name);
$deleteButton = $groupLi->find("xpath", $this->deleteBtnXpath);
if ($deleteButton === null) {
throw new ElementNotFoundException("cannot find delete button");
}
$deleteButton->click();
}

/**
* returns all group names in an array
*
* @return string[]
*/
public function namesToArray() {
$allGroupElements = $this->groupListElement->findAll(
"xpath", $this->allGroupsXpath
);
$allGroups = [];
foreach ($allGroupElements as $element) {
$allGroups[] = $element->getText();
}
return $allGroups;
}
}

Loading

0 comments on commit 5e29c03

Please sign in to comment.