Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add integration tests for getting folder sizes
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Aug 8, 2022
commit 14919971f9930dee2b1e6020a1224d36f5894e39
1 change: 1 addition & 0 deletions build/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
class FeatureContext implements Context, SnippetAcceptingContext {
use ContactsMenu;
use Files;
use Search;
use WebDav;
use Trashbin;
Expand Down
69 changes: 69 additions & 0 deletions build/integration/features/bootstrap/Files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* @copyright Copyright (c) 2022 Daniel Calviño Sánchez <[email protected]>
*
* @author Daniel Calviño Sánchez <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program 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 (at your option) 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/>.
*
*/
use Behat\Behat\Hook\Scope\AfterScenarioScope;
use PHPUnit\Framework\Assert;

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

trait Files {

// BasicStructure trait is expected to be used in the class that uses this
// trait.

/**
* @When logged in user gets storage stats of folder :folder
*
* @param string $folder
*/
public function loggedInUserGetsStorageStatsOfFolder(string $folder) {
$this->loggedInUserGetsStorageStatsOfFolderWith($folder, '200');
}

/**
* @When logged in user gets storage stats of folder :folder with :statusCode
*
* @param string $folder
*/
public function loggedInUserGetsStorageStatsOfFolderWith(string $folder, string $statusCode) {
$this->sendingAToWithRequesttoken('GET', '/index.php/apps/files/ajax/getstoragestats?dir=' . $folder);
$this->theHTTPStatusCodeShouldBe($statusCode);
}

/**
* @Then the storage stats match with
*
* @param Behat\Gherkin\Node\TableNode $body
*/
public function theStorageStatsMatchWith(Behat\Gherkin\Node\TableNode $body) {
$storageStats = json_decode($this->response->getBody()->getContents(), $asAssociativeArray = true);
$storageStats = $storageStats['data'];

foreach ($body->getRowsHash() as $expectedField => $expectedValue) {
if (!array_key_exists($expectedField, $storageStats)) {
Assert::fail("$expectedField was not found in response");
}

Assert::assertEquals($expectedValue, $storageStats[$expectedField], "Field '$expectedField' does not match ({$storageStats[$expectedField]})");
}
}
}
93 changes: 93 additions & 0 deletions build/integration/features/files.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Feature: files

# Counterpart scenarios for getting the folder size in webdav-related.feature

Scenario: Retrieving storage stats after a file was uploaded
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/test.txt"
When Logging in using web as "user0"
And logged in user gets storage stats of folder "/"
Then the storage stats match with
| used | 447 |

Scenario: Retrieving storage stats after a file was uploaded to a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
When Logging in using web as "user0"
And logged in user gets storage stats of folder "/"
Then the storage stats match with
| used | 447 |

Scenario: Retrieving storage stats for folder after a file was uploaded to that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
When Logging in using web as "user0"
And logged in user gets storage stats of folder "/FOLDER/"
Then the storage stats match with
| used | 108 |

Scenario: Retrieving storage stats after a file was deleted from a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 23 bytes to "/FOLDER/test1.txt"
And user "user0" adds a file of 42 bytes to "/FOLDER/test2.txt"
And user "user0" adds a file of 108 bytes to "/FOLDER/test3.txt"
And User "user0" deletes file "/FOLDER/test2.txt"
When Logging in using web as "user0"
And logged in user gets storage stats of folder "/"
Then the storage stats match with
| used | 470 |

Scenario: Retrieving storage stats for folder after a file was deleted from that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 23 bytes to "/FOLDER/test1.txt"
And user "user0" adds a file of 42 bytes to "/FOLDER/test2.txt"
And user "user0" adds a file of 108 bytes to "/FOLDER/test3.txt"
And User "user0" deletes file "/FOLDER/test2.txt"
When Logging in using web as "user0"
And logged in user gets storage stats of folder "/FOLDER/"
Then the storage stats match with
| used | 131 |

Scenario: Retrieving storage stats after the last file was deleted from a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
And Logging in using web as "user0"
# Get the size after uploading the file to ensure that the size after the
# deletion is not just a size cached before the upload.
And logged in user gets storage stats of folder "/"
And the storage stats match with
| used | 447 |
And User "user0" deletes file "/FOLDER/test.txt"
When logged in user gets storage stats of folder "/"
Then the storage stats match with
| used | 339 |

Scenario: Retrieving storage stats for folder after the last file was deleted from that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
And Logging in using web as "user0"
# Get the size after uploading the file to ensure that the size after the
# deletion is not just a size cached before the upload.
And logged in user gets storage stats of folder "/"
And the storage stats match with
| used | 447 |
And User "user0" deletes file "/FOLDER/test.txt"
When logged in user gets storage stats of folder "/FOLDER/"
Then the storage stats match with
| used | 0 |

# End of counterpart scenarios
85 changes: 85 additions & 0 deletions build/integration/features/webdav-related.feature
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,91 @@ Feature: webdav-related
|{DAV:}quota-available-bytes|
Then the single response should contain a property "{DAV:}quota-available-bytes" with value "685"

# Counterpart scenarios for getting the storage stats in files.feature

Scenario: Retrieving root folder size after a file was uploaded
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/test.txt"
When as "user0" gets properties of folder "/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "447"

Scenario: Retrieving root folder size after a file was uploaded to a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
When as "user0" gets properties of folder "/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "447"

Scenario: Retrieving folder size after a file was uploaded to that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
When as "user0" gets properties of folder "/FOLDER/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "108"

Scenario: Retrieving root folder size after a file was deleted from a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 23 bytes to "/FOLDER/test1.txt"
And user "user0" adds a file of 42 bytes to "/FOLDER/test2.txt"
And user "user0" adds a file of 108 bytes to "/FOLDER/test3.txt"
And User "user0" deletes file "/FOLDER/test2.txt"
When as "user0" gets properties of folder "/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "470"

Scenario: Retrieving folder size after a file was deleted from that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 23 bytes to "/FOLDER/test1.txt"
And user "user0" adds a file of 42 bytes to "/FOLDER/test2.txt"
And user "user0" adds a file of 108 bytes to "/FOLDER/test3.txt"
And User "user0" deletes file "/FOLDER/test2.txt"
When as "user0" gets properties of folder "/FOLDER/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "131"

Scenario: Retrieving root folder size after the last file was deleted from a folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
# Get the size after uploading the file to ensure that the size after the
# deletion is not just a size cached before the upload.
And as "user0" gets properties of folder "/" with
|{http://owncloud.org/ns}size|
And the single response should contain a property "{http://owncloud.org/ns}size" with value "447"
And User "user0" deletes file "/FOLDER/test.txt"
When as "user0" gets properties of folder "/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "339"

Scenario: Retrieving folder size after the last file was deleted from that folder
Given using old dav path
And As an "admin"
And user "user0" exists
And user "user0" adds a file of 108 bytes to "/FOLDER/test.txt"
# Get the size after uploading the file to ensure that the size after the
# deletion is not just a size cached before the upload.
And as "user0" gets properties of folder "/FOLDER/" with
|{http://owncloud.org/ns}size|
And the single response should contain a property "{http://owncloud.org/ns}size" with value "108"
And User "user0" deletes file "/FOLDER/test.txt"
When as "user0" gets properties of folder "/FOLDER/" with
|{http://owncloud.org/ns}size|
Then the single response should contain a property "{http://owncloud.org/ns}size" with value "0"

# End of counterpart scenarios

Scenario: download a public shared file with range
Given user "user0" exists
And As an "user0"
Expand Down