Completed
Push — master ( c014af...eba3de )
by Henry
06:25
created

CommentTest::testGetRouteById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace Redaxscript\Tests\Model;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * CommentTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Model\Comment
18
 */
19
20
class CommentTest extends TestCaseAbstract
21
{
22
	/**
23
	 * setUp
24
	 *
25
	 * @since 4.0.0
26
	 */
27
28
	public function setUp() : void
29
	{
30
		parent::setUp();
31
		$optionArray =
32
		[
33
			'adminName' => 'Test',
34
			'adminUser' => 'test',
35
			'adminPassword' => 'test',
36
			'adminEmail' => '[email protected]'
37
		];
38
		$installer = $this->installerFactory();
39
		$installer->init();
40
		$installer->rawCreate();
41
		$installer->insertSettings($optionArray);
42
		$categoryOne = Db::forTablePrefix('categories')->create();
43
		$categoryOne
44
			->set(
45
			[
46
				'title' => 'Category One',
47
				'alias' => 'category-one'
48
			])
49
			->save();
50
		$articleOne = Db::forTablePrefix('articles')->create();
51
		$articleOne
52
			->set(
53
			[
54
				'title' => 'Article One',
55
				'alias' => 'article-one',
56
				'category' => $categoryOne->id
57
			])
58
			->save();
59
		$articleTwo = Db::forTablePrefix('articles')->create();
60
		$articleTwo
61
			->set(
62
			[
63
				'title' => 'Article Two',
64
				'alias' => 'article-two'
65
			])
66
			->save();
67
		Db::forTablePrefix('comments')
68
			->create()
69
			->set(
70
			[
71
				'author' => 'Comment One',
72
				'text' => 'Comment One',
73
				'article' => $articleOne->id
74
			])
75
			->save();
76
		Db::forTablePrefix('comments')
77
			->create()
78
			->set(
79
			[
80
				'author' => 'Comment Two',
81
				'text' => 'Comment Two',
82
				'article' => $articleTwo->id
83
			])
84
			->save();
85
		Db::forTablePrefix('comments')
86
			->create()
87
			->set(
88
			[
89
				'author' => 'Comment Three',
90
				'text' => 'Comment Three',
91
				'language' => 'en',
92
				'article' => $articleTwo->id
93
			])
94
			->save();
95
	}
96
97
	/**
98
	 * tearDown
99
	 *
100
	 * @since 4.0.0
101
	 */
102
103
	public function tearDown() : void
104
	{
105
		$this->dropDatabase();
106
	}
107
108
	/**
109
	 * testCountByArticleAndLanguage
110
	 *
111
	 * @since 4.0.0
112
	 *
113
	 * @param int $articleId
114
	 * @param string $language
115
	 * @param int $expect
116
	 *
117
	 * @dataProvider providerAutoloader
118
	 */
119
120
	public function testCountByArticleAndLanguage(int $articleId = null, string $language = null, int $expect = null) : void
121
	{
122
		/* setup */
123
124
		$commentModel = new Model\Comment();
125
126
		/* actual */
127
128
		$actual = $commentModel->countByArticleAndLanguage($articleId, $language);
129
130
		/* compare */
131
132
		$this->assertEquals($expect, $actual);
133
	}
134
135
	/**
136
	 * testGetRouteById
137
	 *
138
	 * @since 4.0.0
139
	 *
140
	 * @param int $commentId
141
	 * @param string $expect
142
	 *
143
	 * @dataProvider providerAutoloader
144
	 */
145
146
	public function testGetRouteById(int $commentId = null, string $expect = null) : void
147
	{
148
		/* setup */
149
150
		$commentModel = new Model\Comment();
151
152
		/* actual */
153
154
		$actual = $commentModel->getRouteById($commentId);
155
156
		/* compare */
157
158
		$this->assertEquals($expect, $actual);
159
	}
160
}
161