Skip to content

Commit

Permalink
Acceptance tests for webdav locking frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it authored and Vincent Petry committed Dec 13, 2018
1 parent 36f5b4d commit 7cf5737
Show file tree
Hide file tree
Showing 8 changed files with 1,359 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,15 @@ matrix:
CHOWN_SERVER: true
OWNCLOUD_LOG: true

- PHP_VERSION: 7.1
TEST_SUITE: selenium
BEHAT_SUITE: webUIWebdavLocks
DB_TYPE: mariadb
USE_SERVER: true
INSTALL_SERVER: true
CHOWN_SERVER: true
OWNCLOUD_LOG: true

# caldav test
- PHP_VERSION: 7.1
TEST_SUITE: caldav
Expand Down
12 changes: 12 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ default:
- WebUILoginContext:
- WebUISharingContext:

webUIWebdavLocks:
paths:
- %paths.base%/../features/webUIWebdavLocks
contexts:
- FeatureContext: *common_feature_context_params
- WebDavLockingContext:
- WebUIFilesContext:
- WebUIGeneralContext:
- WebUILoginContext:
- WebUIWebDavLockingContext:
- WebUISharingContext:

extensions:
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
filename: report.xml
Expand Down
147 changes: 147 additions & 0 deletions tests/acceptance/features/bootstrap/WebDavLockingContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @copyright Copyright (c) 2018 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/>
*
*/

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use TestHelpers\WebDavHelper;

require_once 'bootstrap.php';

