|
4 | 4 |
|
5 | 5 | use Kanboard\Core\Plugin\Loader;
|
6 | 6 | use Kanboard\Plugin\Wiki\Model\Wiki;
|
| 7 | +use Kanboard\Model\ProjectModel; |
| 8 | +use Kanboard\Core\User\UserSession; |
| 9 | +use Kanboard\Core\Security\AuthenticationManager; |
| 10 | +use Kanboard\Auth\DatabaseAuth; |
7 | 11 |
|
8 | 12 | class WikiPageTest extends Base
|
9 | 13 | {
|
10 |
| - public function setUp() |
| 14 | + /** |
| 15 | + * @var Plugin |
| 16 | + */ |
| 17 | + protected $plugin; |
| 18 | + |
| 19 | + protected function setUp(): void |
11 | 20 | {
|
12 | 21 | parent::setUp();
|
| 22 | + // $this->plugin = new Plugin($this->container); |
13 | 23 |
|
14 | 24 | $plugin = new Loader($this->container);
|
15 | 25 | $plugin->scan();
|
16 | 26 | }
|
17 | 27 |
|
18 | 28 | public function testCreation()
|
19 | 29 | {
|
20 |
| - $wikimodel = new Wiki($this->container); |
21 |
| - // $this->assertEquals(1, $wikimodel->createpage(1, "Security", "Some content", '2015-01-01')); |
22 |
| - // $this->assertEquals(2, $wikimodel->createpage(1, "Conventions", 'More content')); |
23 |
| - |
24 | 30 |
|
25 |
| - // $editions = $wikimodel->getEditions(1); |
26 |
| - // $this->assertEmpty($editions); |
| 31 | + $projectModel = new ProjectModel($this->container); |
27 | 32 |
|
28 |
| - // $values = [ |
29 |
| - // 'title' => "Security", |
30 |
| - // 'content' => "Some content", |
31 |
| - // ]; |
| 33 | + $this->assertEquals($projectModel->create(array('name' => 'UnitTest')), 1, 'Failed to create project'); |
32 | 34 |
|
33 |
| - // $this->assertEquals(1, $wikimodel->createEdition($values, 1, 1)); |
| 35 | + $project = $projectModel->getById(1); |
34 | 36 |
|
35 |
| - // createpage |
36 |
| - |
37 |
| - // $rates = $hr->getAllByUser(0); |
38 |
| - // $this->assertEmpty($rates); |
| 37 | + $wikimodel = new Wiki($this->container); |
| 38 | + // create wiki pages |
| 39 | + $this->assertEquals($wikimodel->createpage($project['id'], "Security", "Some content", '2015-01-01'), 1, 'Failed to a create wiki page on project'); |
| 40 | + $this->assertEquals($wikimodel->createpage($project['id'], "Conventions", 'More content'), 2, 'Failed to an additional create wiki page on project'); |
39 | 41 |
|
40 |
| - // $editions = $wikimodel->getEditions(1); |
41 |
| - // $this->assertNotEmpty($editions); |
42 |
| - // $rates = $hr->getAllByUser(1); |
43 |
| - // $this->assertNotEmpty($rates); |
44 |
| - // $this->assertCount(1, $editions); |
| 42 | + // grab editions for first wiki page |
| 43 | + $editions = $wikimodel->getEditions(1); |
| 44 | + $this->assertEmpty($editions); |
45 | 45 |
|
46 |
| - // $this->assertEquals(42, $rates[0]['rate']); |
47 |
| - // $this->assertEquals('Security', $editions[0]['title']); |
48 |
| - // $this->assertEquals('Some content', $editions[0]['content']); |
| 46 | + $values = [ |
| 47 | + 'title' => "Security", |
| 48 | + 'content' => "Some content", |
| 49 | + ]; |
49 | 50 |
|
50 |
| - // $this->assertEquals('2015-02-01', date('Y-m-d', $rates[0]['date_effective'])); |
| 51 | + // create wiki page edition |
| 52 | + |
| 53 | + $authManager = new AuthenticationManager($this->container); |
| 54 | + $authManager->register(new DatabaseAuth($this->container)); |
51 | 55 |
|
52 |
| - // $this->assertEquals(32.4, $rates[1]['rate']); |
53 |
| - // $this->assertEquals('EUR', $rates[1]['currency']); |
54 |
| - // $this->assertEquals('2015-01-01', date('Y-m-d', $rates[1]['date_effective'])); |
| 56 | + $_SESSION['user'] = array('id' => 1, 'username' => 'test', 'role' => 'app-admin'); |
55 | 57 |
|
56 |
| - // $this->assertEquals(0, $hr->getCurrentRate(0)); |
57 |
| - // $this->assertEquals(42, $hr->getCurrentRate(1)); |
| 58 | + $this->assertTrue($this->container['userSession']->isLogged(), 'Failed to login'); |
58 | 59 |
|
59 |
| - // $this->assertTrue($wikimodel->removepage(1)); |
60 |
| - // $this->assertEquals(32.4, $hr->getCurrentRate(1)); |
| 60 | + $this->userSession = new UserSession($this->container); |
| 61 | + // result is not a consistent 1. is this true or id for new edition? |
| 62 | + $createEditionResult = $wikimodel->createEdition($values, 1, 1); |
| 63 | + // $this->assertEquals($wikimodel->createEdition($values, 1, 1), 1, 'Failed to create wiki edition'); |
61 | 64 |
|
62 |
| - // $this->assertTrue($hr->remove(1)); |
63 |
| - // $this->assertEquals(0, $hr->getCurrentRate(1)); |
| 65 | + $editions = $wikimodel->getEditions(1); |
| 66 | + $this->assertNotEmpty($editions, 'Failed to get wiki editions'); |
64 | 67 |
|
65 |
| - // $rates = $hr->getAllByUser(1); |
66 |
| - // $this->assertEmpty($rates); |
| 68 | + $this->assertEquals('Security', $editions[0]['title']); |
| 69 | + $this->assertEquals('Some content', $editions[0]['content']); |
67 | 70 | }
|
68 | 71 | }
|
0 commit comments