Conditions | 1 |
Paths | 1 |
Total Lines | 103 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
70 | */ |
||
71 | public function testBlogSaveNoAdmin(): void { |
||
72 | // No Admin. |
||
73 | self::$ci->blogger->setBlog("test_blog"); |
||
74 | $_POST["action"] = "save"; |
||
75 | $_POST["title"] = "Hello Title"; |
||
76 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
||
77 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::CREATE); |
||
78 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; |
||
79 | $_POST["id"] = 1; |
||
80 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::EDIT); |
||
81 | $this->assertTrue(self::$ci->blogger->renderPost("Hello-Title", null)); |
||
82 | $post = self::$ci->blogger->getPost("Hello-Title", false); |
||
83 | $this->assertTrue(is_array($post)); |
||
84 | $this->assertArrayHasKey("id", $post); |
||
85 | $this->assertArrayHasKey("title", $post); |
||
86 | $this->assertArrayHasKey("content", $post); |
||
87 | $this->assertArrayHasKey("published", $post); |
||
88 | $this->assertArrayHasKey("date_published", $post); |
||
89 | $this->assertArrayHasKey("slug", $post); |
||
90 | $this->assertEquals(1, $post["id"], "Assert Post ID"); |
||
91 | $this->assertEquals("Hello Title", $post["title"], "Assert Post Title"); |
||
92 | $this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); |
||
93 | $this->assertEquals("Hello-Title", $post["slug"]); |
||
94 | $this->assertEquals(0, $post["published"]); |
||
95 | $this->assertEquals(null, $post["date_published"]); |
||
96 | $_POST["action"] = "publish"; |
||
97 | $this->assertEquals(self::$ci->blogger->savePost(), Blogger::PUBLISH); |
||
98 | $post = self::$ci->blogger->getPost("Hello-Title", false); |
||
99 | $this->assertTrue(is_array($post)); |
||
100 | $this->assertEquals(1, $post["published"]); |
||
101 | $this->assertNotEquals(null, $post["date_published"]); |
||
102 | $_POST["action"] = "createAndPublish"; |
||
103 | $_POST["title"] = "Hello Title 2"; |
||
104 | $_POST["editor"] = "Create and Published Post."; |
||
105 | unset($_POST["id"]); |
||
106 | $this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost()); |
||
107 | $post = self::$ci->blogger->getPost("Hello-Title-2", false); |
||
108 | $this->assertTrue(is_array($post)); |
||
109 | $this->assertArrayHasKey("id", $post); |
||
110 | $this->assertArrayHasKey("title", $post); |
||
111 | $this->assertArrayHasKey("content", $post); |
||
112 | $this->assertArrayHasKey("published", $post); |
||
113 | $this->assertArrayHasKey("date_published", $post); |
||
114 | $this->assertArrayHasKey("slug", $post); |
||
115 | $this->assertEquals(2, $post["id"], "Assert Post ID"); |
||
116 | $this->assertEquals("Hello Title 2", $post["title"], "Assert Post Title"); |
||
117 | $this->assertEquals("Create and Published Post.", $post["content"]); |
||
118 | $this->assertEquals("Hello-Title-2", $post["slug"]); |
||
119 | $this->assertEquals(1, $post["published"]); |
||
120 | $this->assertNotEquals(null, $post["date_published"]); |
||
121 | $this->assertEquals(Blogger::ABORT, self::$ci->blogger->savePost(), "No 2 blog posts can have the same title."); |
||
122 | } |
||
123 | /** |
||
124 | * Test blogSave with Admin. |
||
125 | * |
||
126 | * @depends testBlogSaveNoAdmin |
||
127 | */ |
||
128 | public function testBlogSaveWithAdmin(): void { |
||
129 | self::$ci->blogger->setBlog("admin_test_blog"); |
||
130 | $_POST["action"] = "save"; |
||
131 | $_POST["title"] = "Admin Hello Title"; |
||
132 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog."; |
||
133 | unset($_POST["id"]); |
||
134 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::CREATE); |
||
135 | $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again."; |
||
136 | $_POST["id"] = 1; |
||
137 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::EDIT); |
||
138 | $this->assertTrue(self::$ci->blogger->renderPost("Admin-Hello-Title", null)); |
||
139 | $post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
||
140 | $this->assertTrue(is_array($post)); |
||
141 | $this->assertArrayHasKey("id", $post); |
||
142 | $this->assertArrayHasKey("title", $post); |
||
143 | $this->assertArrayHasKey("content", $post); |
||
144 | $this->assertArrayHasKey("published", $post); |
||
145 | $this->assertArrayHasKey("date_published", $post); |
||
146 | $this->assertArrayHasKey("slug", $post); |
||
147 | $this->assertEquals(1, $post["id"], "Assert Post ID"); |
||
148 | $this->assertEquals("Admin Hello Title", $post["title"], "Assert Post Title"); |
||
149 | $this->assertEquals("The Quick Brown Fox Jumped over the Lazy Dog. Again.", $post["content"]); |
||
150 | $this->assertEquals("Admin-Hello-Title", $post["slug"]); |
||
151 | $this->assertEquals(0, $post["published"]); |
||
152 | $this->assertEquals(null, $post["date_published"]); |
||
153 | $_POST["action"] = "publish"; |
||
154 | $this->assertEquals(self::$ci->blogger->savePost(1), Blogger::PUBLISH); |
||
155 | $post = self::$ci->blogger->getPost("Admin-Hello-Title", false); |
||
156 | $this->assertTrue(is_array($post)); |
||
157 | $this->assertEquals(1, $post["published"]); |
||
158 | $this->assertNotEquals(null, $post["date_published"]); |
||
159 | $_POST["action"] = "createAndPublish"; |
||
160 | $_POST["title"] = "Admin Hello Title 2"; |
||
161 | $_POST["editor"] = "Create and Published Post."; |
||
162 | unset($_POST["id"]); |
||
163 | $this->assertEquals(Blogger::CREATE_AND_PUBLISH, self::$ci->blogger->savePost(1)); |
||
164 | $post = self::$ci->blogger->getPost("Admin-Hello-Title-2", false); |
||
165 | $this->assertTrue(is_array($post)); |
||
166 | $this->assertArrayHasKey("id", $post); |
||
167 | $this->assertArrayHasKey("title", $post); |
||
168 | $this->assertArrayHasKey("content", $post); |
||
169 | $this->assertArrayHasKey("published", $post); |
||
170 | $this->assertArrayHasKey("date_published", $post); |
||
171 | $this->assertArrayHasKey("slug", $post); |
||
172 | $this->assertArrayHasKey("poster_id", $post); |
||
173 | $this->assertEquals(2, $post["id"], "Assert Post ID"); |
||
271 |