mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-04 11:19:39 -06:00
add missing helpers and context
remove core caching
This commit is contained in:
@@ -253,7 +253,6 @@ def main(ctx):
|
||||
codestyle(ctx) + \
|
||||
buildWebCache(ctx) + \
|
||||
[buildOcisBinaryForTesting(ctx)] + \
|
||||
cacheCoreReposForTesting(ctx) + \
|
||||
testOcisModules(ctx) + \
|
||||
testPipelines(ctx)
|
||||
|
||||
@@ -719,8 +718,7 @@ def localApiTestPipeline(ctx):
|
||||
localApiTests(suite, storage, params["extraEnvironment"]) +
|
||||
failEarly(ctx, early_fail),
|
||||
"services": redisForOCStorage(storage),
|
||||
"depends_on": getPipelineNames([buildOcisBinaryForTesting(ctx)]) +
|
||||
getPipelineNames(cacheCoreReposForTesting(ctx)),
|
||||
"depends_on": getPipelineNames([buildOcisBinaryForTesting(ctx)]),
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
@@ -937,8 +935,7 @@ def coreApiTests(ctx, part_number = 1, number_of_parts = 1, storage = "ocis", ac
|
||||
},
|
||||
] + failEarly(ctx, early_fail),
|
||||
"services": redisForOCStorage(storage),
|
||||
"depends_on": getPipelineNames([buildOcisBinaryForTesting(ctx)]) +
|
||||
getPipelineNames(cacheCoreReposForTesting(ctx)),
|
||||
"depends_on": getPipelineNames([buildOcisBinaryForTesting(ctx)]),
|
||||
"trigger": {
|
||||
"ref": [
|
||||
"refs/heads/master",
|
||||
|
||||
200
tests/TestHelpers/Asserts/WebDav.php
Normal file
200
tests/TestHelpers/Asserts/WebDav.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* 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/>
|
||||
*
|
||||
*/
|
||||
namespace TestHelpers\Asserts;
|
||||
|
||||
use Exception;
|
||||
use SimpleXMLElement;
|
||||
use TestHelpers\DownloadHelper;
|
||||
use TestHelpers\SetupHelper;
|
||||
|
||||
/**
|
||||
* WebDAV related asserts
|
||||
*/
|
||||
class WebDav extends \PHPUnit\Framework\Assert {
|
||||
/**
|
||||
*
|
||||
* @param string|null $element exception|message|reason
|
||||
* @param string|null $expectedValue
|
||||
* @param array|null $responseXml
|
||||
* @param string|null $extraErrorText
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function assertDavResponseElementIs(
|
||||
?string $element,
|
||||
?string $expectedValue,
|
||||
?array $responseXml,
|
||||
?string $extraErrorText = ''
|
||||
):void {
|
||||
if ($extraErrorText !== '') {
|
||||
$extraErrorText = $extraErrorText . " ";
|
||||
}
|
||||
self::assertArrayHasKey(
|
||||
'value',
|
||||
$responseXml,
|
||||
$extraErrorText . "responseXml does not have key 'value'"
|
||||
);
|
||||
if ($element === "exception") {
|
||||
$result = $responseXml['value'][0]['value'];
|
||||
} elseif ($element === "message") {
|
||||
$result = $responseXml['value'][1]['value'];
|
||||
} elseif ($element === "reason") {
|
||||
$result = $responseXml['value'][3]['value'];
|
||||
}
|
||||
|
||||
self::assertEquals(
|
||||
$expectedValue,
|
||||
$result,
|
||||
__METHOD__ . " " . $extraErrorText . "Expected '$expectedValue' in element $element got '$result'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $responseXmlObject
|
||||
* @param array|null $expectedShareTypes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function assertResponseContainsShareTypes(
|
||||
SimpleXMLElement $responseXmlObject,
|
||||
?array $expectedShareTypes
|
||||
):void {
|
||||
foreach ($expectedShareTypes as $row) {
|
||||
$xmlPart = $responseXmlObject->xpath(
|
||||
"//d:prop/oc:share-types/oc:share-type[.=" . $row[0] . "]"
|
||||
);
|
||||
self::assertNotEmpty(
|
||||
$xmlPart,
|
||||
"cannot find share-type '" . $row[0] . "'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the content of a remote and a local file is the same
|
||||
* or is different
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $username
|
||||
* @param string|null $password
|
||||
* @param string|null $remoteFile
|
||||
* @param string|null $localFile
|
||||
* @param string|null $xRequestId
|
||||
* @param bool $shouldBeSame (default true) if true then check that the file contents are the same
|
||||
* otherwise check that the file contents are different
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function assertContentOfRemoteAndLocalFileIsSame(
|
||||
?string $baseUrl,
|
||||
?string $username,
|
||||
?string $password,
|
||||
?string $remoteFile,
|
||||
?string $localFile,
|
||||
?string $xRequestId = '',
|
||||
?bool $shouldBeSame = true
|
||||
):void {
|
||||
$result = DownloadHelper::download(
|
||||
$baseUrl,
|
||||
$username,
|
||||
$password,
|
||||
$remoteFile,
|
||||
$xRequestId
|
||||
);
|
||||
|
||||
$localContent = \file_get_contents($localFile);
|
||||
$downloadedContent = $result->getBody()->getContents();
|
||||
|
||||
if ($shouldBeSame) {
|
||||
self::assertSame(
|
||||
$localContent,
|
||||
$downloadedContent
|
||||
);
|
||||
} else {
|
||||
self::assertNotSame(
|
||||
$localContent,
|
||||
$downloadedContent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the content of a remote file (downloaded by DAV)
|
||||
* and a file in the skeleton folder of the system under test is the same
|
||||
* or is different
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $username
|
||||
* @param string|null $password
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $remoteFile
|
||||
* @param string|null $fileInSkeletonFolder
|
||||
* @param string|null $xRequestId
|
||||
* @param bool $shouldBeSame (default true) if true then check that the file contents are the same
|
||||
* otherwise check that the file contents are different
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function assertContentOfDAVFileAndSkeletonFileOnSUT(
|
||||
?string $baseUrl,
|
||||
?string $username,
|
||||
?string $password,
|
||||
?string $adminUsername,
|
||||
?string $adminPassword,
|
||||
?string $remoteFile,
|
||||
?string $fileInSkeletonFolder,
|
||||
?string $xRequestId = '',
|
||||
?bool $shouldBeSame = true
|
||||
):void {
|
||||
$result = DownloadHelper::download(
|
||||
$baseUrl,
|
||||
$username,
|
||||
$password,
|
||||
$remoteFile,
|
||||
$xRequestId
|
||||
);
|
||||
$downloadedContent = $result->getBody()->getContents();
|
||||
|
||||
$localContent = SetupHelper::readSkeletonFile(
|
||||
$fileInSkeletonFolder,
|
||||
$xRequestId,
|
||||
$baseUrl,
|
||||
$adminUsername,
|
||||
$adminPassword
|
||||
);
|
||||
|
||||
if ($shouldBeSame) {
|
||||
self::assertSame(
|
||||
$localContent,
|
||||
$downloadedContent
|
||||
);
|
||||
} else {
|
||||
self::assertNotSame(
|
||||
$localContent,
|
||||
$downloadedContent
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
352
tests/TestHelpers/TagsHelper.php
Normal file
352
tests/TestHelpers/TagsHelper.php
Normal file
@@ -0,0 +1,352 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* 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/>
|
||||
*
|
||||
*/
|
||||
namespace TestHelpers;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Exception;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Helper to administer Tags
|
||||
*
|
||||
* @author Artur Neumann <artur@jankaritech.com>
|
||||
*
|
||||
*/
|
||||
class TagsHelper extends \PHPUnit\Framework\Assert {
|
||||
/**
|
||||
* tags a file
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $taggingUser
|
||||
* @param string|null $password
|
||||
* @param string|null $tagName
|
||||
* @param string|null $fileName
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $fileOwner
|
||||
* @param string|null $fileOwnerPassword
|
||||
* @param int|null $davPathVersionToUse (1|2)
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function tag(
|
||||
?string $baseUrl,
|
||||
?string $taggingUser,
|
||||
?string $password,
|
||||
?string $tagName,
|
||||
?string $fileName,
|
||||
?string $xRequestId = '',
|
||||
?string $fileOwner = null,
|
||||
?string $fileOwnerPassword = null,
|
||||
?int $davPathVersionToUse = 2,
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null
|
||||
):ResponseInterface {
|
||||
if ($fileOwner === null) {
|
||||
$fileOwner = $taggingUser;
|
||||
}
|
||||
|
||||
if ($fileOwnerPassword === null) {
|
||||
$fileOwnerPassword = $password;
|
||||
}
|
||||
|
||||
$fileID = WebDavHelper::getFileIdForPath(
|
||||
$baseUrl,
|
||||
$fileOwner,
|
||||
$fileOwnerPassword,
|
||||
$fileName,
|
||||
$xRequestId
|
||||
);
|
||||
|
||||
try {
|
||||
$tag = self::requestTagByDisplayName(
|
||||
$baseUrl,
|
||||
$taggingUser,
|
||||
$password,
|
||||
$tagName,
|
||||
$xRequestId
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
//the tag might be not accessible by the user
|
||||
//if we still want to find it, we need to try as admin
|
||||
if ($adminUsername !== null && $adminPassword !== null) {
|
||||
$tag = self::requestTagByDisplayName(
|
||||
$baseUrl,
|
||||
$adminUsername,
|
||||
$adminPassword,
|
||||
$tagName,
|
||||
$xRequestId
|
||||
);
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$tagID = self::getTagIdFromTagData($tag);
|
||||
$path = '/systemtags-relations/files/' . $fileID . '/' . $tagID;
|
||||
$response = WebDavHelper::makeDavRequest(
|
||||
$baseUrl,
|
||||
$taggingUser,
|
||||
$password,
|
||||
"PUT",
|
||||
$path,
|
||||
null,
|
||||
$xRequestId,
|
||||
null,
|
||||
$davPathVersionToUse,
|
||||
"systemtags"
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SimpleXMLElement $tagData
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getTagIdFromTagData(SimpleXMLElement $tagData):int {
|
||||
$tagID = $tagData->xpath(".//oc:id");
|
||||
self::assertArrayHasKey(
|
||||
0,
|
||||
$tagID,
|
||||
"cannot find id of tag"
|
||||
);
|
||||
|
||||
return (int) $tagID[0]->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* get all tags of a user
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param string|null $xRequestId
|
||||
* @param bool $withGroups
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function requestTagsForUser(
|
||||
?string $baseUrl,
|
||||
?string $user,
|
||||
?string $password,
|
||||
?string $xRequestId = '',
|
||||
?bool $withGroups = false
|
||||
):SimpleXMLElement {
|
||||
$properties = [
|
||||
'oc:id',
|
||||
'oc:display-name',
|
||||
'oc:user-visible',
|
||||
'oc:user-assignable',
|
||||
'oc:can-assign'
|
||||
];
|
||||
if ($withGroups) {
|
||||
\array_push($properties, 'oc:groups');
|
||||
}
|
||||
$response = WebDavHelper::propfind(
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
'/systemtags/',
|
||||
$properties,
|
||||
$xRequestId,
|
||||
'1',
|
||||
"systemtags"
|
||||
);
|
||||
return HttpRequestHelper::getResponseXml($response, __METHOD__);
|
||||
}
|
||||
|
||||
/**
|
||||
* find a tag by its name
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param string|null $tagDisplayName
|
||||
* @param string|null $xRequestId
|
||||
* @param bool $withGroups
|
||||
*
|
||||
* @return SimpleXMLElement
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function requestTagByDisplayName(
|
||||
?string $baseUrl,
|
||||
?string $user,
|
||||
?string $password,
|
||||
?string $tagDisplayName,
|
||||
?string $xRequestId = '',
|
||||
?bool $withGroups = false
|
||||
):SimpleXMLElement {
|
||||
$tagList = self::requestTagsForUser(
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
$xRequestId,
|
||||
$withGroups
|
||||
);
|
||||
$tagData = $tagList->xpath(
|
||||
"//d:prop//oc:display-name[text() ='$tagDisplayName']/.."
|
||||
);
|
||||
self::assertArrayHasKey(
|
||||
0,
|
||||
$tagData,
|
||||
"cannot find 'oc:display-name' property with text '$tagDisplayName'"
|
||||
);
|
||||
return $tagData[0];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|null $baseUrl see: self::makeDavRequest()
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param string|null $name
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $userVisible "true", "1" or "false", "0"
|
||||
* @param string|null $userAssignable "true", "1" or "false", "0"
|
||||
* @param string|null $userEditable "true", "1" or "false", "0"
|
||||
* @param string|null $groups separated by "|"
|
||||
* @param int|null $davPathVersionToUse (1|2)
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @link self::makeDavRequest()
|
||||
*/
|
||||
public static function createTag(
|
||||
?string $baseUrl,
|
||||
?string $user,
|
||||
?string $password,
|
||||
?string $name,
|
||||
?string $xRequestId = '',
|
||||
?string $userVisible = "true",
|
||||
?string $userAssignable = "true",
|
||||
?string $userEditable = "false",
|
||||
?string $groups = null,
|
||||
?int $davPathVersionToUse = 2
|
||||
):ResponseInterface {
|
||||
$tagsPath = '/systemtags/';
|
||||
$body = [
|
||||
'name' => $name,
|
||||
'userVisible' => $userVisible,
|
||||
'userAssignable' => $userAssignable,
|
||||
'userEditable' => $userEditable
|
||||
];
|
||||
|
||||
if ($groups !== null) {
|
||||
$body['groups'] = $groups;
|
||||
}
|
||||
|
||||
return WebDavHelper::makeDavRequest(
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
"POST",
|
||||
$tagsPath,
|
||||
['Content-Type' => 'application/json',],
|
||||
$xRequestId,
|
||||
\json_encode($body),
|
||||
$davPathVersionToUse,
|
||||
"systemtags"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @param int|null $tagID
|
||||
* @param string|null $xRequestId
|
||||
* @param int|null $davPathVersionToUse (1|2)
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public static function deleteTag(
|
||||
?string $baseUrl,
|
||||
?string $user,
|
||||
?string $password,
|
||||
?int $tagID,
|
||||
?string $xRequestId = '',
|
||||
?int $davPathVersionToUse = 1
|
||||
):ResponseInterface {
|
||||
$tagsPath = '/systemtags/' . $tagID;
|
||||
$response = WebDavHelper::makeDavRequest(
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
"DELETE",
|
||||
$tagsPath,
|
||||
[],
|
||||
$xRequestId,
|
||||
null,
|
||||
$davPathVersionToUse,
|
||||
"systemtags"
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the keyword(s) used for the type of tag
|
||||
* Tags can be "normal", "not user-assignable", "not user-visible" or "static"
|
||||
* That determines the tag attributes which are set when creating the tag.
|
||||
*
|
||||
* When creating the tag, the attributes can be enabled/disabled by specifying
|
||||
* either "true"/"false" or "1"/"0" in the request. Choose this "request style"
|
||||
* by passing the $useTrueFalseStrings parameter.
|
||||
*
|
||||
* @param string|null $type
|
||||
* @param boolean $useTrueFalseStrings use the strings "true"/"false" else "1"/"0"
|
||||
*
|
||||
* @return string[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function validateTypeOfTag(?string $type, ?bool $useTrueFalseStrings = true):array {
|
||||
if ($useTrueFalseStrings) {
|
||||
$trueValue = "true";
|
||||
$falseValue = "false";
|
||||
} else {
|
||||
$trueValue = "1";
|
||||
$falseValue = "0";
|
||||
}
|
||||
$userVisible = $trueValue;
|
||||
$userAssignable = $trueValue;
|
||||
$userEditable = $trueValue;
|
||||
switch ($type) {
|
||||
case 'normal':
|
||||
break;
|
||||
case 'not user-assignable':
|
||||
$userAssignable = $falseValue;
|
||||
break;
|
||||
case 'not user-visible':
|
||||
$userVisible = $falseValue;
|
||||
break;
|
||||
case 'static':
|
||||
$userEditable = $falseValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unsupported type');
|
||||
}
|
||||
|
||||
return [$userVisible, $userAssignable, $userEditable];
|
||||
}
|
||||
}
|
||||
@@ -354,6 +354,7 @@ default:
|
||||
- SearchContext:
|
||||
- PublicWebDavContext:
|
||||
- WebDavPropertiesContext:
|
||||
- TagsContext:
|
||||
- TrashbinContext:
|
||||
|
||||
coreApiWebdavPreviews:
|
||||
|
||||
2010
tests/acceptance/features/bootstrap/TagsContext.php
Normal file
2010
tests/acceptance/features/bootstrap/TagsContext.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -447,11 +447,12 @@ if [[ -n "${BEHAT_SUITE}" ]]
|
||||
then
|
||||
BEHAT_SUITES+=("${BEHAT_SUITE}")
|
||||
else
|
||||
if [[ -n "${RUN_PART}" && "${ACCEPTANCE_TEST_TYPE}" == "core-api" ]]
|
||||
then
|
||||
get_behat_suites "core"
|
||||
else
|
||||
get_behat_suites "${ACCEPTANCE_TEST_TYPE}"
|
||||
if [[ -n "${RUN_PART}" ]]; then
|
||||
if [[ "${ACCEPTANCE_TEST_TYPE}" == "core-api" ]]; then
|
||||
get_behat_suites "core"
|
||||
else
|
||||
get_behat_suites "${ACCEPTANCE_TEST_TYPE}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user