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

Acceptance test refactoring and bug fixes #31523

Merged
merged 10 commits into from
May 25, 2018
Merged

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented May 24, 2018

Description

  1. Put in "missing" use statements
  2. Fix a call to isInTrash``` that had too many/wrong parameters. The test elementIsNotInTrashCheckingOriginalPath`` always passed, now it could fail.
  3. Fix a wrong proppatch call in changeFavStateOfAnElement - I don't think the test was actually broken.
  4. Sort out a few inconsistencies in return values and what the docblock said.
  5. Remove unused parameters in various functions. Change the corresponding Gherkin regex to not capture the unused things.
  6. Enhance a couple of places where the IDE thought that a var might be undefined.
  7. Add throws tags to loads of docblocks.

Motivation and Context

Cleanup acceptance test code and let the IDE find dodgy-looking stuff.

How Has This Been Tested?

Local CI running.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Acceptance test refactoring and bug fixes

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@phil-davis phil-davis added this to the development milestone May 24, 2018
@phil-davis phil-davis self-assigned this May 24, 2018
@phil-davis phil-davis changed the title Acceptance test use 01 Acceptance test refactoring and bug fixes May 24, 2018
@phil-davis phil-davis requested a review from individual-it May 24, 2018 12:11
@phil-davis phil-davis force-pushed the acceptance-test-use-01 branch from d45cfea to 029ec58 Compare May 24, 2018 12:46
@phil-davis phil-davis force-pushed the acceptance-test-use-01 branch from 029ec58 to 9027a0a Compare May 25, 2018 04:32
@codecov
Copy link

codecov bot commented May 25, 2018

Codecov Report

Merging #31523 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #31523   +/-   ##
=========================================
  Coverage     62.61%   62.61%           
  Complexity    18273    18273           
=========================================
  Files          1147     1147           
  Lines         68627    68627           
  Branches       1234     1234           
=========================================
  Hits          42971    42971           
  Misses        25295    25295           
  Partials        361      361
Flag Coverage Δ Complexity Δ
#javascript 52.05% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 63.81% <ø> (ø) 18273 <ø> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f801491...0720641. Read the comment docs.

@@ -185,10 +185,10 @@ Feature: tags
When user "user0" adds the tag "MyFirstTag" to "/myFileToTag.txt" owned by "user0" using the API
And user "another_admin" adds the tag "MySecondTag" to "/myFileToTag.txt" shared by "user0" using the API
Then the HTTP status code should be "201"
And file "/myFileToTag.txt" shared by "user0" should have the following tags for "another_admin"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, "user0" was not used by this step. It does not matter here which user is the one who shared the file. So I removed that from the step definition.

@@ -86,7 +86,7 @@ Feature: trashbin-new-endpoint
And user "user0" has deleted file "/textfile0.txt"
And user "user0" has deleted file "/textfile1.txt"
And as "user0" the file "/textfile0.txt" should exist in trash
And as "user0" the file "/textfile0.txt" should exist in trash
And as "user0" the file "/textfile1.txt" should exist in trash
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dumb cut-paste error was here - the test was being doen twice on the same file.

@@ -929,12 +929,12 @@ public function statusPhpRespondedShouldMatch(PyStringNode $jsonExpected) {
$jsonExpectedDecoded['version'] = \trim($version[1]);
$jsonExpectedDecoded['versionstring'] = \trim($versionString[1]);
$jsonExpectedEncoded = \json_encode($jsonExpectedDecoded);
PHPUnit\Framework\Assert::assertEquals(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this up here so the IDE does not shout at me about the vars being maybe undefined.

@@ -243,7 +245,6 @@ public function theseUsersHaveBeenCreated($doNotInitialize, TableNode $table) {
* @return void
*/
public function theAppHasBeenDisabled($app) {
$client = new Client();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a random unused var.

@@ -320,7 +321,6 @@ private function checkUserDownload($url, $options, $mimeType) {
// read everything
$buf .= $body->read(8192);
}
$mimeType = 'text/plain';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was accidentally left hard-coded here when the function was added recently.
Actually $mimeType is passed in as a parameter.

$elementRows = $TableNode->getRows();

if ($elementRows[0][0] === '') {
//It shouldn't have public shares
PHPUnit_Framework_Assert::assertEquals(\count($dataResponded), 0);
return 0;
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just want to return early in this case - no need to return 0

@@ -36,7 +36,7 @@
*/
public function emptyTrashbin($user) {
$body = new \Behat\Gherkin\Node\TableNode(
[['allfiles', 'true'], ['dir', '%2F']]
Copy link
Contributor Author

@phil-davis phil-davis May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending an encoded \ using %2F does not work in the body. When the dir is "hidden" inside the body then there is no need to urlEncode anything.
The test previously passed only because elementIsNotInTrashCheckingOriginalPath() was broken - that Then gherkin step would always pass, even though the trash bin had not actually been emptied.

) {
PHPUnit_Framework_Assert::assertFalse(
$this->isInTrash($user, $entryText, $originalPath),
Copy link
Contributor Author

@phil-davis phil-davis May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the broken line - isInTrash() actually takes 2 parameters. Somehow passing it 3 parameters did not make PHP explode. So it was passing values like file folder in the position where originalPath should go.

false would always be returned, because the trashbin indeed did not have a file called file or a file called folder

*/
public function theResponseShouldContainACustomPropertyWithValue(
$propertyName, $propertyValue, $table=null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodness knows what $table was doing here???

@@ -701,7 +699,7 @@ public function theSingleResponseShouldContainAPropertyWithValueAndAlternative(

if ($expectedValue === "a_comment_url") {
if (\preg_match("#^/remote.php/dav/comments/files/([0-9]+)$#", $value)) {
return 0;
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just want to get out early here, no need to return ``0```

