Skip to content

Commit 232cf74

Browse files
committed
add membership + wiki cat xml tests
1 parent 43eddce commit 232cf74

File tree

3 files changed

+178
-7
lines changed

3 files changed

+178
-7
lines changed

lib/Redmine/Api/Wiki.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ public function all($project, array $params = array())
2727
}
2828

2929
/**
30-
*
31-
* Getting [an old version of ] a wiki page
30+
* Getting [an old version of] a wiki page
3231
* @link http://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Getting-a-wiki-page
3332
* @link http://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Getting-an-old-version-of-a-wiki-page
3433
*
3534
* @param int|string $project the project name
3635
* @param string $page the page name
3736
* @param int $version version of the page
38-
* @return array information about the issue
37+
* @return array information about the wiki page
3938
*/
4039
public function show($project, $page, $version = null)
4140
{
@@ -47,13 +46,11 @@ public function show($project, $page, $version = null)
4746
}
4847

4948
/**
50-
* Create a new issue given an array of $params
51-
* The issue is assigned to the authenticated user.
52-
* @link http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue
49+
* Create a new wiki page given an array of $params
5350
*
5451
* @param int|string $project the project name
5552
* @param string $page the page name
56-
* @param array $params the new issue data
53+
* @param array $params the new wiki page data
5754
* @return SimpleXMLElement
5855
*/
5956
public function create($project, $page, array $params = array())
@@ -73,6 +70,19 @@ public function create($project, $page, array $params = array())
7370
return $this->put('/projects/'.$project.'/wiki/'.$page.'.xml', $xml->asXML());
7471
}
7572

73+
/**
74+
* Updates wiki page $page
75+
*
76+
* @param int|string $project the project name
77+
* @param string $page the page name
78+
* @param array $params the new wiki page data
79+
* @return SimpleXMLElement
80+
*/
81+
public function update($project, $page, array $params = array())
82+
{
83+
return $this->create($project, $page, $params);
84+
}
85+
7686
/**
7787
* Delete a wiki page
7888
* @link http://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Deleting-a-wiki-page
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace Redmine\Tests;
4+
5+
use Redmine\TestClient;
6+
7+
class MembershipXmlTest extends \PHPUnit_Framework_TestCase
8+
{
9+
private $client;
10+
11+
public function setup()
12+
{
13+
$this->client = new TestClient('http://test.local', 'asdf');
14+
}
15+
16+
/**
17+
* @expectedException Exception
18+
*/
19+
public function testCreateBlank()
20+
{
21+
$this->assertInstanceOf('Redmine\Api\Membership', $this->client->api('membership'));
22+
23+
$xml = '<?xml version="1.0"?>
24+
<membership/>';
25+
$res = $this->client->api('membership')->create();
26+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
27+
}
28+
29+
public function testCreateComplex()
30+
{
31+
$res = $this->client->api('membership')->create('otherProject', array(
32+
'user_id' => 1,
33+
'role_ids' => array(1, 2),
34+
));
35+
36+
$xml = '<?xml version="1.0"?>
37+
<membership>
38+
<user_id>1</user_id>
39+
<role_ids type="array">
40+
<role_id>1</role_id>
41+
<role_id>2</role_id>
42+
</role_ids>
43+
</membership>';
44+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
45+
}
46+
47+
public function testCreateComplexMultipleUsers()
48+
{
49+
$res = $this->client->api('membership')->create('otherProject', array(
50+
'user_ids' => array(1, 2),
51+
'role_ids' => array(1, 2),
52+
));
53+
54+
$xml = '<?xml version="1.0"?>
55+
<membership>
56+
<user_ids type="array">
57+
<user_id>1</user_id>
58+
<user_id>2</user_id>
59+
</user_ids>
60+
<role_ids type="array">
61+
<role_id>1</role_id>
62+
<role_id>2</role_id>
63+
</role_ids>
64+
</membership>';
65+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
66+
}
67+
68+
public function testUpdate()
69+
{
70+
$res = $this->client->api('membership')->update(1, array(
71+
'role_ids' => array(1, 2),
72+
));
73+
74+
$xml = '<?xml version="1.0"?>
75+
<membership>
76+
<role_ids type="array">
77+
<role_id>1</role_id>
78+
<role_id>2</role_id>
79+
</role_ids>
80+
</membership>';
81+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
82+
}
83+
84+
private function formatXml($xml)
85+
{
86+
$dom = new \DOMDocument('1.0');
87+
$dom->preserveWhiteSpace = false;
88+
$dom->formatOutput = true;
89+
$dom->loadXML((new \SimpleXMLElement($xml))->asXML());
90+
91+
return $dom->saveXML();
92+
}
93+
}

test/Redmine/Tests/WikiXmlTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Redmine\Tests;
4+
5+
use Redmine\TestClient;
6+
7+
class WikiXmlTest extends \PHPUnit_Framework_TestCase
8+
{
9+
private $client;
10+
11+
public function setup()
12+
{
13+
$this->client = new TestClient('http://test.local', 'asdf');
14+
}
15+
16+
/**
17+
* @expectedException Exception
18+
*/
19+
public function testCreateBlank()
20+
{
21+
$this->assertInstanceOf('Redmine\Api\Wiki', $this->client->api('wiki'));
22+
$res = $this->client->api('wiki')->create();
23+
}
24+
25+
public function testCreateComplex()
26+
{
27+
$res = $this->client->api('wiki')->create('testProject', 'about', array(
28+
'text' => 'asdf',
29+
'comments' => 'asdf',
30+
'version' => 'asdf',
31+
));
32+
33+
$xml = '<?xml version="1.0"?>
34+
<wiki_page>
35+
<text>asdf</text>
36+
<comments>asdf</comments>
37+
<version>asdf</version>
38+
</wiki_page>';
39+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
40+
}
41+
42+
public function testUpdate()
43+
{
44+
$res = $this->client->api('wiki')->update('testProject', 'about', array(
45+
'text' => 'asdf',
46+
'comments' => 'asdf',
47+
'version' => 'asdf',
48+
));
49+
50+
$xml = '<?xml version="1.0"?>
51+
<wiki_page>
52+
<text>asdf</text>
53+
<comments>asdf</comments>
54+
<version>asdf</version>
55+
</wiki_page>';
56+
$this->assertEquals($this->formatXml($xml), $this->formatXml($res));
57+
}
58+
59+
private function formatXml($xml)
60+
{
61+
$dom = new \DOMDocument('1.0');
62+
$dom->preserveWhiteSpace = false;
63+
$dom->formatOutput = true;
64+
$dom->loadXML((new \SimpleXMLElement($xml))->asXML());
65+
66+
return $dom->saveXML();
67+
}
68+
}

0 commit comments

Comments
 (0)