Add tests for creating a file from a template
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
c6cad8b412
Коммит
b9319c126a
|
@ -24,10 +24,10 @@ class RichDocumentsContext implements Context
|
|||
public $currentServer;
|
||||
public $fileId;
|
||||
public $wopiToken;
|
||||
/**
|
||||
* @var array List of opened file ids in order to compare opening accross instances
|
||||
*/
|
||||
/** @var array List of opened file ids in order to compare opening accross instances*/
|
||||
private $fileIds = [];
|
||||
/** @var array List of templates fetched for a given file type */
|
||||
private $templates = [];
|
||||
|
||||
/** @BeforeScenario */
|
||||
public function gatherContexts(BeforeScenarioScope $scope) {
|
||||
|
@ -68,18 +68,7 @@ class RichDocumentsContext implements Context
|
|||
parse_url($lastServer, PHP_URL_PORT) ? ':' . parse_url($lastServer, PHP_URL_PORT) : ''
|
||||
). '/';
|
||||
}
|
||||
$contents = $result->getBody()->getContents();
|
||||
$re = '/var richdocuments_([A-z]+) = (.*);/m';
|
||||
preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
|
||||
$result = [];
|
||||
foreach ($matches as $match) {
|
||||
$result[$match[1]] = str_replace("'", "", $match[2]);
|
||||
}
|
||||
|
||||
$this->fileIds[] = $result['fileId'];
|
||||
$this->fileId = $result['fileId'];
|
||||
$this->wopiToken = $result['token'];
|
||||
$this->wopiContext->setWopiParameters($this->currentServer, $this->fileId, $this->wopiToken);
|
||||
$this->extractRichdocumentsFrontendContext($result);
|
||||
|
||||
Assert::assertNotEmpty($this->fileId);
|
||||
Assert::assertNotEmpty($this->wopiToken);
|
||||
|
@ -126,15 +115,7 @@ class RichDocumentsContext implements Context
|
|||
$result = $client->get(
|
||||
$this->serverContext->getBaseUrl() . 'index.php/apps/richdocuments/public?shareToken=' . $token . ($fileId ? '&fileId=' . $fileId : ''),
|
||||
array_merge($this->serverContext->getWebOptions(), $userId ? [] : ['cookies' => $cookieJar]));
|
||||
$contents = $result->getBody()->getContents();
|
||||
$re = '/var richdocuments_([A-z]+) = (.*);/m';
|
||||
preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
|
||||
$params = [];
|
||||
foreach ($matches as $match) {
|
||||
$params[$match[1]] = str_replace("'", "", $match[2]);
|
||||
}
|
||||
|
||||
$this->wopiContext->setWopiParameters($this->serverContext->getBaseUrl(), $params['fileId'], $params['token']);
|
||||
$this->extractRichdocumentsFrontendContext($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,4 +147,72 @@ class RichDocumentsContext implements Context
|
|||
return $result['{http://owncloud.org/ns}fileid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" fetches the (document|spreadsheet|presentation) template list$/
|
||||
*/
|
||||
public function userFetchesTheTemplateList($user, $type) {
|
||||
$this->serverContext->sendOCSRequest('GET', '/apps/richdocuments/api/v1/templates/' . $type);
|
||||
$this->templates = $this->serverContext->getOCSResponseData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" creates a new file "([^"]*)" from a template$/
|
||||
*/
|
||||
public function userCreatesANewFileFromATemplate($user, $file) {
|
||||
$template = $this->templates[0];
|
||||
$this->serverContext->usingWebAsUser($user);
|
||||
|
||||
$client = new Client();
|
||||
$query = [
|
||||
'templateId' => $template['id'],
|
||||
'fileName' => basename($file),
|
||||
'dir' => dirname($file),
|
||||
];
|
||||
$result = $client->get(
|
||||
$this->serverContext->getBaseUrl() . 'index.php/apps/richdocuments/indexTemplate',
|
||||
array_merge(
|
||||
$this->serverContext->getWebOptions(),
|
||||
[
|
||||
'query' => $query,
|
||||
'allow_redirects' => [
|
||||
'track_redirects' => true
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
$redirects = $result->getHeader('X-Guzzle-Redirect-History');
|
||||
$lastServer = array_pop($redirects);
|
||||
if ($lastServer) {
|
||||
$this->currentServer = parse_url($lastServer, PHP_URL_SCHEME) . '://'. parse_url($lastServer, PHP_URL_HOST) . (
|
||||
parse_url($lastServer, PHP_URL_PORT) ? ':' . parse_url($lastServer, PHP_URL_PORT) : ''
|
||||
). '/';
|
||||
}
|
||||
$this->extractRichdocumentsFrontendContext($result);
|
||||
|
||||
Assert::assertNotEmpty($this->fileId);
|
||||
Assert::assertNotEmpty($this->wopiToken);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Given /^TemplateSource is set$/
|
||||
*/
|
||||
public function templatesourceIsSet() {
|
||||
$this->wopiContext->checkfileinfoMatches('TemplateSource', '%wopi/template/' . $this->templates[0]['id'] . '\\?access_token%');
|
||||
}
|
||||
|
||||
private function extractRichdocumentsFrontendContext($response) {
|
||||
$contents = $response->getBody()->getContents();
|
||||
$re = '/var richdocuments_([A-z]+) = (.*);/m';
|
||||
preg_match_all($re, $contents, $matches, PREG_SET_ORDER, 0);
|
||||
$result = [];
|
||||
foreach ($matches as $match) {
|
||||
$result[$match[1]] = str_replace("'", "", $match[2]);
|
||||
}
|
||||
|
||||
$this->fileIds[] = $result['fileId'];
|
||||
$this->fileId = $result['fileId'];
|
||||
$this->wopiToken = $result['token'];
|
||||
$this->wopiContext->setWopiParameters($this->currentServer, $this->fileId, $this->wopiToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,34 +128,42 @@ class WopiContext implements Context {
|
|||
/**
|
||||
* @Then /^checkFileInfo "([^"]*)" is "([^"]*)"$/
|
||||
*/
|
||||
public function checkfileinfoIs($arg1, $arg2)
|
||||
public function checkfileinfoIs($key, $value)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertEquals($arg2, $this->checkFileInfoResult[$arg1]);
|
||||
\PHPUnit\Framework\Assert::assertEquals($value, $this->checkFileInfoResult[$key]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then /^checkFileInfo "([^"]*)" matches "([^"]*)"$/
|
||||
*/
|
||||
public function checkfileinfoMatches($arg1, $arg2)
|
||||
public function checkfileinfoMatches($key, $regex)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertRegExp($arg2, $this->checkFileInfoResult[$arg1]);
|
||||
\PHPUnit\Framework\Assert::assertRegExp($regex, $this->checkFileInfoResult[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^checkFileInfo "([^"]*)" is true$/
|
||||
*/
|
||||
public function checkfileinfoIsTrue($arg1)
|
||||
public function checkfileinfoIsTrue($key)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertTrue($this->checkFileInfoResult[$arg1]);
|
||||
\PHPUnit\Framework\Assert::assertTrue($this->checkFileInfoResult[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^checkFileInfo "([^"]*)" is false$/
|
||||
*/
|
||||
public function checkfileinfoIsFalse($arg1)
|
||||
public function checkfileinfoIsFalse($key)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertFalse($this->checkFileInfoResult[$arg1]);
|
||||
\PHPUnit\Framework\Assert::assertFalse($this->checkFileInfoResult[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^checkFileInfo "([^"]*)" is not set/
|
||||
*/
|
||||
public function checkfileinfoIsNotSet($key)
|
||||
{
|
||||
\PHPUnit\Framework\Assert::assertArrayNotHasKey($key, $this->checkFileInfoResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -257,3 +257,15 @@ Feature: WOPI
|
|||
And checkFileInfo "UserCanWrite" is false
|
||||
And Collabora downoads the file and it is equal to "./../assets/template.odt"
|
||||
|
||||
|
||||
Scenario: Create a new wopi token from a template for a user and open it
|
||||
Given as user "user1"
|
||||
And user "user1" fetches the document template list
|
||||
And user "user1" creates a new file "/file.odt" from a template
|
||||
And Collabora fetches and receives the following in the checkFileInfo response
|
||||
| BaseFileName | file.odt |
|
||||
| OwnerId | user1 |
|
||||
| UserId | user1 |
|
||||
| UserFriendlyName | user1-displayname |
|
||||
And checkFileInfo "UserCanWrite" is true
|
||||
And TemplateSource is set
|
||||
|
|
Загрузка…
Ссылка в новой задаче