Completed
Push — master ( e44a53...f90670 )
by Henry
08:22
created

ContentTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 133
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 33 1
A tearDown() 0 4 1
A testGetTableByAlias() 0 14 1
A testGetByTableAndId() 0 14 1
A testGetRouteByTableAndId() 0 14 1
1
<?php
2
namespace Redaxscript\Tests\Model;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * ContentTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Model\Content
18
 */
19
20
class ContentTest 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
		$articleOne = Db::forTablePrefix('articles')->create();
43
		$articleOne
44
			->set(
45
			[
46
				'title' => 'Article One',
47
				'alias' => 'article-one',
48
				'category' => $categoryOne->id
49
			])
50
			->save();
51
		Db::forTablePrefix('comments')
52
			->create()
53
			->set(
54
			[
55
				'author' => 'Comment One',
56
				'text' => 'Comment One',
57
				'article' => $articleOne->id
58
			])
59
			->save();
60
	}
61
62
	/**
63
	 * tearDown
64
	 *
65
	 * @since 4.0.0
66
	 */
67
68
	public function tearDown() : void
69
	{
70
		$this->dropDatabase();
71
	}
72
73
	/**
74
	 * testGetTableByAlias
75
	 *
76
	 * @since 4.0.0
77
	 *
78
	 * @param string $contentAlias
79
	 * @param string $expect
80
	 *
81
	 * @dataProvider providerAutoloader
82
	 */
83
84
	public function testGetTableByAlias(string $contentAlias = null, string $expect = null) : void
85
	{
86
		/* setup */
87
88
		$contentModel = new Model\Content();
89
90
		/* actual */
91
92
		$actual = $contentModel->getTableByAlias($contentAlias);
93
94
		/* compare */
95
96
		$this->assertEquals($expect, $actual);
97
	}
98
99
	/**
100
	 * testGetByTableAndId
101
	 *
102
	 * @since 4.0.0
103
	 *
104
	 * @param string $table
105
	 * @param int $contentId
106
	 * @param string $expect
107
	 *
108
	 * @dataProvider providerAutoloader
109
	 */
110
111
	public function testGetByTableAndId(string $table = null, int $contentId = null, string $expect = null) : void
112
	{
113
		/* setup */
114
115
		$contentModel = new Model\Content();
116
117
		/* actual */
118
119
		$actual = $contentModel->getByTableAndId($table, $contentId)->alias;
120
121
		/* compare */
122
123
		$this->assertEquals($expect, $actual);
124
	}
125
126
	/**
127
	 * testGetRouteByTableAndId
128
	 *
129
	 * @since 4.0.0
130
	 *
131
	 * @param string $table
132
	 * @param int $contentId
133
	 * @param string $expect
134
	 *
135
	 * @dataProvider providerAutoloader
136
	 */
137
138
	public function testGetRouteByTableAndId(string $table = null, int $contentId = null, string $expect = null) : void
139
	{
140
		/* setup */
141
142
		$contentModel = new Model\Content();
143
144
		/* actual */
145
146
		$actual = $contentModel->getRouteByTableAndId($table, $contentId);
147
148
		/* compare */
149
150
		$this->assertEquals($expect, $actual);
151
	}
152
}
153