/**
* context containing API steps needed for the locking mechanism of webdav
*/
class WebDavLockingContext implements Context {

/**
*
* @var FeatureContext
*/
private $featureContext;
/**
*
* @var string[][]
*/
private $tokenOfLastLock = [];

/**
* @When the user :user locks file/folder :file using the WebDAV API setting following properties
* @Given the user :user has locked file/folder :file setting following properties
*
* @param string $user
* @param string $file
* @param TableNode $properties table with no heading with | property | value |
*
* @return void
*/
public function lockFileUsingWebDavAPI($user, $file, TableNode $properties) {
$baseUrl = $this->featureContext->getBaseUrl();
$password = $this->featureContext->getPasswordForUser($user);
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:lockinfo xmlns:d='DAV:'> ";
$headers = [];
$propertiesRows = $properties->getRows();
foreach ($propertiesRows as $property) {
if ($property[0] === "depth") { //depth is set in the header not in the xml
$headers["Depth"] = $property[1];
} else {
$body .= "<d:$property[0]><d:$property[1]/></d:$property[0]>";
}
}

$body .= "</d:lockinfo>";
$response = WebDavHelper::makeDavRequest(
$baseUrl, $user, $password, "LOCK", $file, $headers, $body, null,
$this->featureContext->getDavPathVersion()
);
$responseXml = $this->featureContext->getResponseXml($response);
$responseXml->registerXPathNamespace('d', 'DAV:');
$xmlPart = $responseXml->xpath("//d:locktoken/d:href");
$this->tokenOfLastLock[$user][$file] = (string)$xmlPart[0];
}

/**
* @When the user :user unlocks the last created lock of file/folder :file using the WebDAV API
*
* @param string $user
* @param string $file
*
* @return void
*/
public function unlockLastLockUsingWebDavAPI($user, $file) {
$baseUrl = $this->featureContext->getBaseUrl();
$password = $this->featureContext->getPasswordForUser($user);
$headers = ["Lock-Token" => $this->tokenOfLastLock[$user][$file]];
WebDavHelper::makeDavRequest(
$baseUrl, $user, $password, "UNLOCK", $file, $headers, null, null,
$this->featureContext->getDavPathVersion()
);
}

/**
* @Then :count locks should be reported for file/folder :file of user :user by the WebDAV API
*
* @param int $count
* @param string $file
* @param string $user
*
* @return void
*/
public function numberOfLockShouldBeReported($count, $file, $user) {
$baseUrl = $this->featureContext->getBaseUrl();
$password = $this->featureContext->getPasswordForUser($user);
$body
= "<?xml version='1.0' encoding='UTF-8'?>" .
"<d:propfind xmlns:d='DAV:'> " .
"<d:prop><d:lockdiscovery/></d:prop>" .
"</d:propfind>";
$response = WebDavHelper::makeDavRequest(
$baseUrl, $user, $password, "PROPFIND", $file, null, $body, null,
$this->featureContext->getDavPathVersion()
);
$responseXml = $this->featureContext->getResponseXml($response);
$responseXml->registerXPathNamespace('d', 'DAV:');
$xmlPart = $responseXml->xpath("//d:response//d:lockdiscovery/d:activelock");
PHPUnit_Framework_Assert::assertCount(
(int)$count, $xmlPart,
"expected $count lock(s) for '$file' but found " . \count($xmlPart)
);
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
public function before(BeforeScenarioScope $scope) {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->featureContext = $environment->getContext('FeatureContext');
}
}
177 changes: 177 additions & 0 deletions tests/acceptance/features/bootstrap/WebUIWebDavLockingContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @copyright Copyright (c) 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/>
*
*/

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
use Page\FilesPage;
use Page\SharedWithYouPage;

require_once 'bootstrap.php';

/**
* context containing webUI steps needed for the locking mechanism of webdav
*/
class WebUIWebDavLockingContext extends RawMinkContext implements Context {

/**
*
* @var FilesPage
*/
private $filesPage;

/**
*
* @var SharedWithYouPage
*/
private $sharedWithYouPage;

/**
*
* @var WebUIGeneralContext
*/
private $webUIGeneralContext;

private $uploadConflictDialogTitle = "file conflict";

/**
* WebUIFilesContext constructor.
*
* @param FilesPage $filesPage
* @param SharedWithYouPage $sharedWithYouPage
*
* @return void
*/
public function __construct(
FilesPage $filesPage,
SharedWithYouPage $sharedWithYouPage
) {
$this->filesPage = $filesPage;
$this->sharedWithYouPage = $sharedWithYouPage;
}

/**
* @When the user unlocks the lock no :lockNumber of file/folder :file on the webUI
*
* @param int $lockNumber
* @param string $file
*
* @return void
*/
public function unlockFileOnTheWebui($lockNumber, $file) {
$this->closeDetailsDialog();
$pageObject = $this->webUIGeneralContext->getCurrentPageObject();
$fileRow = $pageObject->findFileRowByName($file, $this->getSession());
$fileRow->deleteLockByNumber($lockNumber, $this->getSession());
}

/**
* @Then file/folder :file should be marked as locked on the webUI
*
* @param string $file
*
* @return void
*/
public function theFileShouldBeMarkedAsLockedOnTheWebui($file) {
$this->closeDetailsDialog();
$pageObject = $this->webUIGeneralContext->getCurrentPageObject();
$fileRow = $pageObject->findFileRowByName($file, $this->getSession());
PHPUnit_Framework_Assert::assertTrue(
$fileRow->getLockState(),
"'$file' should be marked as locked, but its not"
);
}

/**
* @Then file/folder :file should not be marked as locked on the webUI
*
* @param string $file
*
* @return void
*/
public function theFileShouldNotBeMarkedAsLockedOnTheWebui($file) {
$this->closeDetailsDialog();
$pageObject = $this->webUIGeneralContext->getCurrentPageObject();
$fileRow = $pageObject->findFileRowByName($file, $this->getSession());
PHPUnit_Framework_Assert::assertFalse(
$fileRow->getLockState(),
"'$file' should not be marked as locked, but it is"
);
}

/**
* @Then file/folder :file should be marked as locked by user :lockedBy in the locks tab of the details panel on the webUI
*
* @param string $file
* @param string $lockedBy
*
* @return boolean
*/
public function theFileShouldBeMarkedAsLockedByUserInLocksTab(
$file, $lockedBy
) {
$this->closeDetailsDialog();
$pageObject = $this->webUIGeneralContext->getCurrentPageObject();
$fileRow = $pageObject->findFileRowByName($file, $this->getSession());
$lockDialog = $fileRow->openLockDialog();
$locks = $lockDialog->getAllLocks();
foreach ($locks as $lock) {
$locker = $lock->getLockingUser();
if ($lockedBy === $locker) {
return true;
}
}
PHPUnit_Framework_Assert::fail("cannot find a lock set by $lockedBy");
}

/**
* This will run before EVERY scenario.
* It will set the properties for this object.
*
* @BeforeScenario @webUI
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
public function before(BeforeScenarioScope $scope) {
// Get the environment
$environment = $scope->getEnvironment();
// Get all the contexts you need in this context
$this->webUIGeneralContext = $environment->getContext('WebUIGeneralContext');
}

/**
* closes any open details dialog but ignores any error (e.g. no dialog open)
*
* @return void
*/
private function closeDetailsDialog() {
$pageObject = $this->webUIGeneralContext->getCurrentPageObject();
try {
$pageObject->closeDetailsDialog();
} catch (Exception $e) {
//ignoge if dialog cannot be closed
//most likely there is no dialog open
}
}
}
Loading

0 comments on commit 7cf5737

Please sign in to comment.