@@ -743,9 +741,7 @@ public function theSingleResponseShouldContainAPropertyWithValueLike(
}
}

if (\preg_match($regex, $value)) {
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return at all here. We can just do the reverse test, and then we are at the end of the function anyway.


// Return an invalid file id so that any later step that tries to use it
// will fail.
return "";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions can return a value to Behat, which will remember the return value. Then it can be saved away for later, by a "built-in" step like:

And we save it into "FILEID"

So in this function we want to always return something, which will keep Behat happy. Then some later step in the scenario can fail gracefully when it tries to use an empty file id.


$response = $client->proppatch(
$this->getDavFilesPath($user) . $path, $properties, $folderDepth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proppatch does not take a 3rd parameter. $folderDepth is irrelevant here. All callers specified 0 anyway.

@@ -593,6 +603,7 @@ public function itShouldNotBePossibleToShareUsingTheWebUI(
'could not find sharing button in fileRow',
'could not share with \'' . $shareWith . '\''
];
$foundMessage = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to keep the IDE happy - it thinks maybe $foundMessage could be undefined.

@@ -1133,12 +1145,12 @@ public function adminMakesUserNotSubadminOfGroupUsingTheAPI($user, $group) {
/**
* @Then /^the users returned by the API should be$/
*
* @param \Behat\Gherkin\Node\TableNode|null $usersList
* @param TableNode|null $usersList
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you can give the function a null but then it would do exactly nothing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at that - the IDE just auto-simplified the TableNode reference for me.
Yes, you are right. If you pass nothing then the code here always passes - it does not check that the actual list is empty. There is a separate step for that:

the list of users returned by the API should be empty

so I will remove the null here.
And the same thing for groups below. I also see that there is no test scenario for getting the groups of a user when the user is not in any other groups - I will look at that separately.

Copy link
Member

@individual-it individual-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one small comment, we can fix that in an other PR

@phil-davis
Copy link
Contributor Author

Removed ```null`` return from functions that should not have it.
Added a test scenario for getting groups of a user when the user is not in any groups.

@phil-davis phil-davis force-pushed the acceptance-test-use-01 branch from d933fb8 to 0720641 Compare May 25, 2018 08:51
@phil-davis phil-davis merged commit 6e3b0e4 into master May 25, 2018
@phil-davis phil-davis deleted the acceptance-test-use-01 branch May 25, 2018 11:18
@phil-davis
Copy link
Contributor Author

Backport ``stable10``` #31536

@lock
Copy link

lock bot commented Jul 30, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants