Skip to content

Commit b2fd567

Browse files
committed
Add some controller tests
1 parent d456588 commit b2fd567

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

tests/unit/ControllerTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
use CodeIgniter\Exceptions\PageNotFoundException;
4+
use CodeIgniter\Test\ControllerTestTrait;
5+
use CodeIgniter\Test\DatabaseTestTrait;
6+
use Tatter\Outbox\Controllers\Templates;
7+
use Tatter\Outbox\Entities\Template;
8+
use Tatter\Outbox\Models\TemplateModel;
9+
use Tests\Support\OutboxTestCase;
10+
11+
/**
12+
* @internal
13+
*/
14+
final class ControllerTest extends OutboxTestCase
15+
{
16+
use ControllerTestTrait;
17+
use DatabaseTestTrait;
18+
19+
/**
20+
* Our Controller set by the trait
21+
*
22+
* @var Templates|null
23+
*/
24+
protected $controller;
25+
26+
/**
27+
* A test Template
28+
*
29+
* @var Template
30+
*/
31+
private $template;
32+
33+
protected function setUp(): void
34+
{
35+
parent::setUp();
36+
37+
$this->controller(Templates::class);
38+
39+
$this->template = new Template([
40+
'name' => 'Test Template',
41+
'subject' => 'Some {subject}',
42+
'body' => '<p>{number}</p>',
43+
]);
44+
$this->template->id = model(TemplateModel::class)->insert($this->template);
45+
}
46+
47+
public function testGetTemplate()
48+
{
49+
$result = $this->controller->getTemplate($this->template->id);
50+
51+
$this->assertSame($this->template->name, $result->name);
52+
}
53+
54+
public function testGetTemplateThrows()
55+
{
56+
$this->expectException(PageNotFoundException::class);
57+
58+
$this->controller->getTemplate(42);
59+
}
60+
61+
public function testIndexListsTemplates()
62+
{
63+
$result = $this->execute('index');
64+
65+
$result->assertStatus(200);
66+
$result->assertSee($this->template->name);
67+
}
68+
}

0 commit comments

Comments
 (0)