Skip to content

Commit 02c822d

Browse files
committed
Add e2e test for uploading attachments to wiki pages
1 parent ab5f4eb commit 02c822d

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/Redmine/Api/Project.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Redmine\Exception\UnexpectedResponseException;
1010
use Redmine\Serializer\PathSerializer;
1111
use Redmine\Serializer\XmlSerializer;
12+
use SimpleXMLElement;
1213

1314
/**
1415
* Listing projects, creating, editing.
@@ -146,7 +147,7 @@ public function show($id, array $params = [])
146147
*
147148
* @throws MissingParameterException
148149
*
149-
* @return string|false
150+
* @return string|SimpleXMLElement|false
150151
*/
151152
public function create(array $params = [])
152153
{

tests/End2End/Wiki/WikiTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Redmine\Tests\End2End\Wiki;
6+
7+
use Redmine\Api\Attachment;
8+
use Redmine\Api\Project;
9+
use Redmine\Api\Wiki;
10+
use Redmine\Tests\End2End\ClientTestCase;
11+
use Redmine\Tests\RedmineExtension\RedmineVersion;
12+
13+
class WikiTest extends ClientTestCase
14+
{
15+
/**
16+
* @dataProvider provideRedmineVersions
17+
*/
18+
public function testInteractionWithGroup(RedmineVersion $redmineVersion): void
19+
{
20+
$client = $this->getNativeCurlClient($redmineVersion);
21+
22+
// Create project
23+
/** @var Project */
24+
$projectApi = $client->getApi('project');
25+
26+
$projectIdentifier = 'project-with-wiki';
27+
28+
$xmlData = $projectApi->create(['name' => 'project with wiki', 'identifier' => $projectIdentifier]);
29+
30+
$projectDataJson = json_encode($xmlData);
31+
$projectData = json_decode($projectDataJson, true);
32+
33+
$this->assertIsArray($projectData, $projectDataJson);
34+
$this->assertSame($projectIdentifier, $projectData['identifier'], $projectDataJson);
35+
36+
// Upload file
37+
/** @var Attachment */
38+
$attachmentApi = $client->getApi('attachment');
39+
40+
$jsonData = $attachmentApi->upload(file_get_contents(dirname(__FILE__, 3) . '/Fixtures/testfile_01.txt'), ['filename' => 'testfile.txt']);
41+
42+
$attachmentData = json_decode($jsonData, true);
43+
44+
$this->assertIsArray($attachmentData, $jsonData);
45+
$this->assertSame(
46+
['id', 'token'],
47+
array_keys($attachmentData['upload']),
48+
$jsonData
49+
);
50+
51+
$attachmentToken = $attachmentData['upload']['token'];
52+
53+
$this->assertSame('1.7b962f8af22e26802b87abfa0b07b21dbd03b984ec8d6888dabd3f69cff162f8', $attachmentToken);
54+
55+
/** @var Wiki */
56+
$wikiApi = $client->getApi('wiki');
57+
58+
$xmlData = $wikiApi->create($projectIdentifier, 'testpage', [
59+
'text' => '# First Wiki page',
60+
'uploads' => [
61+
['token' => $attachmentToken, 'filename' => 'filename.txt', 'content-type' => 'text/plain'],
62+
],
63+
]);
64+
65+
$wikiDataJson = json_encode($xmlData);
66+
$wikiData = json_decode($wikiDataJson, true);
67+
68+
$this->assertIsArray($wikiData, $jsonData);
69+
$this->assertSame(
70+
['title', 'text', 'version', 'author', 'comments', 'created_on', 'updated_on'],
71+
array_keys($wikiData),
72+
$wikiDataJson
73+
);
74+
75+
// Check attachments
76+
$wikiData = $wikiApi->show($projectIdentifier, 'testpage');
77+
78+
$this->assertIsArray($wikiData['wiki_page']['attachments'][0]);
79+
$this->assertSame(
80+
['id', 'filename', 'filesize', 'content_type', 'description', 'content_url', 'author', 'created_on'],
81+
array_keys($wikiData['wiki_page']['attachments'][0])
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)