|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gitlab\Tests\Api; |
| 4 | + |
| 5 | +class WikiTest extends TestCase |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @test |
| 9 | + */ |
| 10 | + public function shouldCreateWiki() |
| 11 | + { |
| 12 | + $expectedArray = [ |
| 13 | + "format" => "markdown", |
| 14 | + "slug" => "Test-Wiki", |
| 15 | + "title" => "Test Wiki", |
| 16 | + "content" => "This is the test Wiki", |
| 17 | + ]; |
| 18 | + |
| 19 | + |
| 20 | + $api = $this->getApiMock(); |
| 21 | + $api->expects($this->once()) |
| 22 | + ->method('post') |
| 23 | + ->with('projects/1/wikis', [ |
| 24 | + "format" => "markdown", |
| 25 | + "title" => "Test Wiki", |
| 26 | + "content" => "This is the test Wiki" |
| 27 | + ]) |
| 28 | + ->will($this->returnValue($expectedArray)); |
| 29 | + |
| 30 | + $this->assertEquals($expectedArray, $api->create(1, |
| 31 | + [ |
| 32 | + "format" => "markdown", |
| 33 | + "title" => "Test Wiki", |
| 34 | + "content" => "This is the test Wiki" |
| 35 | + ] |
| 36 | + )); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @test |
| 41 | + */ |
| 42 | + public function shouldShowWiki() |
| 43 | + { |
| 44 | + $expectedArray = [ |
| 45 | + "slug" => "Test-Wiki", |
| 46 | + "title" => "Test Wiki", |
| 47 | + "format" => "markdown" |
| 48 | + ]; |
| 49 | + |
| 50 | + $api = $this->getApiMock(); |
| 51 | + $api->expects($this->once()) |
| 52 | + ->method('get') |
| 53 | + ->with('projects/1/wikis/Test-Wiki') |
| 54 | + ->will($this->returnValue($expectedArray)); |
| 55 | + |
| 56 | + $this->assertEquals($expectedArray, $api->show(1, "Test-Wiki")); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @test |
| 61 | + */ |
| 62 | + public function shouldShowAllWiki() |
| 63 | + { |
| 64 | + $expectedArray = [ |
| 65 | + "slug" => "Test-Wiki", |
| 66 | + "title" => "Test Wiki", |
| 67 | + "format" => "markdown" |
| 68 | + ]; |
| 69 | + |
| 70 | + $api = $this->getApiMock(); |
| 71 | + $api->expects($this->once()) |
| 72 | + ->method('get') |
| 73 | + ->with('projects/1/wikis') |
| 74 | + ->will($this->returnValue($expectedArray)) |
| 75 | + ; |
| 76 | + |
| 77 | + $this->assertEquals($expectedArray, $api->showAll(1)); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @test |
| 82 | + */ |
| 83 | + public function shouldUpdateWiki() |
| 84 | + { |
| 85 | + $expectedArray = [ |
| 86 | + 'slug' => 'Test-Wiki', |
| 87 | + 'title' => 'Test Wiki', |
| 88 | + "format" => "markdown", |
| 89 | + "content" => "This is the test Wiki that has been updated" |
| 90 | + ]; |
| 91 | + |
| 92 | + $api = $this->getApiMock(); |
| 93 | + $api->expects($this->once()) |
| 94 | + ->method('put') |
| 95 | + ->with('projects/1/wikis/Test-Wiki', ["content" => "This is the test Wiki that has been updated"]) |
| 96 | + ->will($this->returnValue($expectedArray)) |
| 97 | + ; |
| 98 | + |
| 99 | + $this->assertEquals($expectedArray, $api->update(1, "Test-Wiki", ["content" => "This is the test Wiki that has been updated"])); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @test |
| 104 | + */ |
| 105 | + public function shouldRemoveWiki() |
| 106 | + { |
| 107 | + $expectedBool = true; |
| 108 | + |
| 109 | + $api = $this->getApiMock(); |
| 110 | + $api->expects($this->once()) |
| 111 | + ->method('delete') |
| 112 | + ->with('projects/1/wikis/Test-Wiki') |
| 113 | + ->will($this->returnValue($expectedBool)) |
| 114 | + ; |
| 115 | + |
| 116 | + $this->assertEquals($expectedBool, $api->remove(1, "Test-Wiki")); |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + protected function getApiClass() |
| 121 | + { |
| 122 | + return 'Gitlab\Api\Wiki'; |
| 123 | + } |
| 124 | +} |
0 commit comments