Skip to content

Commit

Permalink
add missing helpers and context
Browse files Browse the repository at this point in the history
remove core caching
  • Loading branch information
saw-jan committed Jan 4, 2023
1 parent c3a3653 commit ce314a1
Show file tree
Hide file tree
Showing 5 changed files with 2,565 additions and 5 deletions.
7 changes: 2 additions & 5 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def main(ctx):
codestyle(ctx) + \
buildWebCache(ctx) + \
[buildOcisBinaryForTesting(ctx)] + \
cacheCoreReposForTesting(ctx) + \
testOcisModules(ctx) + \
testPipelines(ctx)

Expand Down Expand Up @@ -725,8 +724,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",
Expand Down Expand Up @@ -944,8 +942,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",
Expand Down
200 changes: 200 additions & 0 deletions tests/TestHelpers/Asserts/WebDav.php
Original file line number Diff line number Diff line change
@@ -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
);
}
}
}
Loading

0 comments on commit ce314a1

Please sign in to comment.