Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/Gitlab/Api/Wiki.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php namespace Gitlab\Api;

class Wiki extends AbstractApi
{

/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function create($project_id, array $params)
{
return $this->post($this->getProjectPath($project_id, 'wikis'), $params);
}

/**
* @param int $project_id
* @param int $wiki_slug
* @return mixed
*/
public function show($project_id, $wiki_slug)
{
return $this->get($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
}

/**
* @param int $project_id
* @return mixed
*/
public function showAll($project_id)
{
return $this->get($this->getProjectPath($project_id, 'wikis'));
}

/**
* @param int $project_id
* @param array $params
* @return mixed
*/
public function update($project_id, $wiki_slug, array $params)
{
return $this->put($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)), $params);
}

/**
* @param int $project_id
* @param int $wiki_slug
* @return mixed
*/
public function remove($project_id, $wiki_slug)
{
return $this->delete($this->getProjectPath($project_id, 'wikis/'.$this->encodePath($wiki_slug)));
}
}
12 changes: 11 additions & 1 deletion lib/Gitlab/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ public function schedules()
return new Api\Schedules($this);
}

/**
* @return Api\Wiki
*/
public function wiki()
{
return new Api\Wiki($this);
}

/**
* @return Api\IssuesStatistics
*/
Expand Down Expand Up @@ -398,10 +406,12 @@ public function api($name)
case 'schedules':
return $this->schedules();

case 'wiki':
return $this->wiki();

case 'issues_statistics':
return $this->issuesStatistics();


default:
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
}
Expand Down
74 changes: 74 additions & 0 deletions lib/Gitlab/Model/Wiki.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Gitlab\Model;

use Gitlab\Client;

/**
* Class Wiki
*
* @property-read string $slug
* @property-read string $title
* @property-read string $format
* @property-read string $content
* @property-read Project $project
*/
class Wiki extends AbstractModel
{
/**
* @var array
*/
protected static $properties = array(
"project",
"slug",
"title",
"format",
"content",
);

/**
* @param Client $client
* @param Project $project
* @param array $data
* @return Wiki
*/
public static function fromArray(Client $client, Project $project, array $data)
{
$wiki = new static($project, $data['slug'], $client);

return $wiki->hydrate($data);
}

/**
* @param Project $project
* @param string $slug
* @param Client $client
*/
public function __construct(Project $project, $slug = null, Client $client = null)
{
$this->setClient($client);
$this->setData('project', $project);
$this->setData('slug', $slug);
}

/**
* @return Wiki
*/
public function show()
{
$data = $this->client->wiki()->show($this->project->id, $this->slug);

return static::fromArray($this->getClient(), $this->project, $data);
}

/**
* @param array $params
* @return Wiki
*/
public function update(array $params)
{
$data = $this->client->wiki()->update($this->project->id, $this->slug, $params);

return static::fromArray($this->getClient(), $this->project, $data);
}
}
124 changes: 124 additions & 0 deletions test/Gitlab/Tests/Api/WikiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Gitlab\Tests\Api;

class WikiTest extends TestCase
{
/**
* @test
*/
public function shouldCreateWiki()
{
$expectedArray = [
"format" => "markdown",
"slug" => "Test-Wiki",
"title" => "Test Wiki",
"content" => "This is the test Wiki",
];


$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('projects/1/wikis', [
"format" => "markdown",
"title" => "Test Wiki",
"content" => "This is the test Wiki"
])
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->create(1,
[
"format" => "markdown",
"title" => "Test Wiki",
"content" => "This is the test Wiki"
]
));
}

/**
* @test
*/
public function shouldShowWiki()
{
$expectedArray = [
"slug" => "Test-Wiki",
"title" => "Test Wiki",
"format" => "markdown"
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/wikis/Test-Wiki')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->show(1, "Test-Wiki"));
}

/**
* @test
*/
public function shouldShowAllWiki()
{
$expectedArray = [
"slug" => "Test-Wiki",
"title" => "Test Wiki",
"format" => "markdown"
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('projects/1/wikis')
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->showAll(1));
}

/**
* @test
*/
public function shouldUpdateWiki()
{
$expectedArray = [
'slug' => 'Test-Wiki',
'title' => 'Test Wiki',
"format" => "markdown",
"content" => "This is the test Wiki that has been updated"
];

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('projects/1/wikis/Test-Wiki', ["content" => "This is the test Wiki that has been updated"])
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->update(1, "Test-Wiki", ["content" => "This is the test Wiki that has been updated"]));
}

/**
* @test
*/
public function shouldRemoveWiki()
{
$expectedBool = true;

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('projects/1/wikis/Test-Wiki')
->will($this->returnValue($expectedBool))
;

$this->assertEquals($expectedBool, $api->remove(1, "Test-Wiki"));
}


protected function getApiClass()
{
return 'Gitlab\Api\Wiki';
}
}