Skip to content

Commit 7606871

Browse files
committed
add path & method test (wiki)
1 parent 232cf74 commit 7606871

File tree

5 files changed

+82
-35
lines changed

5 files changed

+82
-35
lines changed

example.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@
283283
'comments' => null,
284284
'version' => null,
285285
));
286+
$client->api('wiki')->update('testProject', 'about', array(
287+
'text' => null,
288+
'comments' => null,
289+
'version' => null,
290+
));
286291
$client->api('wiki')->remove('testProject', 'about');
287292

288293

lib/Redmine/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function getPort($urlPath = null)
326326
* @return false|SimpleXMLElement|string
327327
* @throws \Exception If anything goes wrong on curl request
328328
*/
329-
private function runRequest($path, $method = 'GET', $data = '')
329+
protected function runRequest($path, $method = 'GET', $data = '')
330330
{
331331
$this->responseCode = null;
332332
$this->getPort($this->url.$path);

lib/Redmine/TestClient.php

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,17 @@
55
class TestClient extends Client
66
{
77
/**
8-
* @param string $path
9-
* @throws Exception
8+
* @param string $path
9+
* @param string $method
10+
* @param string $data
11+
* @return string
12+
* @throws \Exception If anything goes wrong on curl request
1013
*/
11-
public function get($path)
12-
{
13-
throw new \Exception('not available');
14-
}
15-
16-
/**
17-
* returns raw $data
18-
* @param string $path
19-
* @param string $data
20-
* @return string $data
21-
*/
22-
public function post($path, $data)
23-
{
24-
return $data;
25-
}
26-
27-
/**
28-
* returns raw $data
29-
* @param string $path
30-
* @param string $data
31-
* @return strgin $data
32-
*/
33-
public function put($path, $data)
14+
protected function runRequest($path, $method = 'GET', $data = '')
3415
{
16+
if(in_array($method, array('GET', 'DELETE'))) {
17+
throw new \Exception('not available');
18+
}
3519
return $data;
3620
}
37-
38-
/**
39-
* @param string $path
40-
* @throws Exception
41-
*/
42-
public function delete($path)
43-
{
44-
throw new \Exception('not available');
45-
}
4621
}

lib/Redmine/TestUrlClient.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Redmine;
4+
5+
class TestUrlClient extends Client
6+
{
7+
public function get($path)
8+
{
9+
return $this->runRequest($path, 'GET');
10+
}
11+
12+
/**
13+
* @param string $path
14+
* @param string $method
15+
* @param string $data
16+
* @return string
17+
* @throws \Exception If anything goes wrong on curl request
18+
*/
19+
protected function runRequest($path, $method = 'GET', $data = '')
20+
{
21+
return array(
22+
'path' => $path,
23+
'method' => $method,
24+
);
25+
}
26+
}

test/Redmine/Tests/UrlTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Redmine\Tests;
4+
5+
use Redmine\TestUrlClient;
6+
7+
class UrlTest extends \PHPUnit_Framework_TestCase
8+
{
9+
private $client;
10+
11+
public function setup()
12+
{
13+
$this->client = new TestUrlClient('http://test.local', 'asdf');
14+
}
15+
16+
public function testWiki()
17+
{
18+
$res = $this->client->api('wiki')->create('testProject', 'about', array(
19+
'text' => 'asdf',
20+
'comments' => 'asdf',
21+
'version' => 'asdf',
22+
));
23+
$this->assertEquals($res, array('path' => '/projects/testProject/wiki/about.xml', 'method' => 'PUT'));
24+
25+
$res = $this->client->api('wiki')->update('testProject', 'about', array(
26+
'text' => 'asdf',
27+
'comments' => 'asdf',
28+
'version' => 'asdf',
29+
));
30+
$this->assertEquals($res, array('path' => '/projects/testProject/wiki/about.xml', 'method' => 'PUT'));
31+
32+
$res = $this->client->api('wiki')->show('testProject', 'about');
33+
$this->assertEquals($res, array('path' => '/projects/testProject/wiki/about.json', 'method' => 'GET'));
34+
35+
$res = $this->client->api('wiki')->show('testProject', 'about', 'v1');
36+
$this->assertEquals($res, array('path' => '/projects/testProject/wiki/about/v1.json', 'method' => 'GET'));
37+
38+
$res = $this->client->api('wiki')->remove('testProject', 'about');
39+
$this->assertEquals($res, array('path' => '/projects/testProject/wiki/about.xml', 'method' => 'DELETE'));
40+
}
41+
}

0 commit comments

Comments
 (0)