-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxence Lange <[email protected]>
- Loading branch information
1 parent
919b448
commit d9946ec
Showing
2 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @author Joas Schilling <[email protected]> | ||
* @author John Molakvoæ <[email protected]> | ||
* @author Lukas Reschke <[email protected]> | ||
* @author Maxence Lange <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Robin Appelman <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
|
@@ -31,9 +32,10 @@ | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
use GuzzleHttp\Client as GClient; | ||
use GuzzleHttp\Message\ResponseInterface; | ||
use PHPUnit\Framework\Assert; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Sabre\DAV\Client as SClient; | ||
use Sabre\DAV\Xml\Property\ResourceType; | ||
|
||
|
@@ -43,17 +45,13 @@ | |
trait WebDav { | ||
use Sharing; | ||
|
||
/** @var string */ | ||
private $davPath = "remote.php/webdav"; | ||
/** @var boolean */ | ||
private $usingOldDavPath = true; | ||
private string $davPath = "remote.php/webdav"; | ||
private bool $usingOldDavPath = true; | ||
private ?array $storedETAG = null; // map with user as key and another map as value, which has path as key and etag as value | ||
private ?int $storedFileID = null; | ||
/** @var ResponseInterface */ | ||
private $response; | ||
/** @var array map with user as key and another map as value, which has path as key and etag as value */ | ||
private $storedETAG = null; | ||
/** @var int */ | ||
private $storedFileID = null; | ||
|
||
private array $parsedResponse = []; | ||
private string $s3MultipartDestination; | ||
private string $uploadId; | ||
|
||
|
@@ -237,7 +235,7 @@ public function search(): void { | |
public function searchFavorite(): void { | ||
$this->searchFile( | ||
$this->currentUser, | ||
null, | ||
'<oc:favorite/>', | ||
null, | ||
'<d:eq> | ||
<d:prop> | ||
|
@@ -333,19 +331,32 @@ public function asTheFileOrFolderExists($user, $entry, $path) { | |
$this->response = $this->listFolder($user, $path, 0); | ||
} | ||
|
||
/** | ||
* @Then the response should be empty | ||
* @throws \Exception | ||
*/ | ||
public function theResponseShouldBeEmpty(): void { | ||
$response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavEntries() : $this->response; | ||
if ($response === []) { | ||
return; | ||
} | ||
|
||
throw new \Exception('response is not empty'); | ||
} | ||
|
||
/** | ||
* @Then the single response should contain a property :key with value :value | ||
* @param string $key | ||
* @param string $expectedValue | ||
* @throws \Exception | ||
*/ | ||
public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) { | ||
$keys = $this->response; | ||
if (!array_key_exists($key, $keys)) { | ||
$response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavSingleEntry() : $this->response; | ||
if (!array_key_exists($key, $response)) { | ||
throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\""); | ||
} | ||
|
||
$value = $keys[$key]; | ||
$value = $response[$key]; | ||
if ($value instanceof ResourceType) { | ||
$value = $value->getValue(); | ||
if (empty($value)) { | ||
|
@@ -533,6 +544,7 @@ public function searchFile(string $user, ?string $properties = null, ?string $sc | |
$this->response = $this->makeDavRequest($user, "SEARCH", '', [ | ||
'Content-Type' => 'text/xml' | ||
], $body, ''); | ||
|
||
var_dump((string)$this->response->getBody()); | ||
} catch (\GuzzleHttp\Exception\ServerException $e) { | ||
// 5xx responses cause a server exception | ||
|
@@ -1112,4 +1124,32 @@ public function theUploadShouldFailOnObjectStorage() { | |
$this->theHTTPStatusCodeShouldBe(500); | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
private function convertResponseToDavSingleEntry(): array { | ||
$results = $this->convertResponseToDavEntries(); | ||
if (count($results) > 1) { | ||
throw new \Exception('result is empty or contain more than one (1) entry'); | ||
} | ||
|
||
return array_shift($results); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function convertResponseToDavEntries(): array { | ||
$client = $this->getSabreClient($this->currentUser); | ||
$parsedResponse = $client->parseMultiStatus((string)$this->response->getBody()); | ||
|
||
$results = []; | ||
foreach ($parsedResponse as $href => $statusList) { | ||
$results[$href] = $statusList[200] ?? []; | ||
} | ||
|
||
return $results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters