-
Notifications
You must be signed in to change notification settings - Fork 1
/
unittest.php
executable file
·99 lines (75 loc) · 3.09 KB
/
unittest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/phpunit
<?php
require_once 'classes/Routing.php';
require_once 'classes/Post.php';
require_once 'classes/Blog.php';
class DependencyFailureTest extends PHPUnit_Framework_TestCase{
private static $posts=array();
private static $router;
private static $blog;
public static function tearDownAfterClass(){}
public function setup(){
$_SERVER['SERVER_NAME']='localhost';
self::$blog=new Blog(new BlogRouting());
self::$blog->addPost(new Post("Artikel 1", "LOREM IPSUM LOREM IPSUM", "2010 Januar 23"));
self::$blog->addPost(new Post("Verrückte Umlaute", "LOREM IPSUM LOREM IPSUM", "2010 Februar 10"));
self::$blog->addPost(new Post("Artikel 3", "LOREM IPSUM LOREM IPSUM", "2010 März 4"));
self::$blog->addPost(new Post("Artikel 4", "LOREM IPSUM LOREM IPSUM", "2010 April 2"));
self::$blog->addPost(new Post("Artikel 55", "LOREM IPSUM LOREM IPSUM", "2010 September 26"));
self::$blog->addPost(new Post("Einzelpost", "LOREM IPSUM LOREM IPSUM", "2011 April 11"));
self::$blog->addPost(new Post("Artikel 5", "LOREM IPSUM LOREM IPSUM", "2011 Januar 23"));
self::$blog->addPost(new Post("Artikel 6", "LOREM IPSUM LOREM IPSUM", "2011 Januar 10"));
self::$blog->addPost(new Post("Artikel 7", "LOREM IPSUM LOREM IPSUM", "2011 Januar 4"));
self::$blog->addPost(new Post("Artikel 8", "LOREM IPSUM LOREM IPSUM", "2011 Januar 2"));
self::$blog->addPost(new Post("Artikel 9", "LOREM IPSUM LOREM IPSUM", "2010 September 23"));
self::$blog->addPost(new Post("Artikel 10", "LOREM IPSUM LOREM IPSUM", "2010 September 23"));
self::$blog->addPost(new Post("Artikel 11", "LOREM IPSUM LOREM IPSUM", "2010 September 23"));
self::$blog->addPost(new Post("Artikel 12", "LOREM IPSUM LOREM IPSUM", "2010 September 23"));
self::$blog->addPost(new Post("Artikel 13", "Haloooooo", "2010 September 23"));
}//setup
private function countArticles(){
return count(preg_split("/\n/", self::$blog->getPosts(),-1,PREG_SPLIT_NO_EMPTY));
}
public function testGetArticle(){
$_SERVER['REQUEST_URI']='/2011/April/11/Einzelpost';
$this->setUp();
$this->assertEquals($this->countArticles(), 7);
}
public function testGetYear(){
$_SERVER['REQUEST_URI']='/2011';
$this->setUp();
$this->assertEquals($this->countArticles(), 35);
}
public function testGetMonth(){
$_SERVER['REQUEST_URI']='/2010/September';
$this->setUp();
$this->assertEquals($this->countArticles(), 42);
}
public function testGetDay(){
$_SERVER['REQUEST_URI']='/2010/september/23';
$this->setUp();
$this->assertEquals($this->countArticles(), 35);
}
public function testGetDocumentRoot(){
$_SERVER['REQUEST_URI']='/';
$this->setUp();
$this->assertEquals($this->countArticles(), 35);
}
public function testContentNotFound(){
$_SERVER['REQUEST_URI']='/malformed/';
$this->setUp();
$this->assertEquals("<h1>Leider nichts gefunden ☹</h1>",self::$blog->getPosts());
}
/* public function testException(){
$success=false;
try{
$unrar=new UnRar("-ass");
} catch (Exception $e){
$success=true;
}
if(!$success)
$this->fail("Exception for Folder not found raised");
}
*/
}
?>