Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Tests\Integration\Contexts;

use Behat\Step\Given;
use Behat\Step\Then;
use GuzzleHttp;
use PHPUnit\Framework\Assert;

require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

// The following attributes are expected to be available in the class that uses
// this trait:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require __DIR__ . '/../../vendor/autoload.php';

namespace OCA\Talk\Tests\Integration\Contexts;

require __DIR__ . '/../vendor/autoload.php';

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\Hook\AfterScenario;
Expand All @@ -19,16 +21,20 @@
use Behat\Step\Given;
use Behat\Step\Then;
use Behat\Step\When;
use DateTime;
use Exception;
use GuzzleHttp;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Exception\ClientException;
use JsonException;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;

/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext {
class FeatureContext implements Context {
public const TEST_PASSWORD = '123456';

/** @var array<string, string> */
Expand Down Expand Up @@ -213,8 +219,8 @@ public function getAttendeeId(string $type, string $id, string $room, ?string $u
*/
public function __construct() {
$this->cookieJars = [];
$this->localServerUrl = getenv('TEST_SERVER_URL');
$this->remoteServerUrl = getenv('TEST_REMOTE_URL');
$this->localServerUrl = getenv('TEST_SERVER_URL') ?: '';
$this->remoteServerUrl = getenv('TEST_REMOTE_URL') ?: '';

foreach (['LOCAL', 'REMOTE'] as $server) {
$this->changedConfigs[$server] = [];
Expand Down Expand Up @@ -275,7 +281,7 @@ public function setUp(BeforeScenarioScope $scope): void {
public function getOtherRequiredSiblingContexts(BeforeScenarioScope $scope): void {
$environment = $scope->getEnvironment();

$this->sharingContext = $environment->getContext('SharingContext');
$this->sharingContext = $environment->getContext(SharingContext::class);
}

#[AfterScenario]
Expand Down Expand Up @@ -4796,7 +4802,7 @@ public function userSendTheFileAsAvatarOfRoom(string $user, string $file, string
'multipart' => [
[
'name' => 'file',
'contents' => $file !== 'invalid' ? fopen(__DIR__ . '/../../../..' . $file, 'r') : '',
'contents' => $file !== 'invalid' ? fopen(__DIR__ . '/../../..' . $file, 'r') : '',
],
],
];
Expand Down Expand Up @@ -4943,7 +4949,7 @@ public function userStoreRecordingFileInRoom(string $user, string $file, string
// Upload a file
$options['multipart'][] = [
'name' => 'file',
'contents' => fopen(__DIR__ . '/../../../..' . $file, 'r'),
'contents' => fopen(__DIR__ . '/../../..' . $file, 'r'),
];
}
$this->sendRequest(
Expand Down Expand Up @@ -5020,7 +5026,7 @@ public function recordingServerUploadsRecordingFileToRequestedShare(string $file
if ($file === 'empty') {
$options['body'] = '';
} else {
$options['body'] = fopen(__DIR__ . '/../../../..' . $file, 'r');
$options['body'] = fopen(__DIR__ . '/../../..' . $file, 'r');
}

$client = new Client();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Tests\Integration\Contexts;

use Behat\Gherkin\Node\TableNode;
use Behat\Hook\AfterScenario;
use Behat\Step\Given;
Expand Down Expand Up @@ -165,8 +167,8 @@ private function startMockServer(string $path) {

$descriptorSpec = [
0 => $stdin,
1 => [ 'file', $stdoutf, 'a' ],
2 => [ 'file', $stderrf, 'a' ],
1 => ['file', $stdoutf, 'a'],
2 => ['file', $stderrf, 'a'],
];

$process = proc_open($fullCmd, $descriptorSpec, $pipes, $cwd, $env, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Talk\Tests\Integration\Contexts;

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use Behat\Step\Given;
use Behat\Step\Then;
use Behat\Step\When;
use GuzzleHttp;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -477,10 +480,10 @@ public function userGetsTheShareTypeDavPropertyFor(string $user, string $path):
$headers = null;

$body = '<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">'
. ' <d:prop>'
. ' <oc:share-types/>'
. ' </d:prop>'
. '</d:propfind>';
. ' <d:prop>'
. ' <oc:share-types/>'
. ' </d:prop>'
. '</d:propfind>';

$this->sendingToDav('PROPFIND', $url, $headers, $body);

Expand Down Expand Up @@ -610,17 +613,17 @@ public function shareXIsReturnedWith(int $number, TableNode $body): void {
$expectedFields = array_merge($defaultExpectedFields, $fields);

if (!array_key_exists('uid_file_owner', $expectedFields)
&& array_key_exists('uid_owner', $expectedFields)) {
&& array_key_exists('uid_owner', $expectedFields)) {
$expectedFields['uid_file_owner'] = $expectedFields['uid_owner'];
}
if (!array_key_exists('displayname_file_owner', $expectedFields)
&& array_key_exists('displayname_owner', $expectedFields)) {
&& array_key_exists('displayname_owner', $expectedFields)) {
$expectedFields['displayname_file_owner'] = $expectedFields['displayname_owner'];
}

if (array_key_exists('share_type', $expectedFields)
&& $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */
&& array_key_exists('share_with', $expectedFields)) {
&& $expectedFields['share_type'] == 10 /* IShare::TYPE_ROOM */
&& array_key_exists('share_with', $expectedFields)) {
if ($expectedFields['share_with'] === 'private_conversation') {
$expectedFields['share_with'] = 'REGEXP /^private_conversation_[0-9a-f]{6}$/';
$expectedFields['share_with_link'] = '';
Expand Down Expand Up @@ -738,7 +741,7 @@ public function theResponseContainsAShareTypesFilesPropertyForWith(string $path,
$response = json_decode($this->responseBody);

$fileForPath = array_filter($response->files, function ($file) use ($path) {
$filePath = $file->path . (substr($file->path, -1) === '/'? '': '/');
$filePath = $file->path . (substr($file->path, -1) === '/' ? '' : '/');
return ($filePath . $file->name) === $path;
});

Expand Down
47 changes: 47 additions & 0 deletions tests/integration/behat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Formatter\JUnitFormatter;
use Behat\Config\Formatter\PrettyFormatter;
use Behat\Config\Profile;
use Behat\Config\Suite;
use OCA\Talk\Tests\Integration\Behat\GithubActions\GithubActionsExtension;
use OCA\Talk\Tests\Integration\Contexts\FeatureContext;
use OCA\Talk\Tests\Integration\Contexts\SharingContext;

return (new Config())
->withProfile((new Profile('default', [
'autoload' => [
'' => '%paths.base%/features/bootstrap',
],
]))
->withFormatter((new JUnitFormatter())
->withOutputPath('%paths.base%/output'))
->withFormatter((new PrettyFormatter())
->withOutputStyles([
'comment' => [
'bright-blue',
],
]))
->withExtension(new Extension(GithubActionsExtension::class))
->withSuite((new Suite('default'))
->addContext(FeatureContext::class)
->addContext(
SharingContext::class,
[
'baseUrl' => 'http://localhost:8080/',
'admin' => [
'admin',
'admin',
],
'regularUserPassword' => 123456,
]
)
->withPaths('%paths.base%/features')));
5 changes: 3 additions & 2 deletions tests/integration/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
},
"autoload": {
"psr-4": {
"OCA\\Talk\\Tests\\Integration\\Behat\\GithubActions\\": "github-actions-formatter/"
"OCA\\Talk\\Tests\\Integration\\Behat\\GithubActions\\": "github-actions-formatter/",
"OCA\\Talk\\Tests\\Integration\\Contexts\\": "Contexts/"
}
},
"require-dev": {
"behat/behat": "^3.32.0",
"behat/behat": "^4.0.0-alpha1@alpha",
"guzzlehttp/guzzle": "^8.1.0",
"phpunit/phpunit": "^12.5"
}
Expand Down
35 changes: 18 additions & 17 deletions tests/integration/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions tests/integration/config/behat.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public function getOutputPrinter(): OutputPrinter {
return $this->printer;
}

public function setParameter($name, $value): void {
public function setParameter(string $name, $value): void {
$this->parameters[$name] = $value;

if ($name === 'base_path' && is_string($value) && $value !== '') {
$this->basePath = rtrim($value, '/');
}
}

public function getParameter($name) {
public function getParameter(string $name): mixed {
return $this->parameters[$name] ?? null;
}

Expand Down
Loading