Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Acceptance test coding standard changes #31517

Merged
merged 1 commit into from
May 24, 2018
Merged
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
4 changes: 3 additions & 1 deletion tests/acceptance/features/bootstrap/AppConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ abstract public function theHTTPStatusCodeShouldBe($statusCode);
*
* @return void
*/
public function adminSetsServerParameterToUsingAPI($parameter, $app, $value) {
public function adminSetsServerParameterToUsingAPI(
$parameter, $app, $value
) {
$user = $this->currentUser;
$this->currentUser = $this->getAdminUsername();

Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance/features/bootstrap/AppManagementContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ public function setAppDirectories($dir1, $dir2) {
* @return void
*/
public function appHasBeenPutInDir($appId, $version, $dir) {
$ocVersion = \OC::$server->getConfig()->getSystemValue('version', '0.0.0');
$appInfo = sprintf(
$ocVersion = \OC::$server->getConfig()->getSystemValue(
'version', '0.0.0'
);
$appInfo = \sprintf(
'<?xml version="1.0"?>
<info>
<id>%s</id>
Expand Down
10 changes: 7 additions & 3 deletions tests/acceptance/features/bootstrap/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function userGeneratesNewAppPasswordNamed($name) {
$request->setHeader('requesttoken', $this->requestToken);
$request->setHeader('X-Requested-With', 'XMLHttpRequest');
$this->response = $this->client->send($request);
$this->appToken = json_decode($this->response->getBody()->getContents())->token;
$this->appToken
= \json_decode($this->response->getBody()->getContents())->token;
}

/**
Expand Down Expand Up @@ -145,7 +146,8 @@ public function aNewClientTokenHasBeenGenerated($user) {
]
]
);
$this->clientToken = json_decode($resp->getBody()->getContents())->token;
$this->clientToken
= \json_decode($resp->getBody()->getContents())->token;
}

/**
Expand All @@ -160,7 +162,9 @@ public function aNewClientTokenHasBeenGenerated($user) {
*/
public function userRequestsURLWithUsingBasicAuth($user, $url, $method) {
$authString = $user . ':' . $this->getPasswordForUser($user);
$this->sendRequest($url, $method, 'basic ' . base64_encode($authString));
$this->sendRequest(
$url, $method, 'basic ' . \base64_encode($authString)
);
}

/**
Expand Down
57 changes: 37 additions & 20 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ public function theXMLKey1Key2ValueShouldBe($key1, $key2, $idText) {
*
* @return void
*/
public function theXMLKey1Key2Key3ValueShouldBe($key1, $key2, $key3, $idText) {
public function theXMLKey1Key2Key3ValueShouldBe(
$key1, $key2, $key3, $idText
) {
PHPUnit_Framework_Assert::assertEquals(
$idText,
$this->getXMLKey1Key2Key3Value($this->response, $key1, $key2, $key3)
Expand Down Expand Up @@ -912,21 +914,28 @@ public function jsonRespondedShouldMatch(PyStringNode $jsonExpected) {
* @return void
*/
public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected) {
$jsonExpectedDecoded = json_decode($jsonExpected->getRaw(), true);
$jsonRespondedEncoded = json_encode(json_decode($this->response->getBody(), true));
$jsonExpectedDecoded = \json_decode($jsonExpected->getRaw(), true);
$jsonRespondedEncoded
= \json_encode(\json_decode($this->response->getBody(), true));
if ($this->runOcc(['status']) === 0) {
$output = explode("- ", $this->lastStdOut);
$version = explode(": ", $output[2]);
PHPUnit_Framework_Assert::assertEquals("version", $version[0]);
$versionString = explode(": ", $output[3]);
PHPUnit_Framework_Assert::assertEquals("versionstring", $versionString[0]);
$jsonExpectedDecoded['version'] = trim($version[1]);
$jsonExpectedDecoded['versionstring'] = trim($versionString[1]);
$jsonExpectedEncoded = json_encode($jsonExpectedDecoded);
$output = \explode("- ", $this->lastStdOut);
$version = \explode(": ", $output[2]);
PHPUnit_Framework_Assert::assertEquals(
"version", $version[0]
);
$versionString = \explode(": ", $output[3]);
PHPUnit_Framework_Assert::assertEquals(
"versionstring", $versionString[0]
);
$jsonExpectedDecoded['version'] = \trim($version[1]);
$jsonExpectedDecoded['versionstring'] = \trim($versionString[1]);
$jsonExpectedEncoded = \json_encode($jsonExpectedDecoded);
} else {
PHPUnit_Framework_Assert::fail('Cannot get version variables from occ');
}
PHPUnit\Framework\Assert::assertEquals($jsonExpectedEncoded, $jsonRespondedEncoded);
PHPUnit\Framework\Assert::assertEquals(
$jsonExpectedEncoded, $jsonRespondedEncoded
);
}

/**
Expand Down Expand Up @@ -1009,10 +1018,14 @@ public function substituteInLineCodes($value) {
*/
public static function removeFilesFromLocalStorageBefore() {
$dir = "./work/local_storage/";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file) : unlink($file);
$di = new RecursiveDirectoryIterator(
$dir, FilesystemIterator::SKIP_DOTS
);
$ri = new RecursiveIteratorIterator(
$di, RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($ri as $file) {
$file->isDir() ? \rmdir($file) : \unlink($file);
}
}

Expand All @@ -1023,10 +1036,14 @@ public static function removeFilesFromLocalStorageBefore() {
*/
public static function removeFilesFromLocalStorageAfter() {
$dir = "./work/local_storage/";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file) : unlink($file);
$di = new RecursiveDirectoryIterator(
$dir, FilesystemIterator::SKIP_DOTS
);
$ri = new RecursiveIteratorIterator(
$di, RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($ri as $file) {
$file->isDir() ? \rmdir($file) : \unlink($file);
}
}

Expand Down
9 changes: 6 additions & 3 deletions tests/acceptance/features/bootstrap/CalDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function setUpScenario(BeforeScenarioScope $scope) {
* @return void
*/
public function afterScenario() {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/admin/MyCalendar';
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/calendars/admin/MyCalendar';
try {
$this->client->delete(
$davUrl,
Expand All @@ -91,7 +92,8 @@ public function afterScenario() {
* @return void
*/
public function userRequestsCalendarUsingTheAPI($user, $calendar) {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/' . $calendar;
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/calendars/' . $calendar;

try {
$this->response = $this->client->get(
Expand Down Expand Up @@ -185,7 +187,8 @@ public function theCalDavErrorMessageShouldBe($message) {
* @return void
*/
public function userHasCreatedACalendarNamed($user, $name) {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/calendars/' . $user . '/' . $name;
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/calendars/' . $user . '/' . $name;

$request = $this->client->createRequest(
'MKCALENDAR',
Expand Down
18 changes: 12 additions & 6 deletions tests/acceptance/features/bootstrap/CapabilitiesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,29 @@ protected function resetAppConfigs() {
],
[
'capabilitiesApp' => 'files_sharing',
'capabilitiesParameter' => 'public@@@password@@@enforced_for@@@read_only',
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@read_only',
'testingApp' => 'core',
'testingParameter' => 'shareapi_enforce_links_password_read_only',
'testingParameter' =>
'shareapi_enforce_links_password_read_only',
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing',
'capabilitiesParameter' => 'public@@@password@@@enforced_for@@@read_write',
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@read_write',
'testingApp' => 'core',
'testingParameter' => 'shareapi_enforce_links_password_read_write',
'testingParameter' =>
'shareapi_enforce_links_password_read_write',
'testingState' => false
],
[
'capabilitiesApp' => 'files_sharing',
'capabilitiesParameter' => 'public@@@password@@@enforced_for@@@upload_only',
'capabilitiesParameter' =>
'public@@@password@@@enforced_for@@@upload_only',
'testingApp' => 'core',
'testingParameter' => 'shareapi_enforce_links_password_write_only',
'testingParameter' =>
'shareapi_enforce_links_password_write_only',
'testingState' => false
],
[
Expand Down
9 changes: 6 additions & 3 deletions tests/acceptance/features/bootstrap/CardDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function setUpScenario(BeforeScenarioScope $scope) {
* @return void
*/
public function afterScenario() {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/addressbooks/users/admin/MyAddressbook';
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/addressbooks/users/admin/MyAddressbook';
try {
$this->client->delete(
$davUrl,
Expand All @@ -92,7 +93,8 @@ public function afterScenario() {
* @throws \Exception
*/
public function userRequestsAddressbookUsingTheAPI($user, $addressBook) {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/addressbooks/users/' . $addressBook;
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/addressbooks/users/' . $addressBook;

try {
$this->response = $this->client->get(
Expand All @@ -116,7 +118,8 @@ public function userRequestsAddressbookUsingTheAPI($user, $addressBook) {
* @throws \Exception
*/
public function userHasCreatedAnAddressbookNamed($user, $addressBook) {
$davUrl = $this->featureContext->getBaseUrl() . '/remote.php/dav/addressbooks/users/' . $user . '/' . $addressBook;
$davUrl = $this->featureContext->getBaseUrl()
. '/remote.php/dav/addressbooks/users/' . $user . '/' . $addressBook;

$request = $this->client->createRequest(
'MKCOL',
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance/features/bootstrap/Checksums.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public function theWebdavChecksumShouldMatch($checksum) {
public function theHeaderChecksumShouldMatch($checksum) {
if ($this->response->getHeader('OC-Checksum') !== $checksum) {
throw new \Exception(
"Expected $checksum, got " . $this->response->getHeader('OC-Checksum')
"Expected $checksum, got "
. $this->response->getHeader('OC-Checksum')
);
}
}
Expand Down Expand Up @@ -166,7 +167,8 @@ public function theWebdavChecksumShouldBeEmpty() {
public function theOcChecksumHeaderShouldNotBeThere() {
if ($this->response->hasHeader('OC-Checksum')) {
throw new \Exception(
"Expected no checksum header but got " . $this->response->getHeader('OC-Checksum')
"Expected no checksum header but got "
. $this->response->getHeader('OC-Checksum')
);
}
}
Expand Down
26 changes: 17 additions & 9 deletions tests/acceptance/features/bootstrap/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ public function findLines($input, $text) {
public function theCommandShouldHaveBeenSuccessful() {
$exceptions = $this->findExceptions();
if ($this->lastCode !== 0) {
$msg = 'The command was not successful, exit code was ' . $this->lastCode . '.';
$msg = 'The command was not successful, exit code was '
. $this->lastCode . '.';
if (!empty($exceptions)) {
$msg .= ' Exceptions: ' . implode(', ', $exceptions);
}
throw new \Exception($msg);
} else if (!empty($exceptions)) {
$msg = 'The command was successful but triggered exceptions: ' . implode(', ', $exceptions);
} elseif (!empty($exceptions)) {
$msg = 'The command was successful but triggered exceptions: '
. \implode(', ', $exceptions);
throw new \Exception($msg);
}
}
Expand All @@ -156,7 +158,8 @@ public function theCommandShouldHaveBeenSuccessful() {
public function theCommandFailedWithExitCode($exitCode) {
if ($this->lastCode !== (int)$exitCode) {
throw new \Exception(
'The command was expected to fail with exit code ' . $exitCode . ' but got ' . $this->lastCode
'The command was expected to fail with exit code '
. $exitCode . ' but got ' . $this->lastCode
);
}
}
Expand All @@ -177,7 +180,8 @@ public function theCommandFailedWithExceptionText($exceptionText) {

if (!in_array($exceptionText, $exceptions)) {
throw new \Exception(
'The command did not throw any exception with the text "' . $exceptionText . '"'
'The command did not throw any exception with the text "'
. $exceptionText . '"'
);
}
}
Expand All @@ -194,7 +198,8 @@ public function theCommandOutputContainsTheText($text) {
$lines = $this->findLines($this->lastStdOut, $text);
if (empty($lines)) {
throw new \Exception(
'The command did not output the expected text on stdout "' . $text . '"'
'The command did not output the expected text on stdout "'
. $text . '"'
);
}
}
Expand All @@ -211,7 +216,8 @@ public function theCommandErrorOutputContainsTheText($text) {
$lines = $this->findLines($this->lastStdErr, $text);
if (empty($lines)) {
throw new \Exception(
'The command did not output the expected text on stderr "' . $text . '"'
'The command did not output the expected text on stderr "'
. $text . '"'
);
}
}
Expand Down Expand Up @@ -270,7 +276,8 @@ private function findLastTransferFolderForUser($sourceUser, $targetUser) {
*/
public function transferringOwnership($user1, $user2) {
if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) {
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
$this->lastTransferPath
= $this->findLastTransferFolderForUser($user1, $user2);
} else {
// failure
$this->lastTransferPath = null;
Expand Down Expand Up @@ -301,7 +308,8 @@ public function recreateMasterKeyUsingOccCommand() {
public function transferringOwnershipPath($path, $user1, $user2) {
$path = '--path=' . $path;
if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) {
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
$this->lastTransferPath
= $this->findLastTransferFolderForUser($user1, $user2);
} else {
// failure
$this->lastTransferPath = null;
Expand Down
33 changes: 17 additions & 16 deletions tests/acceptance/features/bootstrap/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,22 @@ public function userCommentsWithContentOnEntry($user, $content, $type, $path) {
$user,
"POST",
$commentsPath,
['Content-Type' => 'application/json',
],
['Content-Type' => 'application/json'],
null,
"uploads",
'{"actorId":"user0",
"actorDisplayName":"user0",
"actorType":"users",
"verb":"comment",
"message":"' . $content . '",
"creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT",
"objectType":"files"}'
"actorDisplayName":"user0",
"actorType":"users",
"verb":"comment",
"message":"' . $content . '",
"creationDateTime":"Thu, 18 Feb 2016 17:04:18 GMT",
"objectType":"files"}'
);
$responseHeaders = $this->response->getHeaders();
$commentUrl = $responseHeaders['Content-Location'][0];
$this->lastCommentId = substr($commentUrl, strrpos($commentUrl, '/') + 1);
$this->lastCommentId = \substr(
$commentUrl, \strrpos($commentUrl, '/') + 1
);
} catch (BadResponseException $ex) {
$this->response = $ex->getResponse();
}
Expand Down Expand Up @@ -250,13 +251,13 @@ public function editAComment($user, $content, $fileId, $commentId) {
null,
"uploads",
'<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:set>
<d:prop>
<oc:message>' . htmlspecialchars($content, ENT_XML1, 'UTF-8') . '</oc:message>
</d:prop>
</d:set>
</d:propertyupdate>'
<d:propertyupdate xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:set>
<d:prop>
<oc:message>' . \htmlspecialchars($content, ENT_XML1, 'UTF-8') . '</oc:message>
</d:prop>
</d:set>
</d:propertyupdate>'
);
} catch (BadResponseException $ex) {
$this->response = $ex->getResponse();
Expand Down
Loading