1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
|
5
|
|
|
final class BlogEngineTest extends TestCase { |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Code Igniter Instance. |
9
|
|
|
* @var object |
10
|
|
|
*/ |
11
|
|
|
private static $ci; |
12
|
|
|
/** |
13
|
|
|
* Package name for simplicity |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private const PACKAGE = "francis94c/blog"; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Prerquisites for the Unit Tests. |
20
|
|
|
*/ |
21
|
|
|
public static function setUpBeforeClass(): void { |
22
|
|
|
self::$ci =& get_instance(); |
23
|
|
|
self::$ci->load->database('mysqli://root@localhost/test_db'); |
24
|
|
|
$queries = [ |
25
|
|
|
"CREATE TABLE IF NOT EXISTS admins (id INT(7) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, password TEXT NOT NULL) Engine=InnoDB;", |
26
|
|
|
"INSERT INTO admins (id, name, password) VALUES (1, \"Dev\", \"does_not_matter_for_this_test\");" |
27
|
|
|
]; |
28
|
|
|
foreach ($queries as $query) { |
29
|
|
|
self::assertTrue(self::$ci->db->query($query), "$query, Failed to Run."); |
30
|
|
|
} |
31
|
|
|
self::$ci->load->splint("francis94c/blog", "+Blogger", null, "blogger"); |
32
|
|
|
} |
33
|
|
|
/** |
34
|
|
|
* Test Constructor |
35
|
|
|
* |
36
|
|
|
* @tesdox Test Constructor. √ |
37
|
|
|
*/ |
38
|
|
|
public function testConstructor(): void { |
39
|
|
|
$params = [ |
40
|
|
|
"name" => "ronaldo" |
41
|
|
|
]; |
42
|
|
|
self::$ci->load->splint(self::PACKAGE, "+Blogger", $params, "messi"); |
43
|
|
|
$this->assertEquals(Blogger::TABLE_PREFIX . "_ronaldo", self::$ci->messi->getName()); |
44
|
|
|
} |
45
|
|
|
/** |
46
|
|
|
* Test all functions relating to the installation of a blog. this is just the |
47
|
|
|
* creation of tables under the hood. |
48
|
|
|
* |
49
|
|
|
* @testdox Test Installation of Blog with and Without Admin Constraints. √ |
50
|
|
|
*/ |
51
|
|
|
public function testInstallBlog(): void { |
52
|
|
|
$this->assertTrue(self::$ci->blogger->install("test_blog"), "Blog Installed Successfuly without admin ID constraint."); |
53
|
|
|
$this->assertTrue(self::$ci->db->table_exists(Blogger::TABLE_PREFIX . "_test_blog")); |
54
|
|
|
$fields = self::$ci->db->list_fields(Blogger::TABLE_PREFIX . "_test_blog"); |
55
|
|
|
$this->assertContains("id", $fields); |
56
|
|
|
$this->assertContains("title", $fields); |
57
|
|
|
$this->assertContains("content", $fields); |
58
|
|
|
$this->assertContains("slug", $fields); |
59
|
|
|
$this->assertContains("date_created", $fields); |
60
|
|
|
$this->assertContains("date_published", $fields); |
61
|
|
|
$this->assertTrue(self::$ci->blogger->install("test_blog"), "Verify CREATE IF NOT EXISTS clause"); |
62
|
|
|
$this->assertTrue(self::$ci->blogger->install("admin_test_blog", "admins", "id", 7), "Create Blog with existent admin constarint"); |
63
|
|
|
$fields = self::$ci->db->list_fields(Blogger::TABLE_PREFIX . "_admin_test_blog"); |
64
|
|
|
$this->assertContains("id", $fields); |
65
|
|
|
$this->assertContains("title", $fields); |
66
|
|
|
$this->assertContains("content", $fields); |
67
|
|
|
$this->assertContains("slug", $fields); |
68
|
|
|
$this->assertContains("date_created", $fields); |
69
|
|
|
$this->assertContains("date_published", $fields); |
70
|
|
|
$this->assertContains("poster_id", $fields); |
71
|
|
|
} |
72
|
|
|
/** |
73
|
|
|
* Test Empty Blog. |
74
|
|
|
* |
75
|
|
|
* @depends testInstallBlog |
76
|
|
|
* |
77
|
|
|
* @testdox Test HTML Output When no Post is Present. √ |
78
|
|
|
*/ |
79
|
|
|
public function testEmptyBlog(): void { |
80
|
|
|
self::$ci->blogger->setBlog("test_blog"); |
81
|
|
|
$this->setOutputCallback(function ($output) { |
82
|
|
|
$this->assertRegExp("/<h3 class=\"w3-center w3-margin\">No Posts.<\/h3>/", $output); |
83
|
|
|
$this->assertRegExp("/<div class=\"w3-padding\">/", $output); |
84
|
|
|
}); |
85
|
|
|
$this->assertTrue(self::$ci->blogger->renderPostItems(null, null, null, 1, 0), "Test load empty posts set"); |
86
|
|
|
} |
87
|
|
|
/** |
88
|
|
|
* Test UI functions. This just out pust HTML for manual inspection. The optimal |
89
|
|
|
* inspection for this part is to use the Code Igniter Unit Testing system that |
90
|
|
|
* outputs to a browser. See https://splint.cynobit/wiki |
91
|
|
|
* |
92
|
|
|
* @depends testInstallBlog |
93
|
|
|
* |
94
|
|
|
* @testdox Test Editor HTML Output. √ |
95
|
|
|
*/ |
96
|
|
|
public function testEditor(): void { |
97
|
|
|
|
98
|
|
|
// === Collect Output === |
99
|
|
|
$this->setOutputCallback(function () {}); |
100
|
|
|
$this->assertTrue(self::$ci->blogger->loadEditor("my_callback")); // Outputs Editor HTML. |
101
|
|
|
$o = $this->getActualOutput(); |
102
|
|
|
// ==/ Collect Output === |
103
|
|
|
|
104
|
|
|
$this->assertRegExp("/<link rel=\"stylesheet\" href=\"https:\/\/www\.w3schools\.com\/w3css\/4\/w3.css\">/", $o); |
105
|
|
|
$this->assertRegExp("/<link rel=\"stylesheet\" href=\"https:\/\/cdn.jsdelivr.net\/simplemde\/latest\/simplemde.min.css\">/", $o); |
106
|
|
|
$this->assertRegExp("/<script src=\"https:\/\/cdn.jsdelivr.net\/simplemde\/latest\/simplemde.min.js\"><\/script>/", $o); |
107
|
|
|
$this->assertRegExp("/id=\"publishModal\"/", $o); |
108
|
|
|
$this->assertRegExp("/<input type=\"hidden\" name=\"id\" value=\"\"\/>/", $o); |
109
|
|
|
$this->assertRegExp("/\/my_callback/", $o); |
110
|
|
|
|
111
|
|
|
// Reset Output Callback. |
112
|
|
|
$this->setOutputCallback(function ($o) { return $o;}); |
113
|
|
|
|
114
|
|
|
$this->expectOutputRegex("/value=\"1\"\/>/"); |
115
|
|
|
$this->assertTrue(self::$ci->blogger->loadEditor("my_callback", 1)); // Outputs Editor HTML. |
116
|
|
|
} |
117
|
|
|
/** |
118
|
|
|
* Test the blog post saving functionality of the library. |
119
|
|
|
* Create, Save, Publish, Create and Publish |
120
|
|
|
* |
121
|
|
|
* @testdox Blog Save Tested without Admin Constraint. √ |
122
|
|
|
* |
123
|
|
|
* @depends testInstallBlog |
124
|
|
|
*/ |
125
|
|
|
public function testBlogSaveNoAdmin(): void { |
126
|
|
|
// No Admin. |
127
|
|
|
self::$ci->blogger->setBlog("test_blog"); |
128
|
|
|
$_POST["action"] = "save"; |
129
|
|
|
$_POST["title"] = "Hello Title"; |
130
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
131
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(), Blogger::CREATE); |
132
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; |
133
|
|
|
$_POST["id"] = 1; |
134
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(), Blogger::EDIT); |
135
|
|
|
$post = self::$ci->blogger->getPost("Hello-Title", false); |
136
|
|
|
$this->assertTrue(is_array($post)); |
137
|
|
|
$this->assertArrayHasKey("id", $post); |
138
|
|
|
$this->assertArrayHasKey("title", $post); |
139
|
|
|
$this->assertArrayHasKey("content", $post); |
140
|
|
|
$this->assertArrayHasKey("published", $post); |
141
|
|
|
$this->assertArrayHasKey("date_published", $post); |
142
|
|
|
$this->assertArrayHasKey("slug", $post); |
143
|
|
|
$this->assertEquals(1, $post["id"], "Assert Post ID"); |
144
|
|
|
$this->assertEquals("Hello Title", $post["title"], "Assert Post Title"); |
145
|
|
|
$this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); |
146
|
|
|
$this->assertEquals("Hello-Title", $post["slug"]); |
147
|
|
|
$this->assertEquals(0, $post["published"]); |
148
|
|
|
$this->assertEquals(null, $post["date_published"]); |
149
|
|
|
$_POST["action"] = "publish"; |
150
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(), Blogger::PUBLISH); |
151
|
|
|
$post = self::$ci->blogger->getPost("Hello-Title", false); |
152
|
|
|
$this->assertTrue(is_array($post)); |
153
|
|
|
$this->assertEquals(1, $post["published"]); |
154
|
|
|
$this->assertNotEquals(null, $post["date_published"]); |
155
|
|
|
$_POST["action"] = "createAndPublish"; |
156
|
|
|
$_POST["title"] = "Hello Title 2"; |
157
|
|
|
$_POST["editor"] = "Create and Published Post."; |
158
|
|
|
unset($_POST["id"]); |
159
|
|
|
$this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost()); |
160
|
|
|
$post = self::$ci->blogger->getPost("Hello-Title-2", false); |
161
|
|
|
$this->assertTrue(is_array($post)); |
162
|
|
|
$this->assertArrayHasKey("id", $post); |
163
|
|
|
$this->assertArrayHasKey("title", $post); |
164
|
|
|
$this->assertArrayHasKey("content", $post); |
165
|
|
|
$this->assertArrayHasKey("published", $post); |
166
|
|
|
$this->assertArrayHasKey("date_published", $post); |
167
|
|
|
$this->assertArrayHasKey("slug", $post); |
168
|
|
|
$this->assertEquals(2, $post["id"], "Assert Post ID"); |
169
|
|
|
$this->assertEquals("Hello Title 2", $post["title"], "Assert Post Title"); |
170
|
|
|
$this->assertEquals("Create and Published Post.", $post["content"]); |
171
|
|
|
$this->assertEquals("Hello-Title-2", $post["slug"]); |
172
|
|
|
$this->assertEquals(1, $post["published"]); |
173
|
|
|
$this->assertNotEquals(null, $post["date_published"]); |
174
|
|
|
$this->assertEquals(Blogger::ABORT, self::$ci->blogger->savePost(), "No 2 blog posts can have the same title."); |
175
|
|
|
} |
176
|
|
|
/** |
177
|
|
|
* Test blogSave with Admin. |
178
|
|
|
* |
179
|
|
|
* @depends testBlogSaveNoAdmin |
180
|
|
|
*/ |
181
|
|
|
public function testBlogSaveWithAdmin(): void { |
182
|
|
|
self::$ci->blogger->setBlog("admin_test_blog"); |
183
|
|
|
$_POST["action"] = "save"; |
184
|
|
|
$_POST["title"] = "Admin Hello Title"; |
185
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
186
|
|
|
unset($_POST["id"]); |
187
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE); |
188
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; |
189
|
|
|
$_POST["id"] = 1; |
190
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::EDIT); |
191
|
|
|
$post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
192
|
|
|
$this->assertTrue(is_array($post)); |
193
|
|
|
$this->assertArrayHasKey("id", $post); |
194
|
|
|
$this->assertArrayHasKey("title", $post); |
195
|
|
|
$this->assertArrayHasKey("content", $post); |
196
|
|
|
$this->assertArrayHasKey("published", $post); |
197
|
|
|
$this->assertArrayHasKey("date_published", $post); |
198
|
|
|
$this->assertArrayHasKey("slug", $post); |
199
|
|
|
$this->assertEquals(1, $post["id"], "Assert Post ID"); |
200
|
|
|
$this->assertEquals("Admin Hello Title", $post["title"], "Assert Post Title"); |
201
|
|
|
$this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); |
202
|
|
|
$this->assertEquals("Admin-Hello-Title", $post["slug"]); |
203
|
|
|
$this->assertEquals(0, $post["published"]); |
204
|
|
|
$this->assertEquals(null, $post["date_published"]); |
205
|
|
|
$_POST["action"] = "publish"; |
206
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::PUBLISH); |
207
|
|
|
$post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
208
|
|
|
$this->assertTrue(is_array($post)); |
209
|
|
|
$this->assertEquals(1, $post["published"]); |
210
|
|
|
$this->assertNotEquals(null, $post["date_published"]); |
211
|
|
|
// Create And Publish At Once. |
212
|
|
|
$_POST["action"] = "createAndPublish"; |
213
|
|
|
$_POST["title"] = "Admin Hello Title 2"; |
214
|
|
|
$_POST["editor"] = "Create and Published Post."; |
215
|
|
|
unset($_POST["id"]); |
216
|
|
|
$this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost(1)); |
217
|
|
|
$post = self::$ci->blogger->getPost("Admin-Hello-Title-2", false); |
218
|
|
|
$this->assertTrue(is_array($post)); |
219
|
|
|
$this->assertArrayHasKey("id", $post); |
220
|
|
|
$this->assertArrayHasKey("title", $post); |
221
|
|
|
$this->assertArrayHasKey("content", $post); |
222
|
|
|
$this->assertArrayHasKey("published", $post); |
223
|
|
|
$this->assertArrayHasKey("date_published", $post); |
224
|
|
|
$this->assertArrayHasKey("slug", $post); |
225
|
|
|
$this->assertArrayHasKey("poster_id", $post); |
226
|
|
|
$this->assertEquals(2, $post["id"], "Assert Post ID"); |
227
|
|
|
$this->assertEquals("Admin Hello Title 2", $post["title"], "Assert Post Title"); |
228
|
|
|
$this->assertEquals("Create and Published Post.", $post["content"]); |
229
|
|
|
$this->assertEquals("Admin-Hello-Title-2", $post["slug"]); |
230
|
|
|
$this->assertEquals(1, $post["published"]); |
231
|
|
|
$this->assertNotEquals(null, $post["date_published"]); |
232
|
|
|
$this->assertEquals(Blogger::ABORT, self::$ci->blogger->savePost(1), "No 2 blog posts can have the same title."); |
233
|
|
|
} |
234
|
|
|
/** |
235
|
|
|
* Test content of editor when editing post. |
236
|
|
|
* |
237
|
|
|
* @depends testBlogSaveWithAdmin |
238
|
|
|
*/ |
239
|
|
|
public function testEditPostUI(): void { |
240
|
|
|
// === Collect Output === |
241
|
|
|
$this->setOutputCallback(function () {}); |
242
|
|
|
$this->assertTrue(self::$ci->blogger->loadEditor("a_callback", 1)); // Outputs Editor HTML. |
243
|
|
|
$o = $this->getActualOutput(); |
244
|
|
|
// ==/ Collect Output === |
245
|
|
|
$this->assertRegExp("/<div id=\"content\" style=\"display:none;\">(\n|\r|\r\n)The Quick Brown Fox Jumped over the Lazy Dog. Again.<\/div>/", $o); |
246
|
|
|
$this->assertRegExp("/<div class=\"w3-padding w3-margin w3-border w3-round\" id=\"preview\">(\n|\r|\r\n) <p>The Quick Brown Fox Jumped over the Lazy Dog. Again.<\/p><\/div>/", $o); |
247
|
|
|
} |
248
|
|
|
/** |
249
|
|
|
* Test for Recent Post. |
250
|
|
|
* |
251
|
|
|
* @depends testBlogSaveWithAdmin |
252
|
|
|
*/ |
253
|
|
|
public function testGetRecentPosts():void { |
254
|
|
|
// Check Blog Post Counts for different alues of limit. |
255
|
|
|
$this->assertCount(2, self::$ci->blogger->getRecentPosts(0)); |
256
|
|
|
$this->assertCount(1, self::$ci->blogger->getRecentPosts(1)); |
257
|
|
|
$this->assertCount(2, self::$ci->blogger->getRecentPosts(2)); |
258
|
|
|
$this->assertCount(2, self::$ci->blogger->getRecentPosts(5)); |
259
|
|
|
$this->assertCount(2, self::$ci->blogger->getRecentPosts()); |
260
|
|
|
// Validate contents of first post. |
261
|
|
|
$posts = self::$ci->blogger->getRecentPosts(5); |
262
|
|
|
$this->assertArrayHasKey("id", $posts[0]); |
263
|
|
|
$this->assertArrayHasKey("title", $posts[0]); |
264
|
|
|
$this->assertArrayHasKey("content", $posts[0]); |
265
|
|
|
$this->assertArrayHasKey("published", $posts[0]); |
266
|
|
|
$this->assertArrayHasKey("date_published", $posts[0]); |
267
|
|
|
$this->assertArrayHasKey("slug", $posts[0]); |
268
|
|
|
$this->assertArrayHasKey("poster_id", $posts[0]); |
269
|
|
|
$this->assertEquals(2, $posts[0]["id"], "Assert Post ID"); |
270
|
|
|
$this->assertEquals("Admin Hello Title 2", $posts[0]["title"], "Assert Post Title"); |
271
|
|
|
$this->assertEquals("Create and Published Post.", $posts[0]["content"]); |
272
|
|
|
$this->assertEquals("Admin-Hello-Title-2", $posts[0]["slug"]); |
273
|
|
|
$this->assertEquals(1, $posts[0]["published"]); |
274
|
|
|
$this->assertNotEquals(null, $posts[0]["date_published"]); |
275
|
|
|
// Validate contents of second post |
276
|
|
|
$this->assertArrayHasKey("id", $posts[1]); |
277
|
|
|
$this->assertArrayHasKey("title", $posts[1]); |
278
|
|
|
$this->assertArrayHasKey("content", $posts[1]); |
279
|
|
|
$this->assertArrayHasKey("published", $posts[1]); |
280
|
|
|
$this->assertArrayHasKey("date_published", $posts[1]); |
281
|
|
|
$this->assertArrayHasKey("slug", $posts[1]); |
282
|
|
|
$this->assertArrayHasKey("poster_id", $posts[1]); |
283
|
|
|
$this->assertEquals(1, $posts[1]["id"], "Assert Post ID"); |
284
|
|
|
$this->assertEquals("Admin Hello Title", $posts[1]["title"], "Assert Post Title"); |
285
|
|
|
$this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $posts[1]["content"]); |
286
|
|
|
$this->assertEquals("Admin-Hello-Title", $posts[1]["slug"]); |
287
|
|
|
$this->assertEquals(1, $posts[1]["published"]); |
288
|
|
|
$this->assertNotEquals(null, $posts[0]["date_published"]); |
289
|
|
|
// Test Filter. |
290
|
|
|
$_POST["action"] = "save"; |
291
|
|
|
$_POST["title"] = "Test Filter"; |
292
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
293
|
|
|
unset($_POST["id"]); |
294
|
|
|
$this->assertEquals(Blogger::CREATE, self::$ci->blogger->savePost(1)); |
295
|
|
|
$this->assertCount(2, self::$ci->blogger->getRecentPosts(5, true)); |
296
|
|
|
} |
297
|
|
|
// TODO: Test Hits |
298
|
|
|
/** |
299
|
|
|
* Test Single Post Rendering |
300
|
|
|
* |
301
|
|
|
* @depends testGetRecentPosts |
302
|
|
|
*/ |
303
|
|
|
public function testRenderPost(): void { |
304
|
|
|
// Default Post View |
305
|
|
|
// Test Content. |
306
|
|
|
$post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
307
|
|
|
$this->expectOutputRegex("/<h1><b>Admin Hello Title<\/b><\/h1>/"); |
308
|
|
|
self::$ci->blogger->renderPost($post); |
309
|
|
|
$this->expectOutputRegex("/<p>The Quick Brown Fox Jumped over the Lazy Dog. Again.<\/p>/"); |
310
|
|
|
self::$ci->blogger->renderPost($post); |
311
|
|
|
$this->expectOutputRegex("/<div class=\"w3-padding\">/"); |
312
|
|
|
self::$ci->blogger->renderPost($post); |
313
|
|
|
// Test MarkUp |
314
|
|
|
$this->expectOutputRegex("/<div class=\"w3-padding\">([\w(\r|\n|\r\n) <>\/.]+)<\/div>/"); |
315
|
|
|
self::$ci->blogger->renderPost($post); |
316
|
|
|
// Test Custom View. |
317
|
|
|
$this->expectOutputRegex("/BLOGAdmin Hello TitleCONTENT<p>The Quick Brown Fox Jumped over the Lazy Dog. Again.<\/p>/"); |
318
|
|
|
self::$ci->blogger->renderPost($post, "../splints/" . self::PACKAGE . "/phpunit/views/test_post_item"); |
319
|
|
|
} |
320
|
|
|
/** |
321
|
|
|
* Test Posts Vount and Blog Delete. |
322
|
|
|
* |
323
|
|
|
* @testdox Test Posts Count and Blog Delete. √ |
324
|
|
|
* |
325
|
|
|
* @depends testRenderPost |
326
|
|
|
*/ |
327
|
|
|
public function testPostCountAndPostDelete(): void { |
328
|
|
|
$this->assertEquals(2, self::$ci->blogger->getPostsCount()); |
329
|
|
|
$this->assertEquals(3, self::$ci->blogger->getPostsCount(false)); |
330
|
|
|
$_POST["action"] = "delete"; |
331
|
|
|
unset($_POST["title"]); |
332
|
|
|
unset($_POST["editor"]); |
333
|
|
|
// ID maybe = 4 due to failed attempt in creating posts with identical slug (MySQL Doc). |
334
|
|
|
$_POST["id"] = self::$ci->blogger->getPost("Test-Filter", false)["id"]; |
335
|
|
|
$this->assertEquals(Blogger::DELETE, self::$ci->blogger->savePost(1)); |
336
|
|
|
$this->assertEquals(2, self::$ci->blogger->getPostsCount(false)); |
337
|
|
|
} |
338
|
|
|
/** |
339
|
|
|
* Test Meta OG |
340
|
|
|
* |
341
|
|
|
*@depends testPostCountAndPostDelete |
342
|
|
|
* |
343
|
|
|
* @testdox Test Open Graph Tags Generation. √ |
344
|
|
|
*/ |
345
|
|
|
public function testMetaOG(): void { |
346
|
|
|
$post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
347
|
|
|
$og = self::$ci->blogger->metaOg($post); |
348
|
|
|
$this->assertRegExp("/<meta name=\"description\" content=\"The Quick Brown Fox Jumped over the Lazy Dog. Again.\">/", $og); |
349
|
|
|
$this->assertRegExp("/<meta property=\"og:title\" content=\"Admin Hello Title\">/", $og); |
350
|
|
|
$this->assertRegExp("/<meta property=\"og:description\" content=\"The Quick Brown Fox Jumped over the Lazy Dog. Again.\">/", $og); |
351
|
|
|
$this->assertRegExp("/<meta property=\"og:image\" content=\"\">/", $og); |
352
|
|
|
$this->assertRegExp("/<meta name=\"twitter:card\" content=\"summary_large_image\">/", $og); |
353
|
|
|
} |
354
|
|
|
/** |
355
|
|
|
* Test No Action |
356
|
|
|
* |
357
|
|
|
* @testdox Test No Editor Action. √ |
358
|
|
|
* |
359
|
|
|
* @depends testPostCountAndPostDelete |
360
|
|
|
*/ |
361
|
|
|
public function testNoPostAction(): void { |
362
|
|
|
$_POST["action"] = "absolutely_crap"; |
363
|
|
|
$this->assertEquals(Blogger::NO_ACTION, self::$ci->blogger->savePost(1)); |
364
|
|
|
} |
365
|
|
|
/** |
366
|
|
|
* Test Render Post items |
367
|
|
|
* |
368
|
|
|
* @testdox Test Rendering of Post Items. √ |
369
|
|
|
* |
370
|
|
|
* @depends testNoPostAction |
371
|
|
|
*/ |
372
|
|
|
public function testRenderPostItems(): void { |
373
|
|
|
// === Collect Output === |
374
|
|
|
$this->setOutputCallback(function () {}); |
375
|
|
|
$this->assertTrue(self::$ci->blogger->renderPostItems("../splints/" . self::PACKAGE . "/phpunit/views/test_post_card_item", "the_gunners")); |
376
|
|
|
$o = $this->getActualOutput(); |
377
|
|
|
// ==/ Collect Output === |
378
|
|
|
|
379
|
|
|
$this->assertRegExp("/A CARD HERE Admin Hello Title TOKEN <p>The Quick Brown Fox Jumped over the Lazy Dog. Again.<\/p> ID = 1/", $o); |
380
|
|
|
$this->assertRegExp("/A CARD HERE Admin Hello Title 2 TOKEN <p>Create and Published Post.<\/p> ID = 2/", $o); |
381
|
|
|
$this->assertRegExp("/the_gunners/", $o); |
382
|
|
|
} |
383
|
|
|
/** |
384
|
|
|
* Test Pagination |
385
|
|
|
* |
386
|
|
|
* @testdox Test Pagination. √ |
387
|
|
|
* |
388
|
|
|
* @depends testRenderPostItems |
389
|
|
|
*/ |
390
|
|
|
public function testPagination(): void { |
391
|
|
|
self::$ci->blogger->setBlog("admin_test_blog"); |
392
|
|
|
// Populate Tables with post to make it up to 12 items in total. |
393
|
|
|
// Current Posts count is 2. |
394
|
|
|
$_POST["action"] = "createAndPublish"; |
395
|
|
|
$_POST["title"] = "Item 3"; // This is all that needs to be unique. |
396
|
|
|
$_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
397
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
398
|
|
|
$_POST["title"] = "Item 4"; |
399
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
400
|
|
|
$_POST["title"] = "Item 5"; |
401
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
402
|
|
|
$_POST["title"] = "Item 6"; |
403
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
404
|
|
|
$_POST["title"] = "Item 7"; |
405
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
406
|
|
|
$_POST["title"] = "Item 8"; |
407
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
408
|
|
|
$_POST["title"] = "Item 9"; |
409
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
410
|
|
|
$_POST["title"] = "Item 10"; |
411
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
412
|
|
|
$_POST["title"] = "Item 11"; |
413
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
414
|
|
|
$_POST["title"] = "Item 12"; |
415
|
|
|
$this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE_AND_PUBLISH); |
416
|
|
|
$this->assertEquals(12, self::$ci->blogger->getPostsCount(false)); |
417
|
|
|
$this->assertCount(5, self::$ci->blogger->getPosts(1, 5)); // Page 1 |
418
|
|
|
$this->assertCount(5, self::$ci->blogger->getPosts(2, 5)); // Page 2 |
419
|
|
|
$this->assertCount(2, self::$ci->blogger->getPosts(3, 5)); // Page 3 |
420
|
|
|
$this->assertCount(0, self::$ci->blogger->getPosts(4, 5)); // Page 4 - Non Existent. |
421
|
|
|
$posts = self::$ci->blogger->getPosts(1, 5); |
422
|
|
|
$this->assertEquals("Item 12", $posts[0]["title"]); |
423
|
|
|
$this->assertEquals("Item 8", $posts[4]["title"]); |
424
|
|
|
$posts = self::$ci->blogger->getPosts(3, 5); |
425
|
|
|
$this->assertEquals("Admin Hello Title 2", $posts[0]["title"]); |
426
|
|
|
$this->assertEquals("Admin Hello Title", $posts[1]["title"]); |
427
|
|
|
$posts = self::$ci->blogger->getPosts(2, 5); |
428
|
|
|
$this->assertEquals("Item 7", $posts[0]["title"]); |
429
|
|
|
} |
430
|
|
|
/** |
431
|
|
|
* Test Post Hit Counting. |
432
|
|
|
* |
433
|
|
|
* @testdox Test Post Hit Counting logic. |
434
|
|
|
* |
435
|
|
|
* @depends testPagination |
436
|
|
|
*/ |
437
|
|
|
public function testPostHitCount(): void { |
438
|
|
|
self::$ci->blogger->setBlog("admin_test_blog"); |
439
|
|
|
$this->assertEquals(0, self::$ci->blogger->getPost("Item-12", false)["hits"]); |
440
|
|
|
self::$ci->blogger->getPost("Item-12", true); |
441
|
|
|
self::$ci->blogger->getPost("Item-12", true); |
442
|
|
|
self::$ci->blogger->getPost("Item-12", true); |
443
|
|
|
$this->assertEquals(3, self::$ci->blogger->getPost("Item-12", false)["hits"]); |
444
|
|
|
$this->assertEquals(3, self::$ci->blogger->getHits((int) self::$ci->blogger->getPost("Item-12", false)["id"])); |
445
|
|
|
} |
446
|
|
|
/** |
447
|
|
|
* Test Post Publish Function. |
448
|
|
|
* |
449
|
|
|
* @testdox Test Post Publish Function. |
450
|
|
|
* |
451
|
|
|
* @depends testPostHitCount |
452
|
|
|
*/ |
453
|
|
|
public function testPostPublishFunction(): void { |
454
|
|
|
self::$ci->blogger->setBlog("admin_test_blog"); |
455
|
|
|
$post = self::$ci->blogger->getPost("Item-12", false); |
456
|
|
|
self::$ci->blogger->publishPost((int) $post["id"], false); |
457
|
|
|
$this->assertEquals(0, self::$ci->blogger->getPost("Item-12")["published"]); |
458
|
|
|
self::$ci->blogger->publishPost((int) $post["id"], true); |
459
|
|
|
$this->assertEquals(1, self::$ci->blogger->getPost("Item-12")["published"]); |
460
|
|
|
} |
461
|
|
|
/** |
462
|
|
|
* Test Search Posts. |
463
|
|
|
* |
464
|
|
|
* @testdox Test Search Posts |
465
|
|
|
* |
466
|
|
|
* @depends testPostHitCount |
467
|
|
|
*/ |
468
|
|
|
public function testSearchPosts(): void { |
469
|
|
|
// The expected Results are gotten from the actions of the tests this test |
470
|
|
|
// depends on. |
471
|
|
|
|
472
|
|
|
// Title Search |
473
|
|
|
$this->assertCount(5, self::$ci->blogger->searchPosts("Item")); |
474
|
|
|
$this->assertCount(5, self::$ci->blogger->searchPosts("Item", 2)); |
475
|
|
|
$this->assertCount(0, self::$ci->blogger->searchPosts("Item", 3)); |
476
|
|
|
|
477
|
|
|
// Body Search. |
478
|
|
|
$this->assertCount(1, self::$ci->blogger->searchPosts("Fox", 3)); |
479
|
|
|
} |
480
|
|
|
/** |
481
|
|
|
* Test Setters and Getters. |
482
|
|
|
* |
483
|
|
|
* @testdox Getters and Setters. √ |
484
|
|
|
*/ |
485
|
|
|
public function testDynamicFunctions(): void { |
486
|
|
|
self::$ci->blogger->setBlog("rocket_blog"); |
487
|
|
|
$this->assertEquals(Blogger::TABLE_PREFIX . "_rocket_blog", self::$ci->blogger->getName(), "Blogger setBlog works."); |
488
|
|
|
} |
489
|
|
|
/** |
490
|
|
|
* Load Scripts Test. |
491
|
|
|
* |
492
|
|
|
* @testdox Client Side Scripts Test. √ |
493
|
|
|
*/ |
494
|
|
|
public function testClientSideScripts(): void { |
495
|
|
|
$this->assertRegExp("/<link rel=\"stylesheet\" href=\"https:\/\/www\.w3schools\.com\/w3css\/4\/w3.css\">/", self::$ci->blogger->w3css()); |
496
|
|
|
$this->assertRegExp("/<link rel=\"stylesheet\" href=\"https:\/\/use.fontawesome.com\/releases\/v5.3.1\/css\/all.css\"\/>/", self::$ci->blogger->fontsAwesome()); |
497
|
|
|
} |
498
|
|
|
/** |
499
|
|
|
* Clear and Free up persistent used resources for this test class. |
500
|
|
|
*/ |
501
|
|
|
public static function tearDownAfterClass(): void { |
502
|
|
|
self::$ci->db->empty_table("blogger_posts_test_blog"); |
503
|
|
|
self::$ci->db->empty_table("blogger_posts_admin_test_blog"); |
504
|
|
|
self::$ci->db->empty_table("admins"); |
505
|
|
|
self::$ci->load->dbforge(); |
506
|
|
|
self::$ci->dbforge->drop_table("blogger_posts_test_blog"); |
507
|
|
|
self::$ci->dbforge->drop_table("blogger_posts_admin_test_blog"); |
508
|
|
|
self::$ci->dbforge->drop_table("admins"); |
509
|
|
|
self::$ci->db->close(); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|