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

ArticleTest::testGetByAlias()   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
 * ArticleTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Model\Article
18
 */
19
20
class ArticleTest extends TestCaseAbstract
21
{
22
	/**
23
	 * setUp
24
	 *
25
	 * @since 4.0.0
26
	 */
27
28
	public function setUp() : void
29
	{
30
		parent::setUp();
31
		$installer = $this->installerFactory();
32
		$installer->init();
33
		$installer->rawCreate();
34
		$categoryOne = Db::forTablePrefix('categories')->create();
35
		$categoryOne
36
			->set(
37
			[
38
				'title' => 'Category One',
39
				'alias' => 'category-one'
40
			])
41
			->save();
42
		$categoryTwo = Db::forTablePrefix('categories')->create();
43
		$categoryTwo
44
			->set(
45
			[
46
				'title' => 'Category Two',
47
				'alias' => 'category-two',
48
				'parent' => $categoryOne->id
49
			])
50
			->save();
51
		Db::forTablePrefix('articles')
52
			->create()
53
			->set(
54
			[
55
				'title' => 'Article One',
56
				'alias' => 'article-one',
57
				'category' => $categoryOne->id
58
			])
59
			->save();
60
		Db::forTablePrefix('articles')
61
			->create()
62
			->set(
63
			[
64
				'title' => 'Article Two',
65
				'alias' => 'article-two',
66
				'category' => $categoryTwo->id
67
			])
68
			->save();
69
		Db::forTablePrefix('articles')
70
			->create()
71
			->set(
72
			[
73
				'title' => 'Article Three',
74
				'alias' => 'article-three',
75
				'language' => 'en',
76
				'category' => $categoryTwo->id
77
			])
78
			->save();
79
		Db::forTablePrefix('articles')
80
			->create()
81
			->set(
82
			[
83
				'title' => 'Article Four',
84
				'alias' => 'article-four'
85
			])
86
			->save();
87
	}
88
89
	/**
90
	 * tearDown
91
	 *
92
	 * @since 4.0.0
93
	 */
94
95
	public function tearDown() : void
96
	{
97
		$this->dropDatabase();
98
	}
99
100
	/**
101
	 * testGetByAlias
102
	 *
103
	 * @since 4.0.0
104
	 *
105
	 * @param string $articleAlias
106
	 * @param int $expect
107
	 *
108
	 * @dataProvider providerAutoloader
109
	 */
110
111
	public function testGetByAlias(string $articleAlias = null, int $expect = null) : void
112
	{
113
		/* setup */
114
115
		$articleModel = new Model\Article();
116
117
		/* actual */
118
119
		$actual = $articleModel->getByAlias($articleAlias)->id;
120
121
		/* compare */
122
123
		$this->assertEquals($expect, $actual);
124
	}
125
126
	/**
127
	 *
128
	 * testCountByCategoryAndLanguage
129
	 *
130
	 * @since 4.0.0
131
	 *
132
	 * @param int $categoryId
133
	 * @param string $language
134
	 * @param int $expect
135
	 *
136
	 * @dataProvider providerAutoloader
137
	 */
138
139
	public function testCountByCategoryAndLanguage(int $categoryId = null, string $language = null, int $expect = null) : void
140
	{
141
		/* setup */
142
143
		$articleModel = new Model\Article();
144
145
		/* actual */
146
147
		$actual = $articleModel->countByCategoryAndLanguage($categoryId, $language);
148
149
		/* compare */
150
151
		$this->assertEquals($expect, $actual);
152
	}
153
154
	/**
155
	 * testGetRouteById
156
	 *
157
	 * @since 4.0.0
158
	 *
159
	 * @param int $articleId
160
	 * @param string $expect
161
	 *
162
	 * @dataProvider providerAutoloader
163
	 */
164
165
	public function testGetRouteById(int $articleId = null, string $expect = null) : void
166
	{
167
		/* setup */
168
169
		$articleModel = new Model\Article();
170
171
		/* actual */
172
173
		$actual = $articleModel->getRouteById($articleId);
174
175
		/* compare */
176
177
		$this->assertEquals($expect, $actual);
178
	}
179
}
180