@@ -5,26 +5,26 @@ |
||
5 | 5 | class AboutController extends DefaultPageController |
6 | 6 | { |
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
10 | - $this->set_title("Jacob Emerick's Portfolio"); |
|
11 | - $this->set_description("Jacob Emerick's Portfolio - collection of programming projects and resume"); |
|
12 | - $this->set_keywords([ |
|
13 | - 'portfolio', |
|
14 | - 'Jacob Emerick', |
|
15 | - 'web development', |
|
16 | - 'web programming', |
|
17 | - 'software development', |
|
18 | - 'agile', |
|
19 | - 'freelance', |
|
20 | - ]); |
|
21 | - } |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | + $this->set_title("Jacob Emerick's Portfolio"); |
|
11 | + $this->set_description("Jacob Emerick's Portfolio - collection of programming projects and resume"); |
|
12 | + $this->set_keywords([ |
|
13 | + 'portfolio', |
|
14 | + 'Jacob Emerick', |
|
15 | + 'web development', |
|
16 | + 'web programming', |
|
17 | + 'software development', |
|
18 | + 'agile', |
|
19 | + 'freelance', |
|
20 | + ]); |
|
21 | + } |
|
22 | 22 | |
23 | - protected function set_body_data() |
|
24 | - { |
|
25 | - $this->set_body('body_view', 'About'); |
|
26 | - $this->set_body('body_data', []); |
|
23 | + protected function set_body_data() |
|
24 | + { |
|
25 | + $this->set_body('body_view', 'About'); |
|
26 | + $this->set_body('body_data', []); |
|
27 | 27 | |
28 | - parent::set_body_data(); |
|
29 | - } |
|
28 | + parent::set_body_data(); |
|
29 | + } |
|
30 | 30 | } |
@@ -5,31 +5,31 @@ |
||
5 | 5 | class ResumeController extends DefaultPageController |
6 | 6 | { |
7 | 7 | |
8 | - protected $resume = 'resume-20160318.json'; |
|
8 | + protected $resume = 'resume-20160318.json'; |
|
9 | 9 | |
10 | - protected function set_head_data() |
|
11 | - { |
|
12 | - $this->set_title("Resume | Jacob Emerick's Portfolio"); |
|
13 | - $this->set_description("Resume for Jacob Emerick, a software engineer extraordinaire"); |
|
14 | - $this->set_keywords([ |
|
15 | - 'resume', |
|
16 | - 'programming resume', |
|
17 | - 'Jacob Emerick', |
|
18 | - 'software engineer', |
|
19 | - 'portfolio', |
|
20 | - 'shutterstock', |
|
21 | - ]); |
|
22 | - } |
|
10 | + protected function set_head_data() |
|
11 | + { |
|
12 | + $this->set_title("Resume | Jacob Emerick's Portfolio"); |
|
13 | + $this->set_description("Resume for Jacob Emerick, a software engineer extraordinaire"); |
|
14 | + $this->set_keywords([ |
|
15 | + 'resume', |
|
16 | + 'programming resume', |
|
17 | + 'Jacob Emerick', |
|
18 | + 'software engineer', |
|
19 | + 'portfolio', |
|
20 | + 'shutterstock', |
|
21 | + ]); |
|
22 | + } |
|
23 | 23 | |
24 | - protected function set_body_data() |
|
25 | - { |
|
26 | - $this->set_body('body_view', 'Resume'); |
|
24 | + protected function set_body_data() |
|
25 | + { |
|
26 | + $this->set_body('body_view', 'Resume'); |
|
27 | 27 | |
28 | - $resumePath = Loader::getRootURL('portfolio') . "/jsonresume/{$this->resume}"; |
|
29 | - $resume = file_get_contents($resumePath); |
|
30 | - $resume = json_decode($resume, true); |
|
31 | - $this->set_body('body_data', $resume); |
|
28 | + $resumePath = Loader::getRootURL('portfolio') . "/jsonresume/{$this->resume}"; |
|
29 | + $resume = file_get_contents($resumePath); |
|
30 | + $resume = json_decode($resume, true); |
|
31 | + $this->set_body('body_data', $resume); |
|
32 | 32 | |
33 | - parent::set_body_data(); |
|
34 | - } |
|
33 | + parent::set_body_data(); |
|
34 | + } |
|
35 | 35 | } |
@@ -5,25 +5,25 @@ |
||
5 | 5 | class ProjectsController extends DefaultPageController |
6 | 6 | { |
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
10 | - $this->set_title("Projects Page | Jacob Emerick's Portfolio"); |
|
11 | - $this->set_description("Collection of key open-source projects that Jacob has developed and maintained over the years."); |
|
12 | - $this->set_keywords([ |
|
13 | - 'projects', |
|
14 | - 'open source', |
|
15 | - 'example work', |
|
16 | - 'portfolio', |
|
17 | - 'Jacob Emerick', |
|
18 | - 'software development', |
|
19 | - ]); |
|
20 | - } |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | + $this->set_title("Projects Page | Jacob Emerick's Portfolio"); |
|
11 | + $this->set_description("Collection of key open-source projects that Jacob has developed and maintained over the years."); |
|
12 | + $this->set_keywords([ |
|
13 | + 'projects', |
|
14 | + 'open source', |
|
15 | + 'example work', |
|
16 | + 'portfolio', |
|
17 | + 'Jacob Emerick', |
|
18 | + 'software development', |
|
19 | + ]); |
|
20 | + } |
|
21 | 21 | |
22 | - protected function set_body_data() |
|
23 | - { |
|
24 | - $this->set_body('body_view', 'Projects'); |
|
25 | - $this->set_body('body_data', []); |
|
22 | + protected function set_body_data() |
|
23 | + { |
|
24 | + $this->set_body('body_view', 'Projects'); |
|
25 | + $this->set_body('body_data', []); |
|
26 | 26 | |
27 | - parent::set_body_data(); |
|
28 | - } |
|
27 | + parent::set_body_data(); |
|
28 | + } |
|
29 | 29 | } |
@@ -10,14 +10,14 @@ discard block |
||
10 | 10 | class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase |
11 | 11 | { |
12 | 12 | |
13 | - protected static $connection; |
|
13 | + protected static $connection; |
|
14 | 14 | |
15 | - public static function setUpBeforeClass() |
|
16 | - { |
|
17 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
18 | - $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
15 | + public static function setUpBeforeClass() |
|
16 | + { |
|
17 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
18 | + $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
19 | 19 | |
20 | - $extendedPdo->exec(" |
|
20 | + $extendedPdo->exec(" |
|
21 | 21 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
22 | 22 | `id` integer PRIMARY KEY AUTOINCREMENT, |
23 | 23 | `title` varchar(60) NOT NULL, |
@@ -27,1282 +27,1282 @@ discard block |
||
27 | 27 | `body` text, |
28 | 28 | `display` integer(1) NOT NULL |
29 | 29 | )" |
30 | - ); |
|
31 | - $extendedPdo->exec(" |
|
30 | + ); |
|
31 | + $extendedPdo->exec(" |
|
32 | 32 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`ptlink` ( |
33 | 33 | `post_id` integer NOT NULL, |
34 | 34 | `tag_id` integer NOT NULL |
35 | 35 | )" |
36 | - ); |
|
37 | - $extendedPdo->exec(" |
|
36 | + ); |
|
37 | + $extendedPdo->exec(" |
|
38 | 38 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`series_post` ( |
39 | 39 | `series` integer NOT NULL, |
40 | 40 | `post` integer NOT NULL, |
41 | 41 | `order` integer(1) NOT NULL |
42 | 42 | )" |
43 | - ); |
|
44 | - $extendedPdo->exec(" |
|
43 | + ); |
|
44 | + $extendedPdo->exec(" |
|
45 | 45 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`tag` ( |
46 | 46 | `id` integer PRIMARY KEY AUTOINCREMENT, |
47 | 47 | `tag` varchar(25) NOT NULL |
48 | 48 | )" |
49 | - ); |
|
50 | - |
|
51 | - self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
52 | - return $extendedPdo; |
|
53 | - }); |
|
54 | - } |
|
55 | - |
|
56 | - public function testIsInstanceOfPostRepository() |
|
57 | - { |
|
58 | - $repository = new MysqlPostRepository(self::$connection); |
|
59 | - |
|
60 | - $this->assertInstanceOf( |
|
61 | - 'Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository', |
|
62 | - $repository |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - public function testImplementsPostInterface() |
|
67 | - { |
|
68 | - $repository = new MysqlPostRepository(self::$connection); |
|
69 | - |
|
70 | - $this->assertInstanceOf( |
|
71 | - 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
72 | - $repository |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - public function testConstructSetsConnections() |
|
77 | - { |
|
78 | - $respository = new MysqlPostRepository(self::$connection); |
|
79 | - |
|
80 | - $this->assertAttributeSame( |
|
81 | - self::$connection, |
|
82 | - 'connections', |
|
83 | - $respository |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - public function testFindPostByPath() |
|
88 | - { |
|
89 | - $testData = [ |
|
90 | - 'id' => rand(1, 100), |
|
91 | - 'title' => 'test title', |
|
92 | - 'path' => 'test-path', |
|
93 | - 'category' => 'test category', |
|
94 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
95 | - 'body' => 'test body', |
|
96 | - 'display' => 1 |
|
97 | - ]; |
|
98 | - |
|
99 | - $this->insertPostData($testData); |
|
100 | - |
|
101 | - $repository = new MysqlPostRepository(self::$connection); |
|
102 | - $data = $repository->findPostByPath($testData['path']); |
|
103 | - |
|
104 | - $this->assertNotFalse($data); |
|
105 | - $this->assertInternalType('array', $data); |
|
106 | - $this->assertArrayHasKey('id', $data); |
|
107 | - $this->assertEquals($testData['id'], $data['id']); |
|
108 | - $this->assertArrayHasKey('title', $data); |
|
109 | - $this->assertEquals($testData['title'], $data['title']); |
|
110 | - $this->assertArrayHasKey('path', $data); |
|
111 | - $this->assertEquals($testData['path'], $data['path']); |
|
112 | - $this->assertArrayHasKey('date', $data); |
|
113 | - $this->assertEquals($testData['date'], $data['date']); |
|
114 | - $this->assertArrayHasKey('body', $data); |
|
115 | - $this->assertEquals($testData['body'], $data['body']); |
|
116 | - $this->assertArrayHasKey('category', $data); |
|
117 | - $this->assertEquals($testData['category'], $data['category']); |
|
118 | - } |
|
119 | - |
|
120 | - public function testFindPostByPathInactive() |
|
121 | - { |
|
122 | - $testData = [ |
|
123 | - 'id' => rand(1, 100), |
|
124 | - 'path' => 'test-path', |
|
125 | - 'display' => 0 |
|
126 | - ]; |
|
127 | - |
|
128 | - $this->insertPostData($testData); |
|
129 | - |
|
130 | - $repository = new MysqlPostRepository(self::$connection); |
|
131 | - $data = $repository->findPostByPath($testData['path']); |
|
132 | - |
|
133 | - $this->assertFalse($data); |
|
134 | - } |
|
135 | - |
|
136 | - public function testFindPostByPathFailure() |
|
137 | - { |
|
138 | - $repository = new MysqlPostRepository(self::$connection); |
|
139 | - $data = $repository->findPostByPath(''); |
|
140 | - |
|
141 | - $this->assertFalse($data); |
|
142 | - } |
|
143 | - |
|
144 | - public function testGetActivePosts() |
|
145 | - { |
|
146 | - $testData = [ |
|
147 | - [ |
|
148 | - 'id' => rand(1, 100), |
|
149 | - 'title' => 'title one', |
|
150 | - 'path' => 'path-one', |
|
151 | - 'category' => 'test category', |
|
152 | - 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
153 | - 'body' => 'body one', |
|
154 | - 'display' => 1, |
|
155 | - ], |
|
156 | - [ |
|
157 | - 'id' => rand(101, 200), |
|
158 | - 'title' => 'title two', |
|
159 | - 'path' => 'path-two', |
|
160 | - 'category' => 'test category', |
|
161 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
162 | - 'body' => 'body one', |
|
163 | - 'display' => 1, |
|
164 | - ], |
|
165 | - ]; |
|
166 | - |
|
167 | - array_walk($testData, [$this, 'insertPostData']); |
|
168 | - |
|
169 | - $repository = new MysqlPostRepository(self::$connection); |
|
170 | - $data = $repository->getActivePosts(); |
|
171 | - |
|
172 | - $this->assertNotFalse($data); |
|
173 | - $this->assertInternalType('array', $data); |
|
174 | - $this->assertCount(count($testData), $data); |
|
175 | - |
|
176 | - usort($testData, function ($rowA, $rowB) { |
|
177 | - return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
178 | - }); |
|
179 | - |
|
180 | - foreach ($testData as $key => $testRow) { |
|
181 | - $this->assertArrayHasKey('id', $data[$key]); |
|
182 | - $this->assertEquals($testRow['id'], $data[$key]['id']); |
|
183 | - $this->assertArrayHasKey('title', $data[$key]); |
|
184 | - $this->assertEquals($testRow['title'], $data[$key]['title']); |
|
185 | - $this->assertArrayHasKey('path', $data[$key]); |
|
186 | - $this->assertEquals($testRow['path'], $data[$key]['path']); |
|
187 | - $this->assertArrayHasKey('date', $data[$key]); |
|
188 | - $this->assertEquals($testRow['date'], $data[$key]['date']); |
|
189 | - $this->assertArrayHasKey('body', $data[$key]); |
|
190 | - $this->assertEquals($testRow['body'], $data[$key]['body']); |
|
191 | - $this->assertArrayHasKey('category', $data[$key]); |
|
192 | - $this->assertEquals($testRow['category'], $data[$key]['category']); |
|
193 | - } |
|
194 | - } |
|
49 | + ); |
|
50 | + |
|
51 | + self::$connection = new ConnectionLocator(function () use ($extendedPdo) { |
|
52 | + return $extendedPdo; |
|
53 | + }); |
|
54 | + } |
|
55 | + |
|
56 | + public function testIsInstanceOfPostRepository() |
|
57 | + { |
|
58 | + $repository = new MysqlPostRepository(self::$connection); |
|
59 | + |
|
60 | + $this->assertInstanceOf( |
|
61 | + 'Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository', |
|
62 | + $repository |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + public function testImplementsPostInterface() |
|
67 | + { |
|
68 | + $repository = new MysqlPostRepository(self::$connection); |
|
69 | + |
|
70 | + $this->assertInstanceOf( |
|
71 | + 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
72 | + $repository |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + public function testConstructSetsConnections() |
|
77 | + { |
|
78 | + $respository = new MysqlPostRepository(self::$connection); |
|
79 | + |
|
80 | + $this->assertAttributeSame( |
|
81 | + self::$connection, |
|
82 | + 'connections', |
|
83 | + $respository |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + public function testFindPostByPath() |
|
88 | + { |
|
89 | + $testData = [ |
|
90 | + 'id' => rand(1, 100), |
|
91 | + 'title' => 'test title', |
|
92 | + 'path' => 'test-path', |
|
93 | + 'category' => 'test category', |
|
94 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
95 | + 'body' => 'test body', |
|
96 | + 'display' => 1 |
|
97 | + ]; |
|
98 | + |
|
99 | + $this->insertPostData($testData); |
|
100 | + |
|
101 | + $repository = new MysqlPostRepository(self::$connection); |
|
102 | + $data = $repository->findPostByPath($testData['path']); |
|
103 | + |
|
104 | + $this->assertNotFalse($data); |
|
105 | + $this->assertInternalType('array', $data); |
|
106 | + $this->assertArrayHasKey('id', $data); |
|
107 | + $this->assertEquals($testData['id'], $data['id']); |
|
108 | + $this->assertArrayHasKey('title', $data); |
|
109 | + $this->assertEquals($testData['title'], $data['title']); |
|
110 | + $this->assertArrayHasKey('path', $data); |
|
111 | + $this->assertEquals($testData['path'], $data['path']); |
|
112 | + $this->assertArrayHasKey('date', $data); |
|
113 | + $this->assertEquals($testData['date'], $data['date']); |
|
114 | + $this->assertArrayHasKey('body', $data); |
|
115 | + $this->assertEquals($testData['body'], $data['body']); |
|
116 | + $this->assertArrayHasKey('category', $data); |
|
117 | + $this->assertEquals($testData['category'], $data['category']); |
|
118 | + } |
|
119 | + |
|
120 | + public function testFindPostByPathInactive() |
|
121 | + { |
|
122 | + $testData = [ |
|
123 | + 'id' => rand(1, 100), |
|
124 | + 'path' => 'test-path', |
|
125 | + 'display' => 0 |
|
126 | + ]; |
|
127 | + |
|
128 | + $this->insertPostData($testData); |
|
129 | + |
|
130 | + $repository = new MysqlPostRepository(self::$connection); |
|
131 | + $data = $repository->findPostByPath($testData['path']); |
|
132 | + |
|
133 | + $this->assertFalse($data); |
|
134 | + } |
|
135 | + |
|
136 | + public function testFindPostByPathFailure() |
|
137 | + { |
|
138 | + $repository = new MysqlPostRepository(self::$connection); |
|
139 | + $data = $repository->findPostByPath(''); |
|
140 | + |
|
141 | + $this->assertFalse($data); |
|
142 | + } |
|
143 | + |
|
144 | + public function testGetActivePosts() |
|
145 | + { |
|
146 | + $testData = [ |
|
147 | + [ |
|
148 | + 'id' => rand(1, 100), |
|
149 | + 'title' => 'title one', |
|
150 | + 'path' => 'path-one', |
|
151 | + 'category' => 'test category', |
|
152 | + 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
153 | + 'body' => 'body one', |
|
154 | + 'display' => 1, |
|
155 | + ], |
|
156 | + [ |
|
157 | + 'id' => rand(101, 200), |
|
158 | + 'title' => 'title two', |
|
159 | + 'path' => 'path-two', |
|
160 | + 'category' => 'test category', |
|
161 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
162 | + 'body' => 'body one', |
|
163 | + 'display' => 1, |
|
164 | + ], |
|
165 | + ]; |
|
166 | + |
|
167 | + array_walk($testData, [$this, 'insertPostData']); |
|
168 | + |
|
169 | + $repository = new MysqlPostRepository(self::$connection); |
|
170 | + $data = $repository->getActivePosts(); |
|
171 | + |
|
172 | + $this->assertNotFalse($data); |
|
173 | + $this->assertInternalType('array', $data); |
|
174 | + $this->assertCount(count($testData), $data); |
|
175 | + |
|
176 | + usort($testData, function ($rowA, $rowB) { |
|
177 | + return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
178 | + }); |
|
179 | + |
|
180 | + foreach ($testData as $key => $testRow) { |
|
181 | + $this->assertArrayHasKey('id', $data[$key]); |
|
182 | + $this->assertEquals($testRow['id'], $data[$key]['id']); |
|
183 | + $this->assertArrayHasKey('title', $data[$key]); |
|
184 | + $this->assertEquals($testRow['title'], $data[$key]['title']); |
|
185 | + $this->assertArrayHasKey('path', $data[$key]); |
|
186 | + $this->assertEquals($testRow['path'], $data[$key]['path']); |
|
187 | + $this->assertArrayHasKey('date', $data[$key]); |
|
188 | + $this->assertEquals($testRow['date'], $data[$key]['date']); |
|
189 | + $this->assertArrayHasKey('body', $data[$key]); |
|
190 | + $this->assertEquals($testRow['body'], $data[$key]['body']); |
|
191 | + $this->assertArrayHasKey('category', $data[$key]); |
|
192 | + $this->assertEquals($testRow['category'], $data[$key]['category']); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - public function testGetActivePostsInactive() |
|
197 | - { |
|
198 | - $testData = [ |
|
199 | - [ |
|
200 | - 'id' => rand(1, 100), |
|
201 | - 'display' => 1, |
|
202 | - ], |
|
203 | - [ |
|
204 | - 'id' => rand(101, 200), |
|
205 | - 'display' => 0, |
|
206 | - ], |
|
207 | - [ |
|
208 | - 'id' => rand(201, 300), |
|
209 | - 'display' => 1, |
|
210 | - ], |
|
211 | - ]; |
|
212 | - |
|
213 | - array_walk($testData, [$this, 'insertPostData']); |
|
214 | - |
|
215 | - $repository = new MysqlPostRepository(self::$connection); |
|
216 | - $data = $repository->getActivePosts(); |
|
217 | - |
|
218 | - $this->assertNotFalse($data); |
|
219 | - $this->assertInternalType('array', $data); |
|
220 | - |
|
221 | - $testData = array_filter($testData, function ($row) { |
|
222 | - return ($row['display'] == 1); |
|
223 | - }); |
|
224 | - |
|
225 | - $this->assertCount(count($testData), $data); |
|
226 | - |
|
227 | - $testIds = array_column($testData, 'ids'); |
|
228 | - $dataIds = array_column($data, 'ids'); |
|
229 | - |
|
230 | - $this->assertEmpty(array_merge( |
|
231 | - array_diff($testIds, $dataIds), |
|
232 | - array_diff($dataIds, $testIds) |
|
233 | - )); |
|
234 | - } |
|
196 | + public function testGetActivePostsInactive() |
|
197 | + { |
|
198 | + $testData = [ |
|
199 | + [ |
|
200 | + 'id' => rand(1, 100), |
|
201 | + 'display' => 1, |
|
202 | + ], |
|
203 | + [ |
|
204 | + 'id' => rand(101, 200), |
|
205 | + 'display' => 0, |
|
206 | + ], |
|
207 | + [ |
|
208 | + 'id' => rand(201, 300), |
|
209 | + 'display' => 1, |
|
210 | + ], |
|
211 | + ]; |
|
212 | + |
|
213 | + array_walk($testData, [$this, 'insertPostData']); |
|
214 | + |
|
215 | + $repository = new MysqlPostRepository(self::$connection); |
|
216 | + $data = $repository->getActivePosts(); |
|
217 | + |
|
218 | + $this->assertNotFalse($data); |
|
219 | + $this->assertInternalType('array', $data); |
|
220 | + |
|
221 | + $testData = array_filter($testData, function ($row) { |
|
222 | + return ($row['display'] == 1); |
|
223 | + }); |
|
224 | + |
|
225 | + $this->assertCount(count($testData), $data); |
|
226 | + |
|
227 | + $testIds = array_column($testData, 'ids'); |
|
228 | + $dataIds = array_column($data, 'ids'); |
|
229 | + |
|
230 | + $this->assertEmpty(array_merge( |
|
231 | + array_diff($testIds, $dataIds), |
|
232 | + array_diff($dataIds, $testIds) |
|
233 | + )); |
|
234 | + } |
|
235 | 235 | |
236 | - public function testGetActivePostsFailure() |
|
237 | - { |
|
238 | - $repository = new MysqlPostRepository(self::$connection); |
|
239 | - $data = $repository->getActivePosts(); |
|
240 | - |
|
241 | - $this->assertEmpty($data); |
|
242 | - $this->assertInternalType('array', $data); |
|
243 | - } |
|
244 | - |
|
245 | - public function testGetActivePostsRange() |
|
246 | - { |
|
247 | - $testData = [ |
|
248 | - [ |
|
249 | - 'id' => rand(1, 100), |
|
250 | - 'display' => 1, |
|
251 | - ], |
|
252 | - [ |
|
253 | - 'id' => rand(101, 200), |
|
254 | - 'display' => 1, |
|
255 | - ], |
|
256 | - [ |
|
257 | - 'id' => rand(201, 300), |
|
258 | - 'display' => 1, |
|
259 | - ], |
|
260 | - ]; |
|
261 | - |
|
262 | - array_walk($testData, [$this, 'insertPostData']); |
|
263 | - |
|
264 | - $repository = new MysqlPostRepository(self::$connection); |
|
265 | - $data = $repository->getActivePosts(2, 1); |
|
266 | - |
|
267 | - $this->assertNotFalse($data); |
|
268 | - $this->assertInternalType('array', $data); |
|
269 | - $this->assertCount(2, $data); |
|
270 | - |
|
271 | - $testData = array_slice($testData, 2, 1); |
|
272 | - |
|
273 | - $testIds = array_column($testData, 'ids'); |
|
274 | - $dataIds = array_column($data, 'ids'); |
|
275 | - |
|
276 | - $this->assertEmpty(array_merge( |
|
277 | - array_diff($testIds, $dataIds), |
|
278 | - array_diff($dataIds, $testIds) |
|
279 | - )); |
|
280 | - } |
|
281 | - |
|
282 | - public function testGetActivePostsRangeFailure() |
|
283 | - { |
|
284 | - $testData = [ |
|
285 | - [ |
|
286 | - 'id' => rand(1, 100), |
|
287 | - 'display' => 1, |
|
288 | - ], |
|
289 | - [ |
|
290 | - 'id' => rand(101, 200), |
|
291 | - 'display' => 1, |
|
292 | - ], |
|
293 | - [ |
|
294 | - 'id' => rand(201, 300), |
|
295 | - 'display' => 1, |
|
296 | - ], |
|
297 | - ]; |
|
298 | - |
|
299 | - array_walk($testData, [$this, 'insertPostData']); |
|
300 | - |
|
301 | - $repository = new MysqlPostRepository(self::$connection); |
|
302 | - $data = $repository->getActivePosts(1, 3); |
|
303 | - |
|
304 | - $this->assertEmpty($data); |
|
305 | - $this->assertInternalType('array', $data); |
|
306 | - } |
|
307 | - |
|
308 | - public function testGetActivePostsCount() |
|
309 | - { |
|
310 | - $testData = [ |
|
311 | - [ |
|
312 | - 'id' => rand(1, 100), |
|
313 | - 'display' => 1, |
|
314 | - ], |
|
315 | - [ |
|
316 | - 'id' => rand(101, 200), |
|
317 | - 'display' => 1, |
|
318 | - ], |
|
319 | - ]; |
|
320 | - |
|
321 | - array_walk($testData, [$this, 'insertPostData']); |
|
322 | - |
|
323 | - $repository = new MysqlPostRepository(self::$connection); |
|
324 | - $data = $repository->getActivePostsCount(); |
|
325 | - |
|
326 | - $this->assertNotFalse($data); |
|
327 | - $this->assertStringMatchesFormat('%d', $data); |
|
328 | - $this->assertEquals(count($testData), $data); |
|
329 | - } |
|
330 | - |
|
331 | - public function testGetActivePostsCountInactive() |
|
332 | - { |
|
333 | - $testData = [ |
|
334 | - [ |
|
335 | - 'id' => rand(1, 100), |
|
336 | - 'display' => 1, |
|
337 | - ], |
|
338 | - [ |
|
339 | - 'id' => rand(101, 200), |
|
340 | - 'display' => 1, |
|
341 | - ], |
|
342 | - [ |
|
343 | - 'id' => rand(201, 300), |
|
344 | - 'display' => 0, |
|
345 | - ], |
|
346 | - ]; |
|
347 | - |
|
348 | - array_walk($testData, [$this, 'insertPostData']); |
|
349 | - |
|
350 | - $repository = new MysqlPostRepository(self::$connection); |
|
351 | - $data = $repository->getActivePostsCount(); |
|
352 | - |
|
353 | - $this->assertNotFalse($data); |
|
354 | - $this->assertStringMatchesFormat('%d', $data); |
|
355 | - |
|
356 | - $testData = array_filter($testData, function ($row) { |
|
357 | - return ($row['display'] == 1); |
|
358 | - }); |
|
359 | - |
|
360 | - $this->assertEquals(count($testData), $data); |
|
361 | - } |
|
362 | - |
|
363 | - public function testGetActivePostsCountFailure() |
|
364 | - { |
|
365 | - $repository = new MysqlPostRepository(self::$connection); |
|
366 | - $data = $repository->getActivePostsCount(); |
|
367 | - |
|
368 | - $this->assertNotFalse($data); |
|
369 | - $this->assertStringMatchesFormat('%d', $data); |
|
370 | - $this->assertEquals('0', $data); |
|
371 | - } |
|
372 | - |
|
373 | - public function testGetActivePostsByTag() |
|
374 | - { |
|
375 | - $testPostData = [ |
|
376 | - [ |
|
377 | - 'id' => rand(1, 100), |
|
378 | - 'title' => 'title one', |
|
379 | - 'path' => 'path-one', |
|
380 | - 'category' => 'test category', |
|
381 | - 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
382 | - 'body' => 'body one', |
|
383 | - 'display' => 1, |
|
384 | - ], |
|
385 | - [ |
|
386 | - 'id' => rand(101, 200), |
|
387 | - 'title' => 'title two', |
|
388 | - 'path' => 'path-two', |
|
389 | - 'category' => 'test category', |
|
390 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
391 | - 'body' => 'body one', |
|
392 | - 'display' => 1, |
|
393 | - ], |
|
394 | - ]; |
|
395 | - |
|
396 | - $testTagData = [ |
|
397 | - 'id' => rand(1, 100), |
|
398 | - ]; |
|
399 | - |
|
400 | - $testPTLinkData = []; |
|
401 | - foreach ($testPostData as $testPostRow) { |
|
402 | - array_push($testPTLinkData, [ |
|
403 | - 'post_id' => $testPostRow['id'], |
|
404 | - 'tag_id' => $testTagData['id'], |
|
405 | - ]); |
|
406 | - } |
|
407 | - |
|
408 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
409 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
410 | - $this->insertTagData($testTagData); |
|
411 | - |
|
412 | - $repository = new MysqlPostRepository(self::$connection); |
|
413 | - $data = $repository->getActivePostsByTag($testTagData['id']); |
|
414 | - |
|
415 | - $this->assertNotFalse($data); |
|
416 | - $this->assertInternalType('array', $data); |
|
417 | - $this->assertCount(count($testPostData), $data); |
|
418 | - |
|
419 | - usort($testPostData, function ($rowA, $rowB) { |
|
420 | - return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
421 | - }); |
|
422 | - |
|
423 | - foreach ($testPostData as $key => $testPostRow) { |
|
424 | - $this->assertArrayHasKey('id', $data[$key]); |
|
425 | - $this->assertEquals($testPostRow['id'], $data[$key]['id']); |
|
426 | - $this->assertArrayHasKey('title', $data[$key]); |
|
427 | - $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
428 | - $this->assertArrayHasKey('path', $data[$key]); |
|
429 | - $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
430 | - $this->assertArrayHasKey('date', $data[$key]); |
|
431 | - $this->assertEquals($testPostRow['date'], $data[$key]['date']); |
|
432 | - $this->assertArrayHasKey('body', $data[$key]); |
|
433 | - $this->assertEquals($testPostRow['body'], $data[$key]['body']); |
|
434 | - $this->assertArrayHasKey('category', $data[$key]); |
|
435 | - $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - public function testGetActivePostsByTagInactive() |
|
440 | - { |
|
441 | - $testPostData = [ |
|
442 | - [ |
|
443 | - 'id' => rand(1, 100), |
|
444 | - 'display' => 1, |
|
445 | - ], |
|
446 | - [ |
|
447 | - 'id' => rand(101, 200), |
|
448 | - 'display' => 0, |
|
449 | - ], |
|
450 | - [ |
|
451 | - 'id' => rand(201, 300), |
|
452 | - 'display' => 1, |
|
453 | - ], |
|
454 | - ]; |
|
455 | - |
|
456 | - $testTagData = [ |
|
457 | - 'id' => rand(1, 100), |
|
458 | - ]; |
|
459 | - |
|
460 | - $testPTLinkData = []; |
|
461 | - foreach ($testPostData as $testPostRow) { |
|
462 | - array_push($testPTLinkData, [ |
|
463 | - 'post_id' => $testPostRow['id'], |
|
464 | - 'tag_id' => $testTagData['id'], |
|
465 | - ]); |
|
466 | - } |
|
467 | - |
|
468 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
469 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
470 | - $this->insertTagData($testTagData); |
|
471 | - |
|
472 | - $repository = new MysqlPostRepository(self::$connection); |
|
473 | - $data = $repository->getActivePostsByTag($testTagData['id']); |
|
474 | - |
|
475 | - $this->assertNotFalse($data); |
|
476 | - $this->assertInternalType('array', $data); |
|
477 | - |
|
478 | - $testPostData = array_filter($testPostData, function ($row) { |
|
479 | - return ($row['display'] == 1); |
|
480 | - }); |
|
481 | - |
|
482 | - $this->assertCount(count($testPostData), $data); |
|
483 | - |
|
484 | - $testIds = array_column($testPostData, 'ids'); |
|
485 | - $dataIds = array_column($data, 'ids'); |
|
486 | - |
|
487 | - $this->assertEmpty(array_merge( |
|
488 | - array_diff($testIds, $dataIds), |
|
489 | - array_diff($dataIds, $testIds) |
|
490 | - )); |
|
491 | - } |
|
236 | + public function testGetActivePostsFailure() |
|
237 | + { |
|
238 | + $repository = new MysqlPostRepository(self::$connection); |
|
239 | + $data = $repository->getActivePosts(); |
|
240 | + |
|
241 | + $this->assertEmpty($data); |
|
242 | + $this->assertInternalType('array', $data); |
|
243 | + } |
|
244 | + |
|
245 | + public function testGetActivePostsRange() |
|
246 | + { |
|
247 | + $testData = [ |
|
248 | + [ |
|
249 | + 'id' => rand(1, 100), |
|
250 | + 'display' => 1, |
|
251 | + ], |
|
252 | + [ |
|
253 | + 'id' => rand(101, 200), |
|
254 | + 'display' => 1, |
|
255 | + ], |
|
256 | + [ |
|
257 | + 'id' => rand(201, 300), |
|
258 | + 'display' => 1, |
|
259 | + ], |
|
260 | + ]; |
|
261 | + |
|
262 | + array_walk($testData, [$this, 'insertPostData']); |
|
263 | + |
|
264 | + $repository = new MysqlPostRepository(self::$connection); |
|
265 | + $data = $repository->getActivePosts(2, 1); |
|
266 | + |
|
267 | + $this->assertNotFalse($data); |
|
268 | + $this->assertInternalType('array', $data); |
|
269 | + $this->assertCount(2, $data); |
|
270 | + |
|
271 | + $testData = array_slice($testData, 2, 1); |
|
272 | + |
|
273 | + $testIds = array_column($testData, 'ids'); |
|
274 | + $dataIds = array_column($data, 'ids'); |
|
275 | + |
|
276 | + $this->assertEmpty(array_merge( |
|
277 | + array_diff($testIds, $dataIds), |
|
278 | + array_diff($dataIds, $testIds) |
|
279 | + )); |
|
280 | + } |
|
281 | + |
|
282 | + public function testGetActivePostsRangeFailure() |
|
283 | + { |
|
284 | + $testData = [ |
|
285 | + [ |
|
286 | + 'id' => rand(1, 100), |
|
287 | + 'display' => 1, |
|
288 | + ], |
|
289 | + [ |
|
290 | + 'id' => rand(101, 200), |
|
291 | + 'display' => 1, |
|
292 | + ], |
|
293 | + [ |
|
294 | + 'id' => rand(201, 300), |
|
295 | + 'display' => 1, |
|
296 | + ], |
|
297 | + ]; |
|
298 | + |
|
299 | + array_walk($testData, [$this, 'insertPostData']); |
|
300 | + |
|
301 | + $repository = new MysqlPostRepository(self::$connection); |
|
302 | + $data = $repository->getActivePosts(1, 3); |
|
303 | + |
|
304 | + $this->assertEmpty($data); |
|
305 | + $this->assertInternalType('array', $data); |
|
306 | + } |
|
307 | + |
|
308 | + public function testGetActivePostsCount() |
|
309 | + { |
|
310 | + $testData = [ |
|
311 | + [ |
|
312 | + 'id' => rand(1, 100), |
|
313 | + 'display' => 1, |
|
314 | + ], |
|
315 | + [ |
|
316 | + 'id' => rand(101, 200), |
|
317 | + 'display' => 1, |
|
318 | + ], |
|
319 | + ]; |
|
320 | + |
|
321 | + array_walk($testData, [$this, 'insertPostData']); |
|
322 | + |
|
323 | + $repository = new MysqlPostRepository(self::$connection); |
|
324 | + $data = $repository->getActivePostsCount(); |
|
325 | + |
|
326 | + $this->assertNotFalse($data); |
|
327 | + $this->assertStringMatchesFormat('%d', $data); |
|
328 | + $this->assertEquals(count($testData), $data); |
|
329 | + } |
|
330 | + |
|
331 | + public function testGetActivePostsCountInactive() |
|
332 | + { |
|
333 | + $testData = [ |
|
334 | + [ |
|
335 | + 'id' => rand(1, 100), |
|
336 | + 'display' => 1, |
|
337 | + ], |
|
338 | + [ |
|
339 | + 'id' => rand(101, 200), |
|
340 | + 'display' => 1, |
|
341 | + ], |
|
342 | + [ |
|
343 | + 'id' => rand(201, 300), |
|
344 | + 'display' => 0, |
|
345 | + ], |
|
346 | + ]; |
|
347 | + |
|
348 | + array_walk($testData, [$this, 'insertPostData']); |
|
349 | + |
|
350 | + $repository = new MysqlPostRepository(self::$connection); |
|
351 | + $data = $repository->getActivePostsCount(); |
|
352 | + |
|
353 | + $this->assertNotFalse($data); |
|
354 | + $this->assertStringMatchesFormat('%d', $data); |
|
355 | + |
|
356 | + $testData = array_filter($testData, function ($row) { |
|
357 | + return ($row['display'] == 1); |
|
358 | + }); |
|
359 | + |
|
360 | + $this->assertEquals(count($testData), $data); |
|
361 | + } |
|
362 | + |
|
363 | + public function testGetActivePostsCountFailure() |
|
364 | + { |
|
365 | + $repository = new MysqlPostRepository(self::$connection); |
|
366 | + $data = $repository->getActivePostsCount(); |
|
367 | + |
|
368 | + $this->assertNotFalse($data); |
|
369 | + $this->assertStringMatchesFormat('%d', $data); |
|
370 | + $this->assertEquals('0', $data); |
|
371 | + } |
|
372 | + |
|
373 | + public function testGetActivePostsByTag() |
|
374 | + { |
|
375 | + $testPostData = [ |
|
376 | + [ |
|
377 | + 'id' => rand(1, 100), |
|
378 | + 'title' => 'title one', |
|
379 | + 'path' => 'path-one', |
|
380 | + 'category' => 'test category', |
|
381 | + 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
382 | + 'body' => 'body one', |
|
383 | + 'display' => 1, |
|
384 | + ], |
|
385 | + [ |
|
386 | + 'id' => rand(101, 200), |
|
387 | + 'title' => 'title two', |
|
388 | + 'path' => 'path-two', |
|
389 | + 'category' => 'test category', |
|
390 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
391 | + 'body' => 'body one', |
|
392 | + 'display' => 1, |
|
393 | + ], |
|
394 | + ]; |
|
395 | + |
|
396 | + $testTagData = [ |
|
397 | + 'id' => rand(1, 100), |
|
398 | + ]; |
|
399 | + |
|
400 | + $testPTLinkData = []; |
|
401 | + foreach ($testPostData as $testPostRow) { |
|
402 | + array_push($testPTLinkData, [ |
|
403 | + 'post_id' => $testPostRow['id'], |
|
404 | + 'tag_id' => $testTagData['id'], |
|
405 | + ]); |
|
406 | + } |
|
407 | + |
|
408 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
409 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
410 | + $this->insertTagData($testTagData); |
|
411 | + |
|
412 | + $repository = new MysqlPostRepository(self::$connection); |
|
413 | + $data = $repository->getActivePostsByTag($testTagData['id']); |
|
414 | + |
|
415 | + $this->assertNotFalse($data); |
|
416 | + $this->assertInternalType('array', $data); |
|
417 | + $this->assertCount(count($testPostData), $data); |
|
418 | + |
|
419 | + usort($testPostData, function ($rowA, $rowB) { |
|
420 | + return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
421 | + }); |
|
422 | + |
|
423 | + foreach ($testPostData as $key => $testPostRow) { |
|
424 | + $this->assertArrayHasKey('id', $data[$key]); |
|
425 | + $this->assertEquals($testPostRow['id'], $data[$key]['id']); |
|
426 | + $this->assertArrayHasKey('title', $data[$key]); |
|
427 | + $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
428 | + $this->assertArrayHasKey('path', $data[$key]); |
|
429 | + $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
430 | + $this->assertArrayHasKey('date', $data[$key]); |
|
431 | + $this->assertEquals($testPostRow['date'], $data[$key]['date']); |
|
432 | + $this->assertArrayHasKey('body', $data[$key]); |
|
433 | + $this->assertEquals($testPostRow['body'], $data[$key]['body']); |
|
434 | + $this->assertArrayHasKey('category', $data[$key]); |
|
435 | + $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
436 | + } |
|
437 | + } |
|
438 | + |
|
439 | + public function testGetActivePostsByTagInactive() |
|
440 | + { |
|
441 | + $testPostData = [ |
|
442 | + [ |
|
443 | + 'id' => rand(1, 100), |
|
444 | + 'display' => 1, |
|
445 | + ], |
|
446 | + [ |
|
447 | + 'id' => rand(101, 200), |
|
448 | + 'display' => 0, |
|
449 | + ], |
|
450 | + [ |
|
451 | + 'id' => rand(201, 300), |
|
452 | + 'display' => 1, |
|
453 | + ], |
|
454 | + ]; |
|
455 | + |
|
456 | + $testTagData = [ |
|
457 | + 'id' => rand(1, 100), |
|
458 | + ]; |
|
459 | + |
|
460 | + $testPTLinkData = []; |
|
461 | + foreach ($testPostData as $testPostRow) { |
|
462 | + array_push($testPTLinkData, [ |
|
463 | + 'post_id' => $testPostRow['id'], |
|
464 | + 'tag_id' => $testTagData['id'], |
|
465 | + ]); |
|
466 | + } |
|
467 | + |
|
468 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
469 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
470 | + $this->insertTagData($testTagData); |
|
471 | + |
|
472 | + $repository = new MysqlPostRepository(self::$connection); |
|
473 | + $data = $repository->getActivePostsByTag($testTagData['id']); |
|
474 | + |
|
475 | + $this->assertNotFalse($data); |
|
476 | + $this->assertInternalType('array', $data); |
|
477 | + |
|
478 | + $testPostData = array_filter($testPostData, function ($row) { |
|
479 | + return ($row['display'] == 1); |
|
480 | + }); |
|
481 | + |
|
482 | + $this->assertCount(count($testPostData), $data); |
|
483 | + |
|
484 | + $testIds = array_column($testPostData, 'ids'); |
|
485 | + $dataIds = array_column($data, 'ids'); |
|
486 | + |
|
487 | + $this->assertEmpty(array_merge( |
|
488 | + array_diff($testIds, $dataIds), |
|
489 | + array_diff($dataIds, $testIds) |
|
490 | + )); |
|
491 | + } |
|
492 | 492 | |
493 | - public function testGetActivePostsByTagFailure() |
|
494 | - { |
|
495 | - $testTagData = [ |
|
496 | - 'id' => rand(1, 100), |
|
497 | - ]; |
|
498 | - |
|
499 | - $repository = new MysqlPostRepository(self::$connection); |
|
500 | - $data = $repository->getActivePostsByTag($testTagData['id']); |
|
501 | - |
|
502 | - $this->assertEmpty($data); |
|
503 | - $this->assertInternalType('array', $data); |
|
504 | - } |
|
505 | - |
|
506 | - public function testGetActivePostsByTagRange() |
|
507 | - { |
|
508 | - $testPostData = [ |
|
509 | - [ |
|
510 | - 'id' => rand(1, 100), |
|
511 | - 'display' => 1, |
|
512 | - ], |
|
513 | - [ |
|
514 | - 'id' => rand(101, 200), |
|
515 | - 'display' => 1, |
|
516 | - ], |
|
517 | - [ |
|
518 | - 'id' => rand(201, 300), |
|
519 | - 'display' => 1, |
|
520 | - ], |
|
521 | - ]; |
|
522 | - |
|
523 | - $testTagData = [ |
|
524 | - 'id' => rand(1, 100), |
|
525 | - ]; |
|
526 | - |
|
527 | - $testPTLinkData = []; |
|
528 | - foreach ($testPostData as $testPostRow) { |
|
529 | - array_push($testPTLinkData, [ |
|
530 | - 'post_id' => $testPostRow['id'], |
|
531 | - 'tag_id' => $testTagData['id'], |
|
532 | - ]); |
|
533 | - } |
|
534 | - |
|
535 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
536 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
537 | - $this->insertTagData($testTagData); |
|
538 | - |
|
539 | - $repository = new MysqlPostRepository(self::$connection); |
|
540 | - $data = $repository->getActivePostsByTag($testTagData['id'], 2, 1); |
|
541 | - |
|
542 | - $this->assertNotFalse($data); |
|
543 | - $this->assertInternalType('array', $data); |
|
544 | - |
|
545 | - $testPostData = array_slice($testPostData, 1, 2); |
|
546 | - |
|
547 | - $this->assertCount(count($testPostData), $data); |
|
548 | - |
|
549 | - $testIds = array_column($testPostData, 'ids'); |
|
550 | - $dataIds = array_column($data, 'ids'); |
|
551 | - |
|
552 | - $this->assertEmpty(array_merge( |
|
553 | - array_diff($testIds, $dataIds), |
|
554 | - array_diff($dataIds, $testIds) |
|
555 | - )); |
|
556 | - } |
|
557 | - |
|
558 | - public function testGetActivePostsByTagRangeFailure() |
|
559 | - { |
|
560 | - $testPostData = [ |
|
561 | - [ |
|
562 | - 'id' => rand(1, 100), |
|
563 | - 'display' => 1, |
|
564 | - ], |
|
565 | - [ |
|
566 | - 'id' => rand(101, 200), |
|
567 | - 'display' => 1, |
|
568 | - ], |
|
569 | - [ |
|
570 | - 'id' => rand(201, 300), |
|
571 | - 'display' => 1, |
|
572 | - ], |
|
573 | - ]; |
|
574 | - |
|
575 | - $testTagData = [ |
|
576 | - 'id' => rand(1, 100), |
|
577 | - ]; |
|
578 | - |
|
579 | - $testPTLinkData = []; |
|
580 | - foreach ($testPostData as $testPostRow) { |
|
581 | - array_push($testPTLinkData, [ |
|
582 | - 'post_id' => $testPostRow['id'], |
|
583 | - 'tag_id' => $testTagData['id'], |
|
584 | - ]); |
|
585 | - } |
|
586 | - |
|
587 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
588 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
589 | - $this->insertTagData($testTagData); |
|
590 | - |
|
591 | - $repository = new MysqlPostRepository(self::$connection); |
|
592 | - $data = $repository->getActivePostsByTag($testTagData['id'], 1, 3); |
|
593 | - |
|
594 | - $this->assertEmpty($data); |
|
595 | - $this->assertInternalType('array', $data); |
|
596 | - } |
|
597 | - |
|
598 | - public function testGetActivePostsCountByTag() |
|
599 | - { |
|
600 | - $testPostData = [ |
|
601 | - [ |
|
602 | - 'id' => rand(1, 100), |
|
603 | - 'display' => 1, |
|
604 | - ], |
|
605 | - [ |
|
606 | - 'id' => rand(101, 200), |
|
607 | - 'display' => 1, |
|
608 | - ], |
|
609 | - [ |
|
610 | - 'id' => rand(201, 300), |
|
611 | - 'display' => 1, |
|
612 | - ], |
|
613 | - ]; |
|
614 | - |
|
615 | - $testTagData = [ |
|
616 | - 'id' => rand(1, 100), |
|
617 | - ]; |
|
618 | - |
|
619 | - $testPTLinkData = []; |
|
620 | - foreach ($testPostData as $testPostRow) { |
|
621 | - array_push($testPTLinkData, [ |
|
622 | - 'post_id' => $testPostRow['id'], |
|
623 | - 'tag_id' => $testTagData['id'], |
|
624 | - ]); |
|
625 | - } |
|
626 | - |
|
627 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
628 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
629 | - $this->insertTagData($testTagData); |
|
630 | - |
|
631 | - $repository = new MysqlPostRepository(self::$connection); |
|
632 | - $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
633 | - |
|
634 | - $this->assertNotFalse($data); |
|
635 | - $this->assertStringMatchesFormat('%d', $data); |
|
636 | - $this->assertEquals(count($testPostData), $data); |
|
637 | - } |
|
638 | - |
|
639 | - public function testGetActivePostsCountByTagInactive() |
|
640 | - { |
|
641 | - $testPostData = [ |
|
642 | - [ |
|
643 | - 'id' => rand(1, 100), |
|
644 | - 'display' => 1, |
|
645 | - ], |
|
646 | - [ |
|
647 | - 'id' => rand(101, 200), |
|
648 | - 'display' => 0, |
|
649 | - ], |
|
650 | - [ |
|
651 | - 'id' => rand(201, 300), |
|
652 | - 'display' => 1, |
|
653 | - ], |
|
654 | - ]; |
|
655 | - |
|
656 | - $testTagData = [ |
|
657 | - 'id' => rand(1, 100), |
|
658 | - ]; |
|
659 | - |
|
660 | - $testPTLinkData = []; |
|
661 | - foreach ($testPostData as $testPostRow) { |
|
662 | - array_push($testPTLinkData, [ |
|
663 | - 'post_id' => $testPostRow['id'], |
|
664 | - 'tag_id' => $testTagData['id'], |
|
665 | - ]); |
|
666 | - } |
|
667 | - |
|
668 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
669 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
670 | - $this->insertTagData($testTagData); |
|
671 | - |
|
672 | - $repository = new MysqlPostRepository(self::$connection); |
|
673 | - $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
674 | - |
|
675 | - $this->assertNotFalse($data); |
|
676 | - $this->assertStringMatchesFormat('%d', $data); |
|
677 | - |
|
678 | - $testPostData = array_filter($testPostData, function ($row) { |
|
679 | - return ($row['display'] == 1); |
|
680 | - }); |
|
681 | - |
|
682 | - $this->assertEquals(count($testPostData), $data); |
|
683 | - } |
|
493 | + public function testGetActivePostsByTagFailure() |
|
494 | + { |
|
495 | + $testTagData = [ |
|
496 | + 'id' => rand(1, 100), |
|
497 | + ]; |
|
498 | + |
|
499 | + $repository = new MysqlPostRepository(self::$connection); |
|
500 | + $data = $repository->getActivePostsByTag($testTagData['id']); |
|
501 | + |
|
502 | + $this->assertEmpty($data); |
|
503 | + $this->assertInternalType('array', $data); |
|
504 | + } |
|
505 | + |
|
506 | + public function testGetActivePostsByTagRange() |
|
507 | + { |
|
508 | + $testPostData = [ |
|
509 | + [ |
|
510 | + 'id' => rand(1, 100), |
|
511 | + 'display' => 1, |
|
512 | + ], |
|
513 | + [ |
|
514 | + 'id' => rand(101, 200), |
|
515 | + 'display' => 1, |
|
516 | + ], |
|
517 | + [ |
|
518 | + 'id' => rand(201, 300), |
|
519 | + 'display' => 1, |
|
520 | + ], |
|
521 | + ]; |
|
522 | + |
|
523 | + $testTagData = [ |
|
524 | + 'id' => rand(1, 100), |
|
525 | + ]; |
|
526 | + |
|
527 | + $testPTLinkData = []; |
|
528 | + foreach ($testPostData as $testPostRow) { |
|
529 | + array_push($testPTLinkData, [ |
|
530 | + 'post_id' => $testPostRow['id'], |
|
531 | + 'tag_id' => $testTagData['id'], |
|
532 | + ]); |
|
533 | + } |
|
534 | + |
|
535 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
536 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
537 | + $this->insertTagData($testTagData); |
|
538 | + |
|
539 | + $repository = new MysqlPostRepository(self::$connection); |
|
540 | + $data = $repository->getActivePostsByTag($testTagData['id'], 2, 1); |
|
541 | + |
|
542 | + $this->assertNotFalse($data); |
|
543 | + $this->assertInternalType('array', $data); |
|
544 | + |
|
545 | + $testPostData = array_slice($testPostData, 1, 2); |
|
546 | + |
|
547 | + $this->assertCount(count($testPostData), $data); |
|
548 | + |
|
549 | + $testIds = array_column($testPostData, 'ids'); |
|
550 | + $dataIds = array_column($data, 'ids'); |
|
551 | + |
|
552 | + $this->assertEmpty(array_merge( |
|
553 | + array_diff($testIds, $dataIds), |
|
554 | + array_diff($dataIds, $testIds) |
|
555 | + )); |
|
556 | + } |
|
557 | + |
|
558 | + public function testGetActivePostsByTagRangeFailure() |
|
559 | + { |
|
560 | + $testPostData = [ |
|
561 | + [ |
|
562 | + 'id' => rand(1, 100), |
|
563 | + 'display' => 1, |
|
564 | + ], |
|
565 | + [ |
|
566 | + 'id' => rand(101, 200), |
|
567 | + 'display' => 1, |
|
568 | + ], |
|
569 | + [ |
|
570 | + 'id' => rand(201, 300), |
|
571 | + 'display' => 1, |
|
572 | + ], |
|
573 | + ]; |
|
574 | + |
|
575 | + $testTagData = [ |
|
576 | + 'id' => rand(1, 100), |
|
577 | + ]; |
|
578 | + |
|
579 | + $testPTLinkData = []; |
|
580 | + foreach ($testPostData as $testPostRow) { |
|
581 | + array_push($testPTLinkData, [ |
|
582 | + 'post_id' => $testPostRow['id'], |
|
583 | + 'tag_id' => $testTagData['id'], |
|
584 | + ]); |
|
585 | + } |
|
586 | + |
|
587 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
588 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
589 | + $this->insertTagData($testTagData); |
|
590 | + |
|
591 | + $repository = new MysqlPostRepository(self::$connection); |
|
592 | + $data = $repository->getActivePostsByTag($testTagData['id'], 1, 3); |
|
593 | + |
|
594 | + $this->assertEmpty($data); |
|
595 | + $this->assertInternalType('array', $data); |
|
596 | + } |
|
597 | + |
|
598 | + public function testGetActivePostsCountByTag() |
|
599 | + { |
|
600 | + $testPostData = [ |
|
601 | + [ |
|
602 | + 'id' => rand(1, 100), |
|
603 | + 'display' => 1, |
|
604 | + ], |
|
605 | + [ |
|
606 | + 'id' => rand(101, 200), |
|
607 | + 'display' => 1, |
|
608 | + ], |
|
609 | + [ |
|
610 | + 'id' => rand(201, 300), |
|
611 | + 'display' => 1, |
|
612 | + ], |
|
613 | + ]; |
|
614 | + |
|
615 | + $testTagData = [ |
|
616 | + 'id' => rand(1, 100), |
|
617 | + ]; |
|
618 | + |
|
619 | + $testPTLinkData = []; |
|
620 | + foreach ($testPostData as $testPostRow) { |
|
621 | + array_push($testPTLinkData, [ |
|
622 | + 'post_id' => $testPostRow['id'], |
|
623 | + 'tag_id' => $testTagData['id'], |
|
624 | + ]); |
|
625 | + } |
|
626 | + |
|
627 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
628 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
629 | + $this->insertTagData($testTagData); |
|
630 | + |
|
631 | + $repository = new MysqlPostRepository(self::$connection); |
|
632 | + $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
633 | + |
|
634 | + $this->assertNotFalse($data); |
|
635 | + $this->assertStringMatchesFormat('%d', $data); |
|
636 | + $this->assertEquals(count($testPostData), $data); |
|
637 | + } |
|
638 | + |
|
639 | + public function testGetActivePostsCountByTagInactive() |
|
640 | + { |
|
641 | + $testPostData = [ |
|
642 | + [ |
|
643 | + 'id' => rand(1, 100), |
|
644 | + 'display' => 1, |
|
645 | + ], |
|
646 | + [ |
|
647 | + 'id' => rand(101, 200), |
|
648 | + 'display' => 0, |
|
649 | + ], |
|
650 | + [ |
|
651 | + 'id' => rand(201, 300), |
|
652 | + 'display' => 1, |
|
653 | + ], |
|
654 | + ]; |
|
655 | + |
|
656 | + $testTagData = [ |
|
657 | + 'id' => rand(1, 100), |
|
658 | + ]; |
|
659 | + |
|
660 | + $testPTLinkData = []; |
|
661 | + foreach ($testPostData as $testPostRow) { |
|
662 | + array_push($testPTLinkData, [ |
|
663 | + 'post_id' => $testPostRow['id'], |
|
664 | + 'tag_id' => $testTagData['id'], |
|
665 | + ]); |
|
666 | + } |
|
667 | + |
|
668 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
669 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
670 | + $this->insertTagData($testTagData); |
|
671 | + |
|
672 | + $repository = new MysqlPostRepository(self::$connection); |
|
673 | + $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
674 | + |
|
675 | + $this->assertNotFalse($data); |
|
676 | + $this->assertStringMatchesFormat('%d', $data); |
|
677 | + |
|
678 | + $testPostData = array_filter($testPostData, function ($row) { |
|
679 | + return ($row['display'] == 1); |
|
680 | + }); |
|
681 | + |
|
682 | + $this->assertEquals(count($testPostData), $data); |
|
683 | + } |
|
684 | 684 | |
685 | - public function testGetActivePostsCountByTagFailure() |
|
686 | - { |
|
687 | - $testTagData = [ |
|
688 | - 'id' => rand(1, 100), |
|
689 | - ]; |
|
685 | + public function testGetActivePostsCountByTagFailure() |
|
686 | + { |
|
687 | + $testTagData = [ |
|
688 | + 'id' => rand(1, 100), |
|
689 | + ]; |
|
690 | 690 | |
691 | - $this->insertTagData($testTagData); |
|
691 | + $this->insertTagData($testTagData); |
|
692 | 692 | |
693 | - $repository = new MysqlPostRepository(self::$connection); |
|
694 | - $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
693 | + $repository = new MysqlPostRepository(self::$connection); |
|
694 | + $data = $repository->getActivePostsCountByTag($testTagData['id']); |
|
695 | 695 | |
696 | - $this->assertNotFalse($data); |
|
697 | - $this->assertStringMatchesFormat('%d', $data); |
|
698 | - $this->assertEquals('0', $data); |
|
699 | - } |
|
696 | + $this->assertNotFalse($data); |
|
697 | + $this->assertStringMatchesFormat('%d', $data); |
|
698 | + $this->assertEquals('0', $data); |
|
699 | + } |
|
700 | 700 | |
701 | - public function testGetActivePostsByCategory() |
|
702 | - { |
|
703 | - $testData = [ |
|
704 | - [ |
|
705 | - 'id' => rand(1, 100), |
|
706 | - 'title' => 'title one', |
|
707 | - 'path' => 'path-one', |
|
708 | - 'category' => 'test category', |
|
709 | - 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
710 | - 'body' => 'body one', |
|
711 | - 'display' => 1, |
|
712 | - ], |
|
713 | - [ |
|
714 | - 'id' => rand(101, 200), |
|
715 | - 'title' => 'title two', |
|
716 | - 'path' => 'path-two', |
|
717 | - 'category' => 'test category', |
|
718 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
719 | - 'body' => 'body one', |
|
720 | - 'display' => 1, |
|
721 | - ], |
|
722 | - ]; |
|
723 | - |
|
724 | - array_walk($testData, [$this, 'insertPostData']); |
|
725 | - |
|
726 | - $repository = new MysqlPostRepository(self::$connection); |
|
727 | - $data = $repository->getActivePostsByCategory(reset($testData)['category']); |
|
728 | - |
|
729 | - $this->assertNotFalse($data); |
|
730 | - $this->assertInternalType('array', $data); |
|
731 | - $this->assertCount(count($testData), $data); |
|
732 | - |
|
733 | - usort($testData, function ($rowA, $rowB) { |
|
734 | - return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
735 | - }); |
|
736 | - |
|
737 | - foreach ($testData as $key => $testDataRow) { |
|
738 | - $this->assertArrayHasKey('id', $data[$key]); |
|
739 | - $this->assertEquals($testDataRow['id'], $data[$key]['id']); |
|
740 | - $this->assertArrayHasKey('title', $data[$key]); |
|
741 | - $this->assertEquals($testDataRow['title'], $data[$key]['title']); |
|
742 | - $this->assertArrayHasKey('path', $data[$key]); |
|
743 | - $this->assertEquals($testDataRow['path'], $data[$key]['path']); |
|
744 | - $this->assertArrayHasKey('date', $data[$key]); |
|
745 | - $this->assertEquals($testDataRow['date'], $data[$key]['date']); |
|
746 | - $this->assertArrayHasKey('body', $data[$key]); |
|
747 | - $this->assertEquals($testDataRow['body'], $data[$key]['body']); |
|
748 | - $this->assertArrayHasKey('category', $data[$key]); |
|
749 | - $this->assertEquals($testDataRow['category'], $data[$key]['category']); |
|
750 | - } |
|
751 | - } |
|
752 | - |
|
753 | - public function testGetActivePostsByCategoryInactive() |
|
754 | - { |
|
755 | - $testData = [ |
|
756 | - [ |
|
757 | - 'id' => rand(1, 100), |
|
758 | - 'category' => 'test category', |
|
759 | - 'display' => 1, |
|
760 | - ], |
|
761 | - [ |
|
762 | - 'id' => rand(101, 200), |
|
763 | - 'category' => 'test category', |
|
764 | - 'display' => 1, |
|
765 | - ], |
|
766 | - [ |
|
767 | - 'id' => rand(201, 300), |
|
768 | - 'category' => 'test category', |
|
769 | - 'display' => 0, |
|
770 | - ], |
|
771 | - ]; |
|
772 | - |
|
773 | - array_walk($testData, [$this, 'insertPostData']); |
|
774 | - |
|
775 | - $repository = new MysqlPostRepository(self::$connection); |
|
776 | - $data = $repository->getActivePostsByCategory(reset($testData)['category']); |
|
777 | - |
|
778 | - $this->assertNotFalse($data); |
|
779 | - $this->assertInternalType('array', $data); |
|
780 | - |
|
781 | - $testData = array_filter($testData, function ($row) { |
|
782 | - return ($row['display'] == 1); |
|
783 | - }); |
|
784 | - |
|
785 | - $this->assertCount(count($testData), $data); |
|
786 | - |
|
787 | - $testIds = array_column($testData, 'ids'); |
|
788 | - $dataIds = array_column($data, 'ids'); |
|
789 | - |
|
790 | - $this->assertEmpty(array_merge( |
|
791 | - array_diff($testIds, $dataIds), |
|
792 | - array_diff($dataIds, $testIds) |
|
793 | - )); |
|
794 | - } |
|
701 | + public function testGetActivePostsByCategory() |
|
702 | + { |
|
703 | + $testData = [ |
|
704 | + [ |
|
705 | + 'id' => rand(1, 100), |
|
706 | + 'title' => 'title one', |
|
707 | + 'path' => 'path-one', |
|
708 | + 'category' => 'test category', |
|
709 | + 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
710 | + 'body' => 'body one', |
|
711 | + 'display' => 1, |
|
712 | + ], |
|
713 | + [ |
|
714 | + 'id' => rand(101, 200), |
|
715 | + 'title' => 'title two', |
|
716 | + 'path' => 'path-two', |
|
717 | + 'category' => 'test category', |
|
718 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
719 | + 'body' => 'body one', |
|
720 | + 'display' => 1, |
|
721 | + ], |
|
722 | + ]; |
|
723 | + |
|
724 | + array_walk($testData, [$this, 'insertPostData']); |
|
725 | + |
|
726 | + $repository = new MysqlPostRepository(self::$connection); |
|
727 | + $data = $repository->getActivePostsByCategory(reset($testData)['category']); |
|
728 | + |
|
729 | + $this->assertNotFalse($data); |
|
730 | + $this->assertInternalType('array', $data); |
|
731 | + $this->assertCount(count($testData), $data); |
|
732 | + |
|
733 | + usort($testData, function ($rowA, $rowB) { |
|
734 | + return ((new DateTime($rowA['date'])) < (new DateTime($rowB['date']))); |
|
735 | + }); |
|
736 | + |
|
737 | + foreach ($testData as $key => $testDataRow) { |
|
738 | + $this->assertArrayHasKey('id', $data[$key]); |
|
739 | + $this->assertEquals($testDataRow['id'], $data[$key]['id']); |
|
740 | + $this->assertArrayHasKey('title', $data[$key]); |
|
741 | + $this->assertEquals($testDataRow['title'], $data[$key]['title']); |
|
742 | + $this->assertArrayHasKey('path', $data[$key]); |
|
743 | + $this->assertEquals($testDataRow['path'], $data[$key]['path']); |
|
744 | + $this->assertArrayHasKey('date', $data[$key]); |
|
745 | + $this->assertEquals($testDataRow['date'], $data[$key]['date']); |
|
746 | + $this->assertArrayHasKey('body', $data[$key]); |
|
747 | + $this->assertEquals($testDataRow['body'], $data[$key]['body']); |
|
748 | + $this->assertArrayHasKey('category', $data[$key]); |
|
749 | + $this->assertEquals($testDataRow['category'], $data[$key]['category']); |
|
750 | + } |
|
751 | + } |
|
752 | + |
|
753 | + public function testGetActivePostsByCategoryInactive() |
|
754 | + { |
|
755 | + $testData = [ |
|
756 | + [ |
|
757 | + 'id' => rand(1, 100), |
|
758 | + 'category' => 'test category', |
|
759 | + 'display' => 1, |
|
760 | + ], |
|
761 | + [ |
|
762 | + 'id' => rand(101, 200), |
|
763 | + 'category' => 'test category', |
|
764 | + 'display' => 1, |
|
765 | + ], |
|
766 | + [ |
|
767 | + 'id' => rand(201, 300), |
|
768 | + 'category' => 'test category', |
|
769 | + 'display' => 0, |
|
770 | + ], |
|
771 | + ]; |
|
772 | + |
|
773 | + array_walk($testData, [$this, 'insertPostData']); |
|
774 | + |
|
775 | + $repository = new MysqlPostRepository(self::$connection); |
|
776 | + $data = $repository->getActivePostsByCategory(reset($testData)['category']); |
|
777 | + |
|
778 | + $this->assertNotFalse($data); |
|
779 | + $this->assertInternalType('array', $data); |
|
780 | + |
|
781 | + $testData = array_filter($testData, function ($row) { |
|
782 | + return ($row['display'] == 1); |
|
783 | + }); |
|
784 | + |
|
785 | + $this->assertCount(count($testData), $data); |
|
786 | + |
|
787 | + $testIds = array_column($testData, 'ids'); |
|
788 | + $dataIds = array_column($data, 'ids'); |
|
789 | + |
|
790 | + $this->assertEmpty(array_merge( |
|
791 | + array_diff($testIds, $dataIds), |
|
792 | + array_diff($dataIds, $testIds) |
|
793 | + )); |
|
794 | + } |
|
795 | 795 | |
796 | - public function testGetActivePostsByCategoryFailure() |
|
797 | - { |
|
798 | - $repository = new MysqlPostRepository(self::$connection); |
|
799 | - $data = $repository->getActivePostsByCategory(''); |
|
800 | - |
|
801 | - $this->assertEmpty($data); |
|
802 | - $this->assertInternalType('array', $data); |
|
803 | - } |
|
804 | - |
|
805 | - public function testGetActivePostsByCategoryRange() |
|
806 | - { |
|
807 | - $testData = [ |
|
808 | - [ |
|
809 | - 'id' => rand(1, 100), |
|
810 | - 'category' => 'test category', |
|
811 | - 'display' => 1, |
|
812 | - ], |
|
813 | - [ |
|
814 | - 'id' => rand(101, 200), |
|
815 | - 'category' => 'test category', |
|
816 | - 'display' => 1, |
|
817 | - ], |
|
818 | - [ |
|
819 | - 'id' => rand(201, 300), |
|
820 | - 'category' => 'test category', |
|
821 | - 'display' => 1, |
|
822 | - ], |
|
823 | - ]; |
|
824 | - |
|
825 | - array_walk($testData, [$this, 'insertPostData']); |
|
826 | - |
|
827 | - $repository = new MysqlPostRepository(self::$connection); |
|
828 | - $data = $repository->getActivePostsByCategory(reset($testData)['category'], 2, 1); |
|
829 | - |
|
830 | - $this->assertNotFalse($data); |
|
831 | - $this->assertInternalType('array', $data); |
|
832 | - |
|
833 | - $testData = array_slice($testData, 1, 2); |
|
834 | - |
|
835 | - $this->assertCount(count($testData), $data); |
|
836 | - |
|
837 | - $testIds = array_column($testData, 'ids'); |
|
838 | - $dataIds = array_column($data, 'ids'); |
|
839 | - |
|
840 | - $this->assertEmpty(array_merge( |
|
841 | - array_diff($testIds, $dataIds), |
|
842 | - array_diff($dataIds, $testIds) |
|
843 | - )); |
|
844 | - } |
|
845 | - |
|
846 | - public function testGetActivePostsByCategoryRangeFailure() |
|
847 | - { |
|
848 | - $testData = [ |
|
849 | - [ |
|
850 | - 'id' => rand(1, 100), |
|
851 | - 'category' => 'test category', |
|
852 | - 'display' => 1, |
|
853 | - ], |
|
854 | - [ |
|
855 | - 'id' => rand(101, 200), |
|
856 | - 'category' => 'test category', |
|
857 | - 'display' => 1, |
|
858 | - ], |
|
859 | - [ |
|
860 | - 'id' => rand(201, 300), |
|
861 | - 'category' => 'test category', |
|
862 | - 'display' => 1, |
|
863 | - ], |
|
864 | - ]; |
|
865 | - |
|
866 | - array_walk($testData, [$this, 'insertPostData']); |
|
867 | - |
|
868 | - $repository = new MysqlPostRepository(self::$connection); |
|
869 | - $data = $repository->getActivePostsByCategory(reset($testData)['category'], 1, 3); |
|
870 | - |
|
871 | - $this->assertEmpty($data); |
|
872 | - $this->assertInternalType('array', $data); |
|
873 | - } |
|
874 | - |
|
875 | - public function testGetActivePostsCountByCategory() |
|
876 | - { |
|
877 | - $testData = [ |
|
878 | - [ |
|
879 | - 'id' => rand(1, 100), |
|
880 | - 'category' => 'test category', |
|
881 | - 'display' => 1, |
|
882 | - ], |
|
883 | - [ |
|
884 | - 'id' => rand(101, 200), |
|
885 | - 'category' => 'test category', |
|
886 | - 'display' => 1, |
|
887 | - ], |
|
888 | - [ |
|
889 | - 'id' => rand(201, 300), |
|
890 | - 'category' => 'test category', |
|
891 | - 'display' => 1, |
|
892 | - ], |
|
893 | - ]; |
|
894 | - |
|
895 | - array_walk($testData, [$this, 'insertPostData']); |
|
896 | - |
|
897 | - $repository = new MysqlPostRepository(self::$connection); |
|
898 | - $data = $repository->getActivePostsCountByCategory(reset($testData)['category']); |
|
899 | - |
|
900 | - $this->assertNotFalse($data); |
|
901 | - $this->assertStringMatchesFormat('%d', $data); |
|
902 | - $this->assertEquals(count($testData), $data); |
|
903 | - } |
|
904 | - |
|
905 | - public function testGetActivePostsCountByCategoryInactive() |
|
906 | - { |
|
907 | - $testData = [ |
|
908 | - [ |
|
909 | - 'id' => rand(1, 100), |
|
910 | - 'category' => 'test category', |
|
911 | - 'display' => 0, |
|
912 | - ], |
|
913 | - [ |
|
914 | - 'id' => rand(101, 200), |
|
915 | - 'category' => 'test category', |
|
916 | - 'display' => 1, |
|
917 | - ], |
|
918 | - [ |
|
919 | - 'id' => rand(201, 300), |
|
920 | - 'category' => 'test category', |
|
921 | - 'display' => 1, |
|
922 | - ], |
|
923 | - ]; |
|
924 | - |
|
925 | - array_walk($testData, [$this, 'insertPostData']); |
|
926 | - |
|
927 | - $repository = new MysqlPostRepository(self::$connection); |
|
928 | - $data = $repository->getActivePostsCountByCategory(reset($testData)['category']); |
|
929 | - |
|
930 | - $this->assertNotFalse($data); |
|
931 | - $this->assertStringMatchesFormat('%d', $data); |
|
932 | - |
|
933 | - $testData = array_filter($testData, function ($row) { |
|
934 | - return ($row['display'] == 1); |
|
935 | - }); |
|
936 | - |
|
937 | - $this->assertEquals(count($testData), $data); |
|
938 | - } |
|
939 | - |
|
940 | - public function testGetActivePostsCountByCategoryFailure() |
|
941 | - { |
|
942 | - $repository = new MysqlPostRepository(self::$connection); |
|
943 | - $data = $repository->getActivePostsCountByCategory(''); |
|
944 | - |
|
945 | - $this->assertNotFalse($data); |
|
946 | - $this->assertStringMatchesFormat('%d', $data); |
|
947 | - $this->assertEquals('0', $data); |
|
948 | - } |
|
949 | - |
|
950 | - public function testGetActivePostsByRelatedTags() |
|
951 | - { |
|
952 | - $testPostData = [ |
|
953 | - [ |
|
954 | - 'id' => rand(1, 100), |
|
955 | - 'title' => 'title one', |
|
956 | - 'path' => 'path-one', |
|
957 | - 'category' => 'test category', |
|
958 | - 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
959 | - 'body' => 'body one', |
|
960 | - 'display' => 1, |
|
961 | - ], |
|
962 | - [ |
|
963 | - 'id' => rand(101, 200), |
|
964 | - 'title' => 'title two', |
|
965 | - 'path' => 'path-two', |
|
966 | - 'category' => 'test category', |
|
967 | - 'date' => (new DateTime('-2 days'))->format('Y-m-d H:i:s'), |
|
968 | - 'body' => 'body two', |
|
969 | - 'display' => 1, |
|
970 | - ], |
|
971 | - [ |
|
972 | - 'id' => rand(201, 300), |
|
973 | - 'title' => 'title three', |
|
974 | - 'path' => 'path-three', |
|
975 | - 'category' => 'test category', |
|
976 | - 'date' => (new DateTime('-3 days'))->format('Y-m-d H:i:s'), |
|
977 | - 'body' => 'body three', |
|
978 | - 'display' => 1, |
|
979 | - ], |
|
980 | - ]; |
|
981 | - |
|
982 | - $testTagData = [ |
|
983 | - 'id' => rand(1, 100), |
|
984 | - ]; |
|
985 | - |
|
986 | - $testPTLinkData = []; |
|
987 | - foreach ($testPostData as $testPostRow) { |
|
988 | - array_push($testPTLinkData, [ |
|
989 | - 'post_id' => $testPostRow['id'], |
|
990 | - 'tag_id' => $testTagData['id'], |
|
991 | - ]); |
|
992 | - } |
|
993 | - |
|
994 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
995 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
996 | - $this->insertTagData($testTagData); |
|
997 | - |
|
998 | - $repository = new MysqlPostRepository(self::$connection); |
|
999 | - $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1000 | - |
|
1001 | - $this->assertNotFalse($data); |
|
1002 | - $this->assertInternalType('array', $data); |
|
1003 | - |
|
1004 | - array_shift($testPostData); |
|
1005 | - |
|
1006 | - $this->assertCount(count($testPostData), $data); |
|
1007 | - foreach ($testPostData as $key => $testPostRow) { |
|
1008 | - $this->assertArrayHasKey('id', $data[$key]); |
|
1009 | - $this->assertEquals($testPostRow['id'], $data[$key]['id']); |
|
1010 | - $this->assertArrayHasKey('title', $data[$key]); |
|
1011 | - $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
1012 | - $this->assertArrayHasKey('path', $data[$key]); |
|
1013 | - $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
1014 | - $this->assertArrayHasKey('date', $data[$key]); |
|
1015 | - $this->assertEquals($testPostRow['date'], $data[$key]['date']); |
|
1016 | - $this->assertArrayHasKey('body', $data[$key]); |
|
1017 | - $this->assertEquals($testPostRow['body'], $data[$key]['body']); |
|
1018 | - $this->assertArrayHasKey('category', $data[$key]); |
|
1019 | - $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
1020 | - $this->assertArrayHasKey('count', $data[$key]); |
|
1021 | - $this->assertEquals(count($testTagData), $data[$key]['count']); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - public function testGetActivePostsByRelatedTagsLimit() |
|
1026 | - { |
|
1027 | - $testPostData = [ |
|
1028 | - [ |
|
1029 | - 'id' => rand(1, 100), |
|
1030 | - 'display' => 1, |
|
1031 | - ], |
|
1032 | - [ |
|
1033 | - 'id' => rand(101, 200), |
|
1034 | - 'display' => 1, |
|
1035 | - ], |
|
1036 | - [ |
|
1037 | - 'id' => rand(201, 300), |
|
1038 | - 'display' => 1, |
|
1039 | - ], |
|
1040 | - ]; |
|
1041 | - |
|
1042 | - $testTagData = [ |
|
1043 | - 'id' => rand(1, 100), |
|
1044 | - ]; |
|
1045 | - |
|
1046 | - $testPTLinkData = []; |
|
1047 | - foreach ($testPostData as $testPostRow) { |
|
1048 | - array_push($testPTLinkData, [ |
|
1049 | - 'post_id' => $testPostRow['id'], |
|
1050 | - 'tag_id' => $testTagData['id'], |
|
1051 | - ]); |
|
1052 | - } |
|
1053 | - |
|
1054 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
1055 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1056 | - $this->insertTagData($testTagData); |
|
1057 | - |
|
1058 | - $repository = new MysqlPostRepository(self::$connection); |
|
1059 | - $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id'], 1); |
|
1060 | - |
|
1061 | - $this->assertNotFalse($data); |
|
1062 | - $this->assertInternalType('array', $data); |
|
1063 | - |
|
1064 | - $testPostData = array_slice($testPostData, 1, 1); |
|
1065 | - |
|
1066 | - $this->assertCount(count($testPostData), $data); |
|
1067 | - |
|
1068 | - $testIds = array_column($testPostData, 'ids'); |
|
1069 | - $dataIds = array_column($data, 'ids'); |
|
1070 | - |
|
1071 | - $this->assertEmpty(array_merge( |
|
1072 | - array_diff($testIds, $dataIds), |
|
1073 | - array_diff($dataIds, $testIds) |
|
1074 | - )); |
|
1075 | - } |
|
796 | + public function testGetActivePostsByCategoryFailure() |
|
797 | + { |
|
798 | + $repository = new MysqlPostRepository(self::$connection); |
|
799 | + $data = $repository->getActivePostsByCategory(''); |
|
800 | + |
|
801 | + $this->assertEmpty($data); |
|
802 | + $this->assertInternalType('array', $data); |
|
803 | + } |
|
804 | + |
|
805 | + public function testGetActivePostsByCategoryRange() |
|
806 | + { |
|
807 | + $testData = [ |
|
808 | + [ |
|
809 | + 'id' => rand(1, 100), |
|
810 | + 'category' => 'test category', |
|
811 | + 'display' => 1, |
|
812 | + ], |
|
813 | + [ |
|
814 | + 'id' => rand(101, 200), |
|
815 | + 'category' => 'test category', |
|
816 | + 'display' => 1, |
|
817 | + ], |
|
818 | + [ |
|
819 | + 'id' => rand(201, 300), |
|
820 | + 'category' => 'test category', |
|
821 | + 'display' => 1, |
|
822 | + ], |
|
823 | + ]; |
|
824 | + |
|
825 | + array_walk($testData, [$this, 'insertPostData']); |
|
826 | + |
|
827 | + $repository = new MysqlPostRepository(self::$connection); |
|
828 | + $data = $repository->getActivePostsByCategory(reset($testData)['category'], 2, 1); |
|
829 | + |
|
830 | + $this->assertNotFalse($data); |
|
831 | + $this->assertInternalType('array', $data); |
|
832 | + |
|
833 | + $testData = array_slice($testData, 1, 2); |
|
834 | + |
|
835 | + $this->assertCount(count($testData), $data); |
|
836 | + |
|
837 | + $testIds = array_column($testData, 'ids'); |
|
838 | + $dataIds = array_column($data, 'ids'); |
|
839 | + |
|
840 | + $this->assertEmpty(array_merge( |
|
841 | + array_diff($testIds, $dataIds), |
|
842 | + array_diff($dataIds, $testIds) |
|
843 | + )); |
|
844 | + } |
|
845 | + |
|
846 | + public function testGetActivePostsByCategoryRangeFailure() |
|
847 | + { |
|
848 | + $testData = [ |
|
849 | + [ |
|
850 | + 'id' => rand(1, 100), |
|
851 | + 'category' => 'test category', |
|
852 | + 'display' => 1, |
|
853 | + ], |
|
854 | + [ |
|
855 | + 'id' => rand(101, 200), |
|
856 | + 'category' => 'test category', |
|
857 | + 'display' => 1, |
|
858 | + ], |
|
859 | + [ |
|
860 | + 'id' => rand(201, 300), |
|
861 | + 'category' => 'test category', |
|
862 | + 'display' => 1, |
|
863 | + ], |
|
864 | + ]; |
|
865 | + |
|
866 | + array_walk($testData, [$this, 'insertPostData']); |
|
867 | + |
|
868 | + $repository = new MysqlPostRepository(self::$connection); |
|
869 | + $data = $repository->getActivePostsByCategory(reset($testData)['category'], 1, 3); |
|
870 | + |
|
871 | + $this->assertEmpty($data); |
|
872 | + $this->assertInternalType('array', $data); |
|
873 | + } |
|
874 | + |
|
875 | + public function testGetActivePostsCountByCategory() |
|
876 | + { |
|
877 | + $testData = [ |
|
878 | + [ |
|
879 | + 'id' => rand(1, 100), |
|
880 | + 'category' => 'test category', |
|
881 | + 'display' => 1, |
|
882 | + ], |
|
883 | + [ |
|
884 | + 'id' => rand(101, 200), |
|
885 | + 'category' => 'test category', |
|
886 | + 'display' => 1, |
|
887 | + ], |
|
888 | + [ |
|
889 | + 'id' => rand(201, 300), |
|
890 | + 'category' => 'test category', |
|
891 | + 'display' => 1, |
|
892 | + ], |
|
893 | + ]; |
|
894 | + |
|
895 | + array_walk($testData, [$this, 'insertPostData']); |
|
896 | + |
|
897 | + $repository = new MysqlPostRepository(self::$connection); |
|
898 | + $data = $repository->getActivePostsCountByCategory(reset($testData)['category']); |
|
899 | + |
|
900 | + $this->assertNotFalse($data); |
|
901 | + $this->assertStringMatchesFormat('%d', $data); |
|
902 | + $this->assertEquals(count($testData), $data); |
|
903 | + } |
|
904 | + |
|
905 | + public function testGetActivePostsCountByCategoryInactive() |
|
906 | + { |
|
907 | + $testData = [ |
|
908 | + [ |
|
909 | + 'id' => rand(1, 100), |
|
910 | + 'category' => 'test category', |
|
911 | + 'display' => 0, |
|
912 | + ], |
|
913 | + [ |
|
914 | + 'id' => rand(101, 200), |
|
915 | + 'category' => 'test category', |
|
916 | + 'display' => 1, |
|
917 | + ], |
|
918 | + [ |
|
919 | + 'id' => rand(201, 300), |
|
920 | + 'category' => 'test category', |
|
921 | + 'display' => 1, |
|
922 | + ], |
|
923 | + ]; |
|
924 | + |
|
925 | + array_walk($testData, [$this, 'insertPostData']); |
|
926 | + |
|
927 | + $repository = new MysqlPostRepository(self::$connection); |
|
928 | + $data = $repository->getActivePostsCountByCategory(reset($testData)['category']); |
|
929 | + |
|
930 | + $this->assertNotFalse($data); |
|
931 | + $this->assertStringMatchesFormat('%d', $data); |
|
932 | + |
|
933 | + $testData = array_filter($testData, function ($row) { |
|
934 | + return ($row['display'] == 1); |
|
935 | + }); |
|
936 | + |
|
937 | + $this->assertEquals(count($testData), $data); |
|
938 | + } |
|
939 | + |
|
940 | + public function testGetActivePostsCountByCategoryFailure() |
|
941 | + { |
|
942 | + $repository = new MysqlPostRepository(self::$connection); |
|
943 | + $data = $repository->getActivePostsCountByCategory(''); |
|
944 | + |
|
945 | + $this->assertNotFalse($data); |
|
946 | + $this->assertStringMatchesFormat('%d', $data); |
|
947 | + $this->assertEquals('0', $data); |
|
948 | + } |
|
949 | + |
|
950 | + public function testGetActivePostsByRelatedTags() |
|
951 | + { |
|
952 | + $testPostData = [ |
|
953 | + [ |
|
954 | + 'id' => rand(1, 100), |
|
955 | + 'title' => 'title one', |
|
956 | + 'path' => 'path-one', |
|
957 | + 'category' => 'test category', |
|
958 | + 'date' => (new DateTime('-1 day'))->format('Y-m-d H:i:s'), |
|
959 | + 'body' => 'body one', |
|
960 | + 'display' => 1, |
|
961 | + ], |
|
962 | + [ |
|
963 | + 'id' => rand(101, 200), |
|
964 | + 'title' => 'title two', |
|
965 | + 'path' => 'path-two', |
|
966 | + 'category' => 'test category', |
|
967 | + 'date' => (new DateTime('-2 days'))->format('Y-m-d H:i:s'), |
|
968 | + 'body' => 'body two', |
|
969 | + 'display' => 1, |
|
970 | + ], |
|
971 | + [ |
|
972 | + 'id' => rand(201, 300), |
|
973 | + 'title' => 'title three', |
|
974 | + 'path' => 'path-three', |
|
975 | + 'category' => 'test category', |
|
976 | + 'date' => (new DateTime('-3 days'))->format('Y-m-d H:i:s'), |
|
977 | + 'body' => 'body three', |
|
978 | + 'display' => 1, |
|
979 | + ], |
|
980 | + ]; |
|
981 | + |
|
982 | + $testTagData = [ |
|
983 | + 'id' => rand(1, 100), |
|
984 | + ]; |
|
985 | + |
|
986 | + $testPTLinkData = []; |
|
987 | + foreach ($testPostData as $testPostRow) { |
|
988 | + array_push($testPTLinkData, [ |
|
989 | + 'post_id' => $testPostRow['id'], |
|
990 | + 'tag_id' => $testTagData['id'], |
|
991 | + ]); |
|
992 | + } |
|
993 | + |
|
994 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
995 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
996 | + $this->insertTagData($testTagData); |
|
997 | + |
|
998 | + $repository = new MysqlPostRepository(self::$connection); |
|
999 | + $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1000 | + |
|
1001 | + $this->assertNotFalse($data); |
|
1002 | + $this->assertInternalType('array', $data); |
|
1003 | + |
|
1004 | + array_shift($testPostData); |
|
1005 | + |
|
1006 | + $this->assertCount(count($testPostData), $data); |
|
1007 | + foreach ($testPostData as $key => $testPostRow) { |
|
1008 | + $this->assertArrayHasKey('id', $data[$key]); |
|
1009 | + $this->assertEquals($testPostRow['id'], $data[$key]['id']); |
|
1010 | + $this->assertArrayHasKey('title', $data[$key]); |
|
1011 | + $this->assertEquals($testPostRow['title'], $data[$key]['title']); |
|
1012 | + $this->assertArrayHasKey('path', $data[$key]); |
|
1013 | + $this->assertEquals($testPostRow['path'], $data[$key]['path']); |
|
1014 | + $this->assertArrayHasKey('date', $data[$key]); |
|
1015 | + $this->assertEquals($testPostRow['date'], $data[$key]['date']); |
|
1016 | + $this->assertArrayHasKey('body', $data[$key]); |
|
1017 | + $this->assertEquals($testPostRow['body'], $data[$key]['body']); |
|
1018 | + $this->assertArrayHasKey('category', $data[$key]); |
|
1019 | + $this->assertEquals($testPostRow['category'], $data[$key]['category']); |
|
1020 | + $this->assertArrayHasKey('count', $data[$key]); |
|
1021 | + $this->assertEquals(count($testTagData), $data[$key]['count']); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + public function testGetActivePostsByRelatedTagsLimit() |
|
1026 | + { |
|
1027 | + $testPostData = [ |
|
1028 | + [ |
|
1029 | + 'id' => rand(1, 100), |
|
1030 | + 'display' => 1, |
|
1031 | + ], |
|
1032 | + [ |
|
1033 | + 'id' => rand(101, 200), |
|
1034 | + 'display' => 1, |
|
1035 | + ], |
|
1036 | + [ |
|
1037 | + 'id' => rand(201, 300), |
|
1038 | + 'display' => 1, |
|
1039 | + ], |
|
1040 | + ]; |
|
1041 | + |
|
1042 | + $testTagData = [ |
|
1043 | + 'id' => rand(1, 100), |
|
1044 | + ]; |
|
1045 | + |
|
1046 | + $testPTLinkData = []; |
|
1047 | + foreach ($testPostData as $testPostRow) { |
|
1048 | + array_push($testPTLinkData, [ |
|
1049 | + 'post_id' => $testPostRow['id'], |
|
1050 | + 'tag_id' => $testTagData['id'], |
|
1051 | + ]); |
|
1052 | + } |
|
1053 | + |
|
1054 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
1055 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1056 | + $this->insertTagData($testTagData); |
|
1057 | + |
|
1058 | + $repository = new MysqlPostRepository(self::$connection); |
|
1059 | + $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id'], 1); |
|
1060 | + |
|
1061 | + $this->assertNotFalse($data); |
|
1062 | + $this->assertInternalType('array', $data); |
|
1063 | + |
|
1064 | + $testPostData = array_slice($testPostData, 1, 1); |
|
1065 | + |
|
1066 | + $this->assertCount(count($testPostData), $data); |
|
1067 | + |
|
1068 | + $testIds = array_column($testPostData, 'ids'); |
|
1069 | + $dataIds = array_column($data, 'ids'); |
|
1070 | + |
|
1071 | + $this->assertEmpty(array_merge( |
|
1072 | + array_diff($testIds, $dataIds), |
|
1073 | + array_diff($dataIds, $testIds) |
|
1074 | + )); |
|
1075 | + } |
|
1076 | 1076 | |
1077 | - public function testGetActivePostsByRelatedTagsInactive() |
|
1078 | - { |
|
1079 | - $testPostData = [ |
|
1080 | - [ |
|
1081 | - 'id' => rand(1, 100), |
|
1082 | - 'display' => 1, |
|
1083 | - ], |
|
1084 | - [ |
|
1085 | - 'id' => rand(101, 200), |
|
1086 | - 'display' => 1, |
|
1087 | - ], |
|
1088 | - [ |
|
1089 | - 'id' => rand(201, 300), |
|
1090 | - 'display' => 0, |
|
1091 | - ], |
|
1092 | - [ |
|
1093 | - 'id' => rand(301, 400), |
|
1094 | - 'display' => 1, |
|
1095 | - ], |
|
1096 | - ]; |
|
1097 | - |
|
1098 | - $testTagData = [ |
|
1099 | - 'id' => rand(1, 100), |
|
1100 | - ]; |
|
1101 | - |
|
1102 | - $testPTLinkData = []; |
|
1103 | - foreach ($testPostData as $testPostRow) { |
|
1104 | - array_push($testPTLinkData, [ |
|
1105 | - 'post_id' => $testPostRow['id'], |
|
1106 | - 'tag_id' => $testTagData['id'], |
|
1107 | - ]); |
|
1108 | - } |
|
1109 | - |
|
1110 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
1111 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1112 | - $this->insertTagData($testTagData); |
|
1113 | - |
|
1114 | - $repository = new MysqlPostRepository(self::$connection); |
|
1115 | - $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1116 | - |
|
1117 | - $this->assertNotFalse($data); |
|
1118 | - $this->assertInternalType('array', $data); |
|
1119 | - |
|
1120 | - array_shift($testPostData); |
|
1121 | - $testPostData = array_filter($testPostData, function ($row) { |
|
1122 | - return ($row['display'] == 1); |
|
1123 | - }); |
|
1124 | - |
|
1125 | - $this->assertCount(count($testPostData), $data); |
|
1126 | - |
|
1127 | - $testIds = array_column($testPostData, 'ids'); |
|
1128 | - $dataIds = array_column($data, 'ids'); |
|
1129 | - |
|
1130 | - $this->assertEmpty(array_merge( |
|
1131 | - array_diff($testIds, $dataIds), |
|
1132 | - array_diff($dataIds, $testIds) |
|
1133 | - )); |
|
1134 | - } |
|
1077 | + public function testGetActivePostsByRelatedTagsInactive() |
|
1078 | + { |
|
1079 | + $testPostData = [ |
|
1080 | + [ |
|
1081 | + 'id' => rand(1, 100), |
|
1082 | + 'display' => 1, |
|
1083 | + ], |
|
1084 | + [ |
|
1085 | + 'id' => rand(101, 200), |
|
1086 | + 'display' => 1, |
|
1087 | + ], |
|
1088 | + [ |
|
1089 | + 'id' => rand(201, 300), |
|
1090 | + 'display' => 0, |
|
1091 | + ], |
|
1092 | + [ |
|
1093 | + 'id' => rand(301, 400), |
|
1094 | + 'display' => 1, |
|
1095 | + ], |
|
1096 | + ]; |
|
1097 | + |
|
1098 | + $testTagData = [ |
|
1099 | + 'id' => rand(1, 100), |
|
1100 | + ]; |
|
1101 | + |
|
1102 | + $testPTLinkData = []; |
|
1103 | + foreach ($testPostData as $testPostRow) { |
|
1104 | + array_push($testPTLinkData, [ |
|
1105 | + 'post_id' => $testPostRow['id'], |
|
1106 | + 'tag_id' => $testTagData['id'], |
|
1107 | + ]); |
|
1108 | + } |
|
1109 | + |
|
1110 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
1111 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1112 | + $this->insertTagData($testTagData); |
|
1113 | + |
|
1114 | + $repository = new MysqlPostRepository(self::$connection); |
|
1115 | + $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1116 | + |
|
1117 | + $this->assertNotFalse($data); |
|
1118 | + $this->assertInternalType('array', $data); |
|
1119 | + |
|
1120 | + array_shift($testPostData); |
|
1121 | + $testPostData = array_filter($testPostData, function ($row) { |
|
1122 | + return ($row['display'] == 1); |
|
1123 | + }); |
|
1124 | + |
|
1125 | + $this->assertCount(count($testPostData), $data); |
|
1126 | + |
|
1127 | + $testIds = array_column($testPostData, 'ids'); |
|
1128 | + $dataIds = array_column($data, 'ids'); |
|
1129 | + |
|
1130 | + $this->assertEmpty(array_merge( |
|
1131 | + array_diff($testIds, $dataIds), |
|
1132 | + array_diff($dataIds, $testIds) |
|
1133 | + )); |
|
1134 | + } |
|
1135 | 1135 | |
1136 | - public function testGetActivePostsByRelatedTagsExcludeSeries() |
|
1137 | - { |
|
1138 | - $testPostData = [ |
|
1139 | - [ |
|
1140 | - 'id' => rand(1, 100), |
|
1141 | - 'display' => 1, |
|
1142 | - ], |
|
1143 | - [ |
|
1144 | - 'id' => rand(101, 200), |
|
1145 | - 'display' => 1, |
|
1146 | - ], |
|
1147 | - [ |
|
1148 | - 'id' => rand(201, 300), |
|
1149 | - 'display' => 1, |
|
1150 | - ], |
|
1151 | - [ |
|
1152 | - 'id' => rand(301, 400), |
|
1153 | - 'display' => 1, |
|
1154 | - ], |
|
1155 | - ]; |
|
1156 | - |
|
1157 | - $testTagData = [ |
|
1158 | - 'id' => rand(1, 100), |
|
1159 | - ]; |
|
1160 | - |
|
1161 | - $testPTLinkData = []; |
|
1162 | - foreach ($testPostData as $testPostRow) { |
|
1163 | - array_push($testPTLinkData, [ |
|
1164 | - 'post_id' => $testPostRow['id'], |
|
1165 | - 'tag_id' => $testTagData['id'], |
|
1166 | - ]); |
|
1167 | - } |
|
1168 | - |
|
1169 | - $seriesPostKey = rand(1, 3); |
|
1170 | - $testSeriesPostData = [ |
|
1171 | - [ |
|
1172 | - 'series' => 1, |
|
1173 | - 'post' => reset($testPostData)['id'], |
|
1174 | - ], |
|
1175 | - [ |
|
1176 | - 'series' => 1, |
|
1177 | - 'post' => $testPostData[$seriesPostKey]['id'], |
|
1178 | - ], |
|
1179 | - ]; |
|
1180 | - |
|
1181 | - array_walk($testPostData, [$this, 'insertPostData']); |
|
1182 | - array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1183 | - array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']); |
|
1184 | - $this->insertTagData($testTagData); |
|
1185 | - |
|
1186 | - $repository = new MysqlPostRepository(self::$connection); |
|
1187 | - $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1188 | - |
|
1189 | - $this->assertNotFalse($data); |
|
1190 | - $this->assertInternalType('array', $data); |
|
1191 | - |
|
1192 | - array_shift($testPostData); |
|
1193 | - $testPostData = array_filter($testPostData, function ($row) use ($testSeriesPostData) { |
|
1194 | - return (!in_array($row['id'], array_column($testSeriesPostData, 'post'))); |
|
1195 | - }); |
|
1196 | - |
|
1197 | - $this->assertCount(count($testPostData), $data); |
|
1198 | - |
|
1199 | - $testIds = array_column($testPostData, 'ids'); |
|
1200 | - $dataIds = array_column($data, 'ids'); |
|
1201 | - |
|
1202 | - $this->assertEmpty(array_merge( |
|
1203 | - array_diff($testIds, $dataIds), |
|
1204 | - array_diff($dataIds, $testIds) |
|
1205 | - )); |
|
1206 | - } |
|
1207 | - |
|
1208 | - public function testGetActivePostsByRelatedTagsFailure() |
|
1209 | - { |
|
1210 | - $repository = new MysqlPostRepository(self::$connection); |
|
1211 | - $data = $repository->getActivePostsByRelatedTags(''); |
|
1212 | - |
|
1213 | - $this->assertEmpty($data); |
|
1214 | - $this->assertInternalType('array', $data); |
|
1215 | - } |
|
1216 | - |
|
1217 | - protected function insertPostData(array $data) |
|
1218 | - { |
|
1219 | - $defaultData = [ |
|
1220 | - 'id' => null, |
|
1221 | - 'title' => '', |
|
1222 | - 'path' => '', |
|
1223 | - 'category' => '', |
|
1224 | - 'date' => '', |
|
1225 | - 'body' => '', |
|
1226 | - 'display' => 0, |
|
1227 | - ]; |
|
1228 | - |
|
1229 | - $data = array_merge($defaultData, $data); |
|
1230 | - |
|
1231 | - return self::$connection->getDefault()->perform(" |
|
1136 | + public function testGetActivePostsByRelatedTagsExcludeSeries() |
|
1137 | + { |
|
1138 | + $testPostData = [ |
|
1139 | + [ |
|
1140 | + 'id' => rand(1, 100), |
|
1141 | + 'display' => 1, |
|
1142 | + ], |
|
1143 | + [ |
|
1144 | + 'id' => rand(101, 200), |
|
1145 | + 'display' => 1, |
|
1146 | + ], |
|
1147 | + [ |
|
1148 | + 'id' => rand(201, 300), |
|
1149 | + 'display' => 1, |
|
1150 | + ], |
|
1151 | + [ |
|
1152 | + 'id' => rand(301, 400), |
|
1153 | + 'display' => 1, |
|
1154 | + ], |
|
1155 | + ]; |
|
1156 | + |
|
1157 | + $testTagData = [ |
|
1158 | + 'id' => rand(1, 100), |
|
1159 | + ]; |
|
1160 | + |
|
1161 | + $testPTLinkData = []; |
|
1162 | + foreach ($testPostData as $testPostRow) { |
|
1163 | + array_push($testPTLinkData, [ |
|
1164 | + 'post_id' => $testPostRow['id'], |
|
1165 | + 'tag_id' => $testTagData['id'], |
|
1166 | + ]); |
|
1167 | + } |
|
1168 | + |
|
1169 | + $seriesPostKey = rand(1, 3); |
|
1170 | + $testSeriesPostData = [ |
|
1171 | + [ |
|
1172 | + 'series' => 1, |
|
1173 | + 'post' => reset($testPostData)['id'], |
|
1174 | + ], |
|
1175 | + [ |
|
1176 | + 'series' => 1, |
|
1177 | + 'post' => $testPostData[$seriesPostKey]['id'], |
|
1178 | + ], |
|
1179 | + ]; |
|
1180 | + |
|
1181 | + array_walk($testPostData, [$this, 'insertPostData']); |
|
1182 | + array_walk($testPTLinkData, [$this, 'insertPTLinkData']); |
|
1183 | + array_walk($testSeriesPostData, [$this, 'insertSeriesPostData']); |
|
1184 | + $this->insertTagData($testTagData); |
|
1185 | + |
|
1186 | + $repository = new MysqlPostRepository(self::$connection); |
|
1187 | + $data = $repository->getActivePostsByRelatedTags(reset($testPostData)['id']); |
|
1188 | + |
|
1189 | + $this->assertNotFalse($data); |
|
1190 | + $this->assertInternalType('array', $data); |
|
1191 | + |
|
1192 | + array_shift($testPostData); |
|
1193 | + $testPostData = array_filter($testPostData, function ($row) use ($testSeriesPostData) { |
|
1194 | + return (!in_array($row['id'], array_column($testSeriesPostData, 'post'))); |
|
1195 | + }); |
|
1196 | + |
|
1197 | + $this->assertCount(count($testPostData), $data); |
|
1198 | + |
|
1199 | + $testIds = array_column($testPostData, 'ids'); |
|
1200 | + $dataIds = array_column($data, 'ids'); |
|
1201 | + |
|
1202 | + $this->assertEmpty(array_merge( |
|
1203 | + array_diff($testIds, $dataIds), |
|
1204 | + array_diff($dataIds, $testIds) |
|
1205 | + )); |
|
1206 | + } |
|
1207 | + |
|
1208 | + public function testGetActivePostsByRelatedTagsFailure() |
|
1209 | + { |
|
1210 | + $repository = new MysqlPostRepository(self::$connection); |
|
1211 | + $data = $repository->getActivePostsByRelatedTags(''); |
|
1212 | + |
|
1213 | + $this->assertEmpty($data); |
|
1214 | + $this->assertInternalType('array', $data); |
|
1215 | + } |
|
1216 | + |
|
1217 | + protected function insertPostData(array $data) |
|
1218 | + { |
|
1219 | + $defaultData = [ |
|
1220 | + 'id' => null, |
|
1221 | + 'title' => '', |
|
1222 | + 'path' => '', |
|
1223 | + 'category' => '', |
|
1224 | + 'date' => '', |
|
1225 | + 'body' => '', |
|
1226 | + 'display' => 0, |
|
1227 | + ]; |
|
1228 | + |
|
1229 | + $data = array_merge($defaultData, $data); |
|
1230 | + |
|
1231 | + return self::$connection->getDefault()->perform(" |
|
1232 | 1232 | INSERT INTO `jpemeric_blog`.`post` |
1233 | 1233 | (id, title, path, category, date, body, display) |
1234 | 1234 | VALUES |
1235 | 1235 | (:id, :title, :path, :category, :date, :body, :display)", |
1236 | - $data |
|
1237 | - ); |
|
1238 | - } |
|
1236 | + $data |
|
1237 | + ); |
|
1238 | + } |
|
1239 | 1239 | |
1240 | - protected function insertPTLinkData(array $data) |
|
1241 | - { |
|
1242 | - $defaultData = [ |
|
1243 | - 'post' => null, |
|
1244 | - 'tag' => null, |
|
1245 | - ]; |
|
1240 | + protected function insertPTLinkData(array $data) |
|
1241 | + { |
|
1242 | + $defaultData = [ |
|
1243 | + 'post' => null, |
|
1244 | + 'tag' => null, |
|
1245 | + ]; |
|
1246 | 1246 | |
1247 | - $data = array_merge($defaultData, $data); |
|
1247 | + $data = array_merge($defaultData, $data); |
|
1248 | 1248 | |
1249 | - return self::$connection->getDefault()->perform(" |
|
1249 | + return self::$connection->getDefault()->perform(" |
|
1250 | 1250 | INSERT INTO `jpemeric_blog`.`ptlink` |
1251 | 1251 | (post_id, tag_id) |
1252 | 1252 | VALUES |
1253 | 1253 | (:post_id, :tag_id)", |
1254 | - $data |
|
1255 | - ); |
|
1256 | - } |
|
1254 | + $data |
|
1255 | + ); |
|
1256 | + } |
|
1257 | 1257 | |
1258 | - protected function insertSeriesPostData(array $data) |
|
1259 | - { |
|
1260 | - $defaultData = [ |
|
1261 | - 'series' => '', |
|
1262 | - 'post' => '', |
|
1263 | - 'order' => 0, |
|
1264 | - ]; |
|
1258 | + protected function insertSeriesPostData(array $data) |
|
1259 | + { |
|
1260 | + $defaultData = [ |
|
1261 | + 'series' => '', |
|
1262 | + 'post' => '', |
|
1263 | + 'order' => 0, |
|
1264 | + ]; |
|
1265 | 1265 | |
1266 | - $data = array_merge($defaultData, $data); |
|
1266 | + $data = array_merge($defaultData, $data); |
|
1267 | 1267 | |
1268 | - return self::$connection->getDefault()->perform(" |
|
1268 | + return self::$connection->getDefault()->perform(" |
|
1269 | 1269 | INSERT INTO `jpemeric_blog`.`series_post` |
1270 | 1270 | (series, post, `order`) |
1271 | 1271 | VALUES |
1272 | 1272 | (:series, :post, :order)", |
1273 | - $data |
|
1274 | - ); |
|
1275 | - } |
|
1273 | + $data |
|
1274 | + ); |
|
1275 | + } |
|
1276 | 1276 | |
1277 | - protected function insertTagData(array $data) |
|
1278 | - { |
|
1279 | - $defaultData = [ |
|
1280 | - 'id' => null, |
|
1281 | - 'tag' => '', |
|
1282 | - ]; |
|
1277 | + protected function insertTagData(array $data) |
|
1278 | + { |
|
1279 | + $defaultData = [ |
|
1280 | + 'id' => null, |
|
1281 | + 'tag' => '', |
|
1282 | + ]; |
|
1283 | 1283 | |
1284 | - $data = array_merge($defaultData, $data); |
|
1284 | + $data = array_merge($defaultData, $data); |
|
1285 | 1285 | |
1286 | - return self::$connection->getDefault()->perform(" |
|
1286 | + return self::$connection->getDefault()->perform(" |
|
1287 | 1287 | INSERT INTO `jpemeric_blog`.`tag` |
1288 | 1288 | (id, tag) |
1289 | 1289 | VALUES |
1290 | 1290 | (:id, :tag)", |
1291 | - $data |
|
1292 | - ); |
|
1293 | - } |
|
1294 | - |
|
1295 | - protected function tearDown() |
|
1296 | - { |
|
1297 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`"); |
|
1298 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`"); |
|
1299 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`"); |
|
1300 | - self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`"); |
|
1301 | - } |
|
1302 | - |
|
1303 | - public static function tearDownAfterClass() |
|
1304 | - { |
|
1305 | - self::$connection->getDefault()->disconnect(); |
|
1306 | - unlink('jpemeric_blog.db'); |
|
1307 | - } |
|
1291 | + $data |
|
1292 | + ); |
|
1293 | + } |
|
1294 | + |
|
1295 | + protected function tearDown() |
|
1296 | + { |
|
1297 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`post`"); |
|
1298 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`ptlink`"); |
|
1299 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`series_post`"); |
|
1300 | + self::$connection->getDefault()->perform("DELETE FROM `jpemeric_blog`.`tag`"); |
|
1301 | + } |
|
1302 | + |
|
1303 | + public static function tearDownAfterClass() |
|
1304 | + { |
|
1305 | + self::$connection->getDefault()->disconnect(); |
|
1306 | + unlink('jpemeric_blog.db'); |
|
1307 | + } |
|
1308 | 1308 | } |
@@ -5,56 +5,56 @@ |
||
5 | 5 | abstract class DefaultPageController extends PageController |
6 | 6 | { |
7 | 7 | |
8 | - public function __construct() |
|
9 | - { |
|
10 | - parent::__construct(); |
|
11 | - |
|
12 | - $this->add_css('reset'); |
|
13 | - $this->add_css('portfolio', 4); |
|
14 | - } |
|
15 | - |
|
16 | - protected function set_body_data() |
|
17 | - { |
|
18 | - $this->set_body('header_data', [ |
|
19 | - 'menu' => $this->get_menu(), |
|
20 | - 'home_link' => Loader::getRootURL(), |
|
21 | - ]); |
|
22 | - $this->set_body('activity_array', $this->get_recent_activity()); |
|
23 | - |
|
24 | - $this->set_body_view('Page'); |
|
25 | - } |
|
26 | - |
|
27 | - protected function get_menu() |
|
28 | - { |
|
29 | - $menu = [ |
|
30 | - [ |
|
31 | - 'name' => 'About', |
|
32 | - 'link' => Loader::getRootURL(), |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'name' => 'Projects', |
|
36 | - 'link' => Loader::getRootURL() . 'projects/', |
|
37 | - ], |
|
38 | - [ |
|
39 | - 'name' => 'Résumé', |
|
40 | - 'link' => Loader::getRootURL() . 'resume/', |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'Contact', |
|
44 | - 'link' => Loader::getRootURL() . 'contact/', |
|
45 | - ], |
|
46 | - ]; |
|
47 | - |
|
48 | - if (!URLDecode::getPiece(1)) { |
|
49 | - $active_page = 'About'; |
|
50 | - } else { |
|
51 | - $active_page = ucfirst(URLDecode::getPiece(1)); |
|
52 | - } |
|
53 | - |
|
54 | - return array_map(function ($row) use ($active_page) { |
|
55 | - $row = (object) $row; |
|
56 | - $row->active = ($row->name == $active_page); |
|
57 | - return $row; |
|
58 | - }, $menu); |
|
59 | - } |
|
8 | + public function __construct() |
|
9 | + { |
|
10 | + parent::__construct(); |
|
11 | + |
|
12 | + $this->add_css('reset'); |
|
13 | + $this->add_css('portfolio', 4); |
|
14 | + } |
|
15 | + |
|
16 | + protected function set_body_data() |
|
17 | + { |
|
18 | + $this->set_body('header_data', [ |
|
19 | + 'menu' => $this->get_menu(), |
|
20 | + 'home_link' => Loader::getRootURL(), |
|
21 | + ]); |
|
22 | + $this->set_body('activity_array', $this->get_recent_activity()); |
|
23 | + |
|
24 | + $this->set_body_view('Page'); |
|
25 | + } |
|
26 | + |
|
27 | + protected function get_menu() |
|
28 | + { |
|
29 | + $menu = [ |
|
30 | + [ |
|
31 | + 'name' => 'About', |
|
32 | + 'link' => Loader::getRootURL(), |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'name' => 'Projects', |
|
36 | + 'link' => Loader::getRootURL() . 'projects/', |
|
37 | + ], |
|
38 | + [ |
|
39 | + 'name' => 'Résumé', |
|
40 | + 'link' => Loader::getRootURL() . 'resume/', |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'Contact', |
|
44 | + 'link' => Loader::getRootURL() . 'contact/', |
|
45 | + ], |
|
46 | + ]; |
|
47 | + |
|
48 | + if (!URLDecode::getPiece(1)) { |
|
49 | + $active_page = 'About'; |
|
50 | + } else { |
|
51 | + $active_page = ucfirst(URLDecode::getPiece(1)); |
|
52 | + } |
|
53 | + |
|
54 | + return array_map(function ($row) use ($active_page) { |
|
55 | + $row = (object) $row; |
|
56 | + $row->active = ($row->name == $active_page); |
|
57 | + return $row; |
|
58 | + }, $menu); |
|
59 | + } |
|
60 | 60 | } |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | { |
24 | 24 | parent::__construct(); |
25 | 25 | |
26 | - global $container; |
|
27 | - $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
28 | - $this->post = $repository->findPostByPath(URLDecode::getPiece(2)); |
|
26 | + global $container; |
|
27 | + $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
28 | + $this->post = $repository->findPostByPath(URLDecode::getPiece(2)); |
|
29 | 29 | |
30 | 30 | if($this->post == null) |
31 | 31 | $this->eject(); |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | Loader::getRootUrl('blog') . $this->post['category'] . '/' . $this->post['path'] . '/', |
37 | 37 | $this->post['title']); |
38 | 38 | |
39 | - global $container; |
|
40 | - $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
41 | - $this->tags = $repository->getTagsForPost($this->post['id']); |
|
39 | + global $container; |
|
40 | + $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
41 | + $this->tags = $repository->getTagsForPost($this->post['id']); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | protected function set_head_data() |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | $this->set_keywords($this->get_post_keywords()); |
51 | 51 | $this->set_author(self::$AUTHOR); |
52 | 52 | |
53 | - $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true); |
|
54 | - $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches); |
|
55 | - $this->set_head('thumbnail', $matches[1]); |
|
53 | + $photo = Content::instance('FetchFirstPhoto', $this->post['body'])->activate(true); |
|
54 | + $photo = preg_match('/^<img src="([a-z-:\.\/]+)" [^>]+>$/', $photo, $matches); |
|
55 | + $this->set_head('thumbnail', $matches[1]); |
|
56 | 56 | |
57 | 57 | if (array_key_exists($this->post['id'], self::$DEPRECATED_BLOGS)) { |
58 | 58 | $log_id = self::$DEPRECATED_BLOGS[$this->post['id']]; |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | |
127 | 127 | $post = new stdclass(); |
128 | 128 | |
129 | - if ( |
|
130 | - strpos($post_row['title'], 'Rainy Supe Loop') === 0 || |
|
131 | - strpos($post_row['title'], 'Malapais Loop') === 0 || |
|
132 | - strpos($post_row['title'], 'Mazatzal Peak Loop') === 0 || |
|
133 | - strpos($post_row['title'], 'Dripping Springs Loop') === 0 |
|
134 | - ) { |
|
135 | - $title = $post_row['title']; |
|
136 | - $title = explode(':', $title); |
|
137 | - $title = array_pop($title); |
|
138 | - $title = trim($title); |
|
139 | - $post->title = $title; |
|
140 | - } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
129 | + if ( |
|
130 | + strpos($post_row['title'], 'Rainy Supe Loop') === 0 || |
|
131 | + strpos($post_row['title'], 'Malapais Loop') === 0 || |
|
132 | + strpos($post_row['title'], 'Mazatzal Peak Loop') === 0 || |
|
133 | + strpos($post_row['title'], 'Dripping Springs Loop') === 0 |
|
134 | + ) { |
|
135 | + $title = $post_row['title']; |
|
136 | + $title = explode(':', $title); |
|
137 | + $title = array_pop($title); |
|
138 | + $title = trim($title); |
|
139 | + $post->title = $title; |
|
140 | + } else if (strpos($post_row['title'], 'Isle Royale') === 0) { |
|
141 | 141 | $title = $post_row['title']; |
142 | 142 | $title = explode(',', $title); |
143 | 143 | $title = array_pop($title); |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | private $series_posts; |
169 | 169 | private function fetch_series_posts() |
170 | 170 | { |
171 | - if(!isset($this->series_posts)) { |
|
172 | - global $container; |
|
173 | - $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']); |
|
174 | - $this->series_posts = $repository->getSeriesForPost($this->post['id']); |
|
175 | - } |
|
176 | - return $this->series_posts; |
|
171 | + if(!isset($this->series_posts)) { |
|
172 | + global $container; |
|
173 | + $repository = new Jacobemerick\Web\Domain\Blog\Series\MysqlSeriesRepository($container['db_connection_locator']); |
|
174 | + $this->series_posts = $repository->getSeriesForPost($this->post['id']); |
|
175 | + } |
|
176 | + return $this->series_posts; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | private function get_related_posts() |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | $exclude_post_array[] = $series_post['post']; |
192 | 192 | } |
193 | 193 | |
194 | - global $container; |
|
195 | - $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
196 | - $post_result = $repository->getActivePostsByRelatedTags($this->post['id']); |
|
194 | + global $container; |
|
195 | + $repository = new Jacobemerick\Web\Domain\Blog\Post\MysqlPostRepository($container['db_connection_locator']); |
|
196 | + $post_result = $repository->getActivePostsByRelatedTags($this->post['id']); |
|
197 | 197 | |
198 | - $post_array = array(); |
|
198 | + $post_array = array(); |
|
199 | 199 | |
200 | 200 | foreach($post_result as $post_row) |
201 | 201 | { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $comment_id = $this->save_comment(); |
43 | 43 | |
44 | 44 | $comment_meta_id = $this->save_comment_meta($commenter_id, $comment_id, $page_id); |
45 | - $comment_service_id = $this->save_to_comment_service(Request::getPost()); |
|
45 | + $comment_service_id = $this->save_to_comment_service(Request::getPost()); |
|
46 | 46 | |
47 | 47 | $this->send_notifications($page_id); |
48 | 48 | $this->redirect_to_comment($comment_meta_id); |
@@ -168,26 +168,26 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - $site = URLDecode::getSite(); |
|
171 | + $site = URLDecode::getSite(); |
|
172 | 172 | |
173 | - if ($site == 'blog') { |
|
174 | - $subject = "New Comment on Jacob Emerick's Blog"; |
|
175 | - $message = "Hello!\nThere has been a new comment on the post '{$this->page_title}' at Jacob Emerick's Blog. You have chosen to be notified of it - please reply to [email protected] if you would like to be removed from these notifications.\n\nOn " . date('F j, Y g:i a') . ", " . Request::getPost('name') . " commented...\n" . Request::getPost('comment') . "\n\nVisit {$this->full_path}#comments to see and reply to all the comments on this post.\nThank you!"; |
|
176 | - } else if ($site == 'waterfalls') { |
|
177 | - $subject = "New Comment on Waterfalls of the Keweenaw"; |
|
178 | - $message = "Hello!\nThere has been a new comment on the page '{$this->page_title}' at Waterfalls of the Keweenaw. You have chosen to be notified of it - please reply to [email protected] if you would like to be removed from these notifications.\n\nOn " . date('F j, Y g:i a') . ", " . Request::getPost('name') . " commented...\n" . Request::getPost('comment') . "\n\nVisit {$this->full_path}#comments to see and reply to all the comments on this post.\nThank you!"; |
|
179 | - } |
|
173 | + if ($site == 'blog') { |
|
174 | + $subject = "New Comment on Jacob Emerick's Blog"; |
|
175 | + $message = "Hello!\nThere has been a new comment on the post '{$this->page_title}' at Jacob Emerick's Blog. You have chosen to be notified of it - please reply to [email protected] if you would like to be removed from these notifications.\n\nOn " . date('F j, Y g:i a') . ", " . Request::getPost('name') . " commented...\n" . Request::getPost('comment') . "\n\nVisit {$this->full_path}#comments to see and reply to all the comments on this post.\nThank you!"; |
|
176 | + } else if ($site == 'waterfalls') { |
|
177 | + $subject = "New Comment on Waterfalls of the Keweenaw"; |
|
178 | + $message = "Hello!\nThere has been a new comment on the page '{$this->page_title}' at Waterfalls of the Keweenaw. You have chosen to be notified of it - please reply to [email protected] if you would like to be removed from these notifications.\n\nOn " . date('F j, Y g:i a') . ", " . Request::getPost('name') . " commented...\n" . Request::getPost('comment') . "\n\nVisit {$this->full_path}#comments to see and reply to all the comments on this post.\nThank you!"; |
|
179 | + } |
|
180 | 180 | |
181 | - global $container; |
|
181 | + global $container; |
|
182 | 182 | |
183 | 183 | foreach($email_recipient_array as $email_recipient) |
184 | 184 | { |
185 | - $sent = $container['mail'] |
|
186 | - ->addTo($email_recipient['email'], $email_recipient['name']) |
|
187 | - ->addBCC($container['config']->admin_email) |
|
188 | - ->setSubject($subject) |
|
189 | - ->setPlainMessage($message) |
|
190 | - ->send(); |
|
185 | + $sent = $container['mail'] |
|
186 | + ->addTo($email_recipient['email'], $email_recipient['name']) |
|
187 | + ->addBCC($container['config']->admin_email) |
|
188 | + ->setSubject($subject) |
|
189 | + ->setPlainMessage($message) |
|
190 | + ->send(); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -201,41 +201,41 @@ discard block |
||
201 | 201 | exit; |
202 | 202 | } |
203 | 203 | |
204 | - private function save_to_comment_service(array $data) |
|
205 | - { |
|
206 | - $path = $_SERVER['REQUEST_URI']; |
|
207 | - $path = explode('/', $path); |
|
208 | - $path = array_filter($path); |
|
209 | - $path = array_slice($path, 0, 2); |
|
210 | - $path = implode('/', $path); |
|
211 | - |
|
212 | - $body = [ |
|
213 | - 'commenter' => [ |
|
214 | - 'name' => $data['name'], |
|
215 | - 'email' => $data['email'], |
|
216 | - 'website' => $data['website'], |
|
217 | - ], |
|
218 | - 'body' => $data['comment'], |
|
219 | - 'should_notify' => (isset($data['notify']) && $data['notify'] == 'check'), |
|
220 | - 'domain' => (URLDecode::getSite() == 'blog' ? 'blog.jacobemerick.com' : 'waterfallsofthekeweenaw.com'), |
|
221 | - 'path' => $path, |
|
222 | - 'url' => $this->full_path, |
|
223 | - 'thread' => 'comments', |
|
224 | - 'ip_address' => $_SERVER['REMOTE_ADDR'], |
|
225 | - 'user_agent' => $_SERVER['HTTP_USER_AGENT'], |
|
226 | - 'referrer' => $_SERVER['HTTP_REFERER'], |
|
227 | - ]; |
|
228 | - |
|
229 | - global $config; |
|
230 | - $configuration = new Jacobemerick\CommentService\Configuration(); |
|
231 | - $configuration->setUsername($config->comments->user); |
|
232 | - $configuration->setPassword($config->comments->password); |
|
233 | - $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
234 | - $configuration->setHost($config->comments->host); |
|
235 | - $configuration->setCurlTimeout($config->comments->timeout); |
|
236 | - |
|
237 | - $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
238 | - $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
239 | - $response = $api->createComment($body); |
|
240 | - } |
|
204 | + private function save_to_comment_service(array $data) |
|
205 | + { |
|
206 | + $path = $_SERVER['REQUEST_URI']; |
|
207 | + $path = explode('/', $path); |
|
208 | + $path = array_filter($path); |
|
209 | + $path = array_slice($path, 0, 2); |
|
210 | + $path = implode('/', $path); |
|
211 | + |
|
212 | + $body = [ |
|
213 | + 'commenter' => [ |
|
214 | + 'name' => $data['name'], |
|
215 | + 'email' => $data['email'], |
|
216 | + 'website' => $data['website'], |
|
217 | + ], |
|
218 | + 'body' => $data['comment'], |
|
219 | + 'should_notify' => (isset($data['notify']) && $data['notify'] == 'check'), |
|
220 | + 'domain' => (URLDecode::getSite() == 'blog' ? 'blog.jacobemerick.com' : 'waterfallsofthekeweenaw.com'), |
|
221 | + 'path' => $path, |
|
222 | + 'url' => $this->full_path, |
|
223 | + 'thread' => 'comments', |
|
224 | + 'ip_address' => $_SERVER['REMOTE_ADDR'], |
|
225 | + 'user_agent' => $_SERVER['HTTP_USER_AGENT'], |
|
226 | + 'referrer' => $_SERVER['HTTP_REFERER'], |
|
227 | + ]; |
|
228 | + |
|
229 | + global $config; |
|
230 | + $configuration = new Jacobemerick\CommentService\Configuration(); |
|
231 | + $configuration->setUsername($config->comments->user); |
|
232 | + $configuration->setPassword($config->comments->password); |
|
233 | + $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
234 | + $configuration->setHost($config->comments->host); |
|
235 | + $configuration->setCurlTimeout($config->comments->timeout); |
|
236 | + |
|
237 | + $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
238 | + $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
239 | + $response = $api->createComment($body); |
|
240 | + } |
|
241 | 241 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | $handle = @fopen($config_path, 'r'); |
17 | 17 | if ($handle === false) { |
18 | - throw new RuntimeException("Could not load config"); |
|
18 | + throw new RuntimeException("Could not load config"); |
|
19 | 19 | } |
20 | 20 | $config = fread($handle, filesize($config_path)); |
21 | 21 | fclose($handle); |
@@ -23,71 +23,71 @@ discard block |
||
23 | 23 | $config = json_decode($config); |
24 | 24 | $last_json_error = json_last_error(); |
25 | 25 | if ($last_json_error !== JSON_ERROR_NONE) { |
26 | - throw new RuntimeException("Could not parse config - JSON error detected"); |
|
26 | + throw new RuntimeException("Could not parse config - JSON error detected"); |
|
27 | 27 | } |
28 | 28 | $container['config'] = $config; |
29 | 29 | |
30 | 30 | // timezones are fun |
31 | 31 | date_default_timezone_set('America/Phoenix'); // todo - belongs in configuration |
32 | 32 | $container['default_timezone'] = function ($c) { |
33 | - return new DateTimeZone('America/Phoenix'); |
|
33 | + return new DateTimeZone('America/Phoenix'); |
|
34 | 34 | }; |
35 | 35 | |
36 | 36 | |
37 | 37 | // configure the db connections holder |
38 | 38 | $db_connections = new Aura\Sql\ConnectionLocator(); |
39 | 39 | $db_connections->setDefault(function () use ($config) { |
40 | - $connection = $config->database->slave; |
|
41 | - return new Aura\Sql\ExtendedPdo( |
|
42 | - "mysql:host={$connection->host}", |
|
43 | - $connection->user, |
|
44 | - $connection->password |
|
45 | - ); |
|
40 | + $connection = $config->database->slave; |
|
41 | + return new Aura\Sql\ExtendedPdo( |
|
42 | + "mysql:host={$connection->host}", |
|
43 | + $connection->user, |
|
44 | + $connection->password |
|
45 | + ); |
|
46 | 46 | }); |
47 | 47 | $db_connections->setWrite('master', function () use ($config) { |
48 | - $connection = $config->database->master; |
|
49 | - return new Aura\Sql\ExtendedPdo( |
|
50 | - "mysql:host={$connection->host}", |
|
51 | - $connection->user, |
|
52 | - $connection->password |
|
53 | - ); |
|
48 | + $connection = $config->database->master; |
|
49 | + return new Aura\Sql\ExtendedPdo( |
|
50 | + "mysql:host={$connection->host}", |
|
51 | + $connection->user, |
|
52 | + $connection->password |
|
53 | + ); |
|
54 | 54 | }); |
55 | 55 | $db_connections->setRead('slave', function () use ($config) { |
56 | - $connection = $config->database->slave; |
|
57 | - $pdo = new Aura\Sql\ExtendedPdo( |
|
58 | - "mysql:host={$connection->host}", |
|
59 | - $connection->user, |
|
60 | - $connection->password |
|
61 | - ); |
|
62 | - |
|
63 | - $profiler = new Aura\Sql\Profiler(); |
|
64 | - $profiler->setActive(true); |
|
65 | - $pdo->setProfiler($profiler); |
|
66 | - |
|
67 | - return $pdo; |
|
56 | + $connection = $config->database->slave; |
|
57 | + $pdo = new Aura\Sql\ExtendedPdo( |
|
58 | + "mysql:host={$connection->host}", |
|
59 | + $connection->user, |
|
60 | + $connection->password |
|
61 | + ); |
|
62 | + |
|
63 | + $profiler = new Aura\Sql\Profiler(); |
|
64 | + $profiler->setActive(true); |
|
65 | + $pdo->setProfiler($profiler); |
|
66 | + |
|
67 | + return $pdo; |
|
68 | 68 | }); |
69 | 69 | $container['db_connection_locator'] = $db_connections; |
70 | 70 | |
71 | 71 | |
72 | 72 | // setup mail handler |
73 | 73 | $container['mail'] = $container->factory(function ($c) { |
74 | - return (new Jacobemerick\Archangel\Archangel())->setLogger($c['logger']); |
|
74 | + return (new Jacobemerick\Archangel\Archangel())->setLogger($c['logger']); |
|
75 | 75 | }); |
76 | 76 | |
77 | 77 | |
78 | 78 | // setup the logger |
79 | 79 | $container['setup_logger'] = $container->protect(function ($name) use ($container) { |
80 | - $logger = new Monolog\Logger($name); |
|
80 | + $logger = new Monolog\Logger($name); |
|
81 | 81 | |
82 | - $logPath = __DIR__ . "/logs/{$name}.log"; |
|
83 | - $streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO); |
|
84 | - $streamHandler->setFormatter( |
|
85 | - new Monolog\Formatter\LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n") |
|
86 | - ); |
|
87 | - $logger->pushHandler($streamHandler); |
|
82 | + $logPath = __DIR__ . "/logs/{$name}.log"; |
|
83 | + $streamHandler = new Monolog\Handler\StreamHandler($logPath, Monolog\Logger::INFO); |
|
84 | + $streamHandler->setFormatter( |
|
85 | + new Monolog\Formatter\LineFormatter("[%datetime%] %channel%.%level_name%: %message%\n") |
|
86 | + ); |
|
87 | + $logger->pushHandler($streamHandler); |
|
88 | 88 | |
89 | - Monolog\ErrorHandler::register($logger); |
|
90 | - $container['logger'] = $logger; |
|
89 | + Monolog\ErrorHandler::register($logger); |
|
90 | + $container['logger'] = $logger; |
|
91 | 91 | }); |
92 | 92 | |
93 | 93 | |
@@ -108,30 +108,30 @@ discard block |
||
108 | 108 | |
109 | 109 | // sets up shutdown function to display profiler |
110 | 110 | register_shutdown_function(function () use ($container) { |
111 | - if ( |
|
112 | - !isset($_COOKIE['debugger']) || |
|
113 | - $_COOKIE['debugger'] != 'display' |
|
114 | - ) { |
|
115 | - return; |
|
116 | - } |
|
117 | - |
|
118 | - $dbProfiles = $container['db_connection_locator'] |
|
119 | - ->getRead() |
|
120 | - ->getProfiler() |
|
121 | - ->getProfiles(); |
|
122 | - $dbProfiles = array_filter($dbProfiles, function ($profile) { |
|
123 | - return $profile['function'] == 'perform'; |
|
124 | - }); |
|
125 | - $dbProfiles = array_map(function ($profile) { |
|
126 | - return [ |
|
127 | - 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
|
128 | - 'parameters' => $profile['bind_values'], |
|
129 | - 'time' => $profile['duration'], |
|
130 | - ]; |
|
131 | - }, $dbProfiles); |
|
132 | - $container['profiler']->setProfiledQueries($dbProfiles); |
|
133 | - $container['profiler']->setDisplay(new Particletree\Pqp\Display()); |
|
134 | - $container['profiler']->display($container['db_connection_locator']->getRead()); |
|
111 | + if ( |
|
112 | + !isset($_COOKIE['debugger']) || |
|
113 | + $_COOKIE['debugger'] != 'display' |
|
114 | + ) { |
|
115 | + return; |
|
116 | + } |
|
117 | + |
|
118 | + $dbProfiles = $container['db_connection_locator'] |
|
119 | + ->getRead() |
|
120 | + ->getProfiler() |
|
121 | + ->getProfiles(); |
|
122 | + $dbProfiles = array_filter($dbProfiles, function ($profile) { |
|
123 | + return $profile['function'] == 'perform'; |
|
124 | + }); |
|
125 | + $dbProfiles = array_map(function ($profile) { |
|
126 | + return [ |
|
127 | + 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
|
128 | + 'parameters' => $profile['bind_values'], |
|
129 | + 'time' => $profile['duration'], |
|
130 | + ]; |
|
131 | + }, $dbProfiles); |
|
132 | + $container['profiler']->setProfiledQueries($dbProfiles); |
|
133 | + $container['profiler']->setDisplay(new Particletree\Pqp\Display()); |
|
134 | + $container['profiler']->display($container['db_connection_locator']->getRead()); |
|
135 | 135 | }); |
136 | 136 | |
137 | 137 | $container['console']->logMemory(null, 'PHP - Post-boostrap memory'); |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | |
19 | 19 | protected function set_head_data() |
20 | 20 | { |
21 | - $this->set_head('rss_link', [ |
|
22 | - 'title' => 'Jacob Emerick Blog Feed', |
|
23 | - 'url' => '/rss.xml' |
|
24 | - ]); |
|
25 | - $this->set_head('rss_comment_link', [ |
|
26 | - 'title' => 'Jacob Emerick Blog Comment Feed', |
|
27 | - 'url' => '/rss-comments.xml' |
|
28 | - ]); |
|
21 | + $this->set_head('rss_link', [ |
|
22 | + 'title' => 'Jacob Emerick Blog Feed', |
|
23 | + 'url' => '/rss.xml' |
|
24 | + ]); |
|
25 | + $this->set_head('rss_comment_link', [ |
|
26 | + 'title' => 'Jacob Emerick Blog Comment Feed', |
|
27 | + 'url' => '/rss-comments.xml' |
|
28 | + ]); |
|
29 | 29 | |
30 | 30 | $this->add_css('normalize'); |
31 | 31 | $this->add_css('blog'); |
@@ -83,45 +83,45 @@ discard block |
||
83 | 83 | final private function get_comments_for_post($post) |
84 | 84 | { |
85 | 85 | $count = CommentCollector::getCommentCountForURL(self::$BLOG_SITE_ID, $post['path']); |
86 | - $count_from_service = $this->get_comments_for_post_from_service($post); |
|
87 | - |
|
88 | - if ($count != $count_from_service) { |
|
89 | - global $container; |
|
90 | - $container['console']->log('Mismatch between comment service and legacy db'); |
|
91 | - $container['console']->log("{$count}, {$count_from_service} in service"); |
|
92 | - } |
|
93 | - return $count; |
|
94 | - } |
|
95 | - |
|
96 | - final private function get_comments_for_post_from_service($post) |
|
97 | - { |
|
98 | - global $config; |
|
99 | - $configuration = new Jacobemerick\CommentService\Configuration(); |
|
100 | - $configuration->setUsername($config->comments->user); |
|
101 | - $configuration->setPassword($config->comments->password); |
|
102 | - $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
103 | - $configuration->setHost($config->comments->host); |
|
104 | - $configuration->setCurlTimeout($config->comments->timeout); |
|
105 | - |
|
106 | - $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
107 | - $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
108 | - |
|
109 | - $start = microtime(true); |
|
110 | - $comment_response = $api->getComments(null, null, null, 'blog.jacobemerick.com', "{$post['category']}/{$post['path']}"); |
|
111 | - $elapsed = microtime(true) - $start; |
|
112 | - global $container; |
|
113 | - $container['logger']->info("CommentService | Comment Count | {$elapsed}"); |
|
114 | - |
|
115 | - return count($comment_response); |
|
116 | - } |
|
86 | + $count_from_service = $this->get_comments_for_post_from_service($post); |
|
87 | + |
|
88 | + if ($count != $count_from_service) { |
|
89 | + global $container; |
|
90 | + $container['console']->log('Mismatch between comment service and legacy db'); |
|
91 | + $container['console']->log("{$count}, {$count_from_service} in service"); |
|
92 | + } |
|
93 | + return $count; |
|
94 | + } |
|
95 | + |
|
96 | + final private function get_comments_for_post_from_service($post) |
|
97 | + { |
|
98 | + global $config; |
|
99 | + $configuration = new Jacobemerick\CommentService\Configuration(); |
|
100 | + $configuration->setUsername($config->comments->user); |
|
101 | + $configuration->setPassword($config->comments->password); |
|
102 | + $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
103 | + $configuration->setHost($config->comments->host); |
|
104 | + $configuration->setCurlTimeout($config->comments->timeout); |
|
105 | + |
|
106 | + $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
107 | + $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
108 | + |
|
109 | + $start = microtime(true); |
|
110 | + $comment_response = $api->getComments(null, null, null, 'blog.jacobemerick.com', "{$post['category']}/{$post['path']}"); |
|
111 | + $elapsed = microtime(true) - $start; |
|
112 | + global $container; |
|
113 | + $container['logger']->info("CommentService | Comment Count | {$elapsed}"); |
|
114 | + |
|
115 | + return count($comment_response); |
|
116 | + } |
|
117 | 117 | |
118 | 118 | final private function get_tags_for_post($post) |
119 | 119 | { |
120 | - global $container; |
|
121 | - $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
122 | - $tag_result = $repository->getTagsForPost($post['id']); |
|
120 | + global $container; |
|
121 | + $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
122 | + $tag_result = $repository->getTagsForPost($post['id']); |
|
123 | 123 | |
124 | - $tag_array = array(); |
|
124 | + $tag_array = array(); |
|
125 | 125 | foreach($tag_result as $tag) |
126 | 126 | { |
127 | 127 | $tag_object = new stdclass(); |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | |
156 | 156 | final private function get_tag_cloud() |
157 | 157 | { |
158 | - global $container; |
|
159 | - $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
160 | - $tag_result = $repository->getTagCloud(); |
|
158 | + global $container; |
|
159 | + $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
|
160 | + $tag_result = $repository->getTagCloud(); |
|
161 | 161 | |
162 | 162 | $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
163 | 163 | |
@@ -206,49 +206,49 @@ discard block |
||
206 | 206 | $array[] = $comment_obj; |
207 | 207 | } |
208 | 208 | |
209 | - $comment_service_array = $this->get_comments_from_service(); |
|
210 | - if ($comment_service_array !== $array) { |
|
211 | - global $container; |
|
212 | - $container['console']->log('Mismatch between comment service and legacy db'); |
|
213 | - $container['console']->log($comment_service_array[0]); |
|
214 | - $container['console']->log($array[0]); |
|
215 | - } |
|
209 | + $comment_service_array = $this->get_comments_from_service(); |
|
210 | + if ($comment_service_array !== $array) { |
|
211 | + global $container; |
|
212 | + $container['console']->log('Mismatch between comment service and legacy db'); |
|
213 | + $container['console']->log($comment_service_array[0]); |
|
214 | + $container['console']->log($array[0]); |
|
215 | + } |
|
216 | 216 | return $array; |
217 | 217 | } |
218 | 218 | |
219 | - final private function get_comments_from_service() |
|
220 | - { |
|
221 | - global $config; |
|
222 | - $configuration = new Jacobemerick\CommentService\Configuration(); |
|
223 | - $configuration->setUsername($config->comments->user); |
|
224 | - $configuration->setPassword($config->comments->password); |
|
225 | - $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
226 | - $configuration->setHost($config->comments->host); |
|
227 | - $configuration->setCurlTimeout($config->comments->timeout); |
|
228 | - |
|
229 | - $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
230 | - $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
231 | - |
|
232 | - $start = microtime(true); |
|
233 | - $comment_response = $api->getComments(1, self::$RECENT_COMMENT_COUNT, '-date', 'blog.jacobemerick.com'); |
|
234 | - $elapsed = microtime(true) - $start; |
|
235 | - global $container; |
|
236 | - $container['logger']->info("CommentService | Sidebar | {$elapsed}"); |
|
237 | - |
|
238 | - $array = array(); |
|
239 | - foreach($comment_response as $comment) |
|
240 | - { |
|
241 | - $body = $comment->getBody(); |
|
242 | - $body = Content::instance('CleanComment', $body)->activate(); |
|
243 | - $body = strip_tags($body); |
|
244 | - |
|
245 | - $comment_obj = new stdclass(); |
|
246 | - $comment_obj->description = Content::instance('SmartTrim', $body)->activate(30); |
|
247 | - $comment_obj->commenter = $comment->getCommenter()->getName(); |
|
248 | - $comment_obj->link = "{$comment->getUrl()}/#comment-{$comment->getId()}"; |
|
249 | - $array[] = $comment_obj; |
|
250 | - } |
|
251 | - return $array; |
|
252 | - } |
|
219 | + final private function get_comments_from_service() |
|
220 | + { |
|
221 | + global $config; |
|
222 | + $configuration = new Jacobemerick\CommentService\Configuration(); |
|
223 | + $configuration->setUsername($config->comments->user); |
|
224 | + $configuration->setPassword($config->comments->password); |
|
225 | + $configuration->addDefaultHeader('Content-Type', 'application/json'); |
|
226 | + $configuration->setHost($config->comments->host); |
|
227 | + $configuration->setCurlTimeout($config->comments->timeout); |
|
228 | + |
|
229 | + $client = new Jacobemerick\CommentService\ApiClient($configuration); |
|
230 | + $api = new Jacobemerick\CommentService\Api\DefaultApi($client); |
|
231 | + |
|
232 | + $start = microtime(true); |
|
233 | + $comment_response = $api->getComments(1, self::$RECENT_COMMENT_COUNT, '-date', 'blog.jacobemerick.com'); |
|
234 | + $elapsed = microtime(true) - $start; |
|
235 | + global $container; |
|
236 | + $container['logger']->info("CommentService | Sidebar | {$elapsed}"); |
|
237 | + |
|
238 | + $array = array(); |
|
239 | + foreach($comment_response as $comment) |
|
240 | + { |
|
241 | + $body = $comment->getBody(); |
|
242 | + $body = Content::instance('CleanComment', $body)->activate(); |
|
243 | + $body = strip_tags($body); |
|
244 | + |
|
245 | + $comment_obj = new stdclass(); |
|
246 | + $comment_obj->description = Content::instance('SmartTrim', $body)->activate(30); |
|
247 | + $comment_obj->commenter = $comment->getCommenter()->getName(); |
|
248 | + $comment_obj->link = "{$comment->getUrl()}/#comment-{$comment->getId()}"; |
|
249 | + $array[] = $comment_obj; |
|
250 | + } |
|
251 | + return $array; |
|
252 | + } |
|
253 | 253 | |
254 | 254 | } |