Passed
Push — master ( 152166...2f0073 )
by Francis
01:16
created

BlogTest::tearDownAfterClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
use PHPUnit\Framework\TestCase;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
3
4
final class BlogTest extends TestCase {
5
6
  /**
7
   * [private description]
8
   * @var [type]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
9
   */
10
  private static $ci;
11
12
  /**
13
   * [setUp description]
14
   */
15
  public static function setUpBeforeClass(): void {
16
    self::$ci =& get_instance();
1 ignored issue
show
Bug introduced by
The function get_instance was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
    self::$ci =& /** @scrutinizer ignore-call */ get_instance();
Loading history...
17
    self::$ci->load->database('mysqli://root@localhost/test_db');
18
    $queries = [
19
      "CREATE TABLE IF NOT EXISTS admins (id INT(7) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, password TEXT NOT NULL) Engine=InnoDB;",
20
      "INSERT INTO admins (id, name, password) VALUES (1, \"Dev\", \"does_not_matter_for_this_test\");"
21
    ];
22
    foreach ($queries as $query) {
23
      self::assertTrue(self::$ci->db->query($query), "$query, Ran sucessfully.");
24
    }
25
    self::$ci->load->splint("francis94c/blog", "+Blogger", null, "blogger");
26
  }
27
  /**
28
   * [testInstallBlog description]
29
   * @return [type] [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
30
   */
31
  public function testInstallBlog() {
32
    $this->assertTrue(self::$ci->blogger->install("test_blog"), "Blog Installed Successfuly without admin ID constraint.");
33
    $this->assertTrue(self::$ci->db->table_exists("blogger_posts_test_blog"));
34
    $fields = self::$ci->db->list_fields("blogger_posts_test_blog");
35
    $this->assertContains("id", $fields);
36
    $this->assertContains("title", $fields);
37
    $this->assertContains("content", $fields);
38
    $this->assertContains("slug", $fields);
39
    $this->assertContains("date_created", $fields);
40
    $this->assertContains("date_published", $fields);
41
    $this->assertTrue(self::$ci->blogger->install("test_blog"), "Verify CREATE IF NOT EXISTS clause");
42
    $this->assertTrue(self::$ci->blogger->install("admin_test_blog", "admins", "id", 7), "Create Blog with existent admin constarint");
43
    $fields = self::$ci->db->list_fields("blogger_posts_admin_test_blog");
44
    $this->assertContains("id", $fields);
45
    $this->assertContains("title", $fields);
46
    $this->assertContains("content", $fields);
47
    $this->assertContains("slug", $fields);
48
    $this->assertContains("date_created", $fields);
49
    $this->assertContains("date_published", $fields);
50
  }
51
  /**
52
   * [testUI description]
53
   * @return [type] [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
54
   * @depends testInstallBlog
55
   */
56
  public function testUI() {
57
    $this->assertTrue(self::$ci->blogger->loadEditor("callback"), "Load Editor");
58
    self::$ci->blogger->setBlog("test_blog");
59
    $this->assertTrue(self::$ci->blogger->renderPostItems(null, null, null, 1, 0), "Test load empty posts set");
60
  }
61
  /**
62
   * [testBlogSave description]
63
   * @return [type] [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
64
   * @depends testInstallBlog
65
   */
66
  public function testBlogSave() {
67
    // No Admin.
68
    self::$ci->blogger->setBlog("test_blog");
69
    $_POST["action"] = "save";
70
    $_POST["title"] = "Hello Title";
71
    $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog.";
72
    $this->assertEquals(self::$ci->blogger->savePost(), Blogger::CREATE);
73
    $_POST["editor"] = "The Quick Brown Fox Jumped over the Lazy Dog. Again.";
74
    $_POST["id"] = 1;
75
    $this->assertEquals(self::$ci->blogger->savePost(), Blogger::EDIT);
76
    $this->assertTrue(self::$ci->blogger->renderPost("Hello-Title", null));
77
  }
78
  /**
79
   * [tearDownAfterClass description]
80
   */
81
  public static function tearDownAfterClass(): void {
82
    self::$ci->db->empty_table("admins");
83
    self::$ci->db->empty_table("blogger_posts_test_blog");
84
    self::$ci->db->empty_table("blogger_posts_admin_test_blog");
85
    self::$ci->load->dbforge();
86
    self::$ci->dbforge->drop_table("admins");
87
    self::$ci->dbforge->drop_table("blogger_posts_test_blog");
88
    self::$ci->dbforge->drop_table("blogger_posts_admin_test_blog");
89
90
  }
91
}
92