Skip to content

Commit 1baf964

Browse files
committed
Improve tests for Wiki::remove
1 parent b3fff8c commit 1baf964

File tree

4 files changed

+65
-29
lines changed

4 files changed

+65
-29
lines changed

tests/Behat/Bootstrap/WikiContextTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function iUpdateTheWikiPageWithNameAndProjectIdentifierWithTheFollowingDa
6969
}
7070

7171
/**
72-
* @When I delete the wiki page with name :pageName and project identifier :identifier
72+
* @When I remove the wiki page with name :pageName and project identifier :identifier
7373
*/
74-
public function iDeleteTheWikiPageWithNameAndProjectIdentifier(string $pageName, string $identifier)
74+
public function iRemoveTheWikiPageWithNameAndProjectIdentifier($pageName, $identifier)
7575
{
7676
/** @var Wiki */
7777
$api = $this->getNativeCurlClient()->getApi('wiki');

tests/Behat/features/wiki.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ Feature: Interacting with the REST API for wikis
234234
And the returned data is exactly ""
235235

236236
@wiki
237-
Scenario: Deleting a wiki page
237+
Scenario: Removing a wiki page
238238
Given I have a "NativeCurlClient" client
239239
And I create a project with name "Test Project" and identifier "test-project"
240240
And I create a wiki page with name "Test Page" and project identifier "test-project" with the following data
241241
| property | value |
242242
| text | # My first wiki page |
243-
When I delete the wiki page with name "Test Page" and project identifier "test-project"
243+
When I remove the wiki page with name "Test Page" and project identifier "test-project"
244244
Then the response has the status code "204"
245245
And the response has an empty content type
246246
And the response has the content ""

tests/Unit/Api/Wiki/RemoveTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Redmine\Tests\Unit\Api\Wiki;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\TestCase;
10+
use Redmine\Api\Wiki;
11+
use Redmine\Tests\Fixtures\AssertingHttpClient;
12+
13+
#[CoversClass(Wiki::class)]
14+
class RemoveTest extends TestCase
15+
{
16+
/**
17+
* @dataProvider getRemoveData
18+
*/
19+
#[DataProvider('getRemoveData')]
20+
public function testRemoveReturnsCorrectResponse($id, $page, $expectedPath, $responseCode, $response)
21+
{
22+
$client = AssertingHttpClient::create(
23+
$this,
24+
[
25+
'DELETE',
26+
$expectedPath,
27+
'application/xml',
28+
'',
29+
$responseCode,
30+
'',
31+
$response
32+
]
33+
);
34+
35+
// Create the object under test
36+
$api = new Wiki($client);
37+
38+
// Perform the tests
39+
$this->assertSame('', $api->remove($id, $page));
40+
}
41+
42+
public static function getRemoveData(): array
43+
{
44+
return [
45+
'test with integer' => [
46+
5,
47+
'test',
48+
'/projects/5/wiki/test.xml',
49+
204,
50+
'',
51+
],
52+
'test with special chars in page name' => [
53+
5,
54+
'test page',
55+
'/projects/5/wiki/test+page.xml',
56+
204,
57+
'',
58+
],
59+
];
60+
}
61+
}

tests/Unit/Api/WikiTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,4 @@ public function testAllReturnsClientGetResponseWithParameters()
114114
// Perform the tests
115115
$this->assertSame($expectedReturn, $api->all(5, $parameters));
116116
}
117-
118-
/**
119-
* Test remove().
120-
*/
121-
public function testRemoveCallsDelete()
122-
{
123-
// Test values
124-
$response = 'API Response';
125-
126-
// Create the used mock objects
127-
$client = $this->createMock(Client::class);
128-
$client->expects($this->once())
129-
->method('requestDelete')
130-
->with('/projects/5/wiki/test.xml')
131-
->willReturn(true);
132-
$client->expects($this->once())
133-
->method('getLastResponseBody')
134-
->willReturn($response);
135-
136-
// Create the object under test
137-
$api = new Wiki($client);
138-
139-
// Perform the tests
140-
$this->assertSame($response, $api->remove(5, 'test'));
141-
}
142117
}

0 commit comments

Comments
 (0)