@@ -28,4 +28,58 @@ public function test_duplicate_models() {
28
28
$ first_model ->a_very_random_value = 1337 ;
29
29
$ this ->assertFalse (isset ($ second_model ->a_very_random_value ));
30
30
}
31
+
32
+ public function test_load_view () {
33
+ $ loader = new Loader ();
34
+ $ view_content = file_get_contents ('tests/views/myview.php ' );
35
+ $ this ->assertSame ($ view_content , $ loader ->view ('myview.php ' ));
36
+ }
37
+
38
+ public function test_view_doesnt_exists () {
39
+ $ this ->setExpectedException ('Core\Exceptions\FileNotFound ' );
40
+ $ loader = new Loader ();
41
+ $ loader ->view ('nonExisting.adadawdakdawd ' );
42
+ }
43
+
44
+ public function test_view_passing_values () {
45
+ $ loader = new Loader ();
46
+ $ view_content = $ loader ->view ('multiply.php ' , ['two ' => 2 , 'three ' => 3 ]);
47
+ $ this ->assertEquals ($ view_content , 6 );
48
+ }
49
+
50
+ public function test_view_pass_object () {
51
+ $ my_object = new DummyClass ();
52
+ $ loader = new Loader ();
53
+ $ view_content = $ loader ->view ('object.php ' , ['object ' => $ my_object ]);
54
+ $ this ->assertEquals ($ view_content , 10 );
55
+ }
56
+
57
+ public function test_view_pass_function () {
58
+ $ function = function ($ a , $ b ) {
59
+ return $ a + $ b ;
60
+ };
61
+
62
+ $ loader = new Loader ();
63
+ $ view_content = $ loader ->view ('function.php ' , ['function ' => $ function ]);
64
+ $ this ->assertEquals ($ view_content , 2 );
65
+ }
66
+
67
+ public function test_view_html () {
68
+ $ loader = new Loader ();
69
+ $ view_content = '<!DOCTYPE html><html><head></head><body>hai</body></html> ' ;
70
+
71
+ $ this ->assertEquals ($ loader ->view ('normal.html ' ), $ view_content );
72
+ }
73
+
74
+ public function test_view_html_with_params () {
75
+ $ loader = new Loader ();
76
+ $ view_content = '<!DOCTYPE html><html><head></head><body>1</body></html> ' ;
77
+ $ this ->assertEquals ($ loader ->view ('withphp.html ' , ['i ' => 1 ]), $ view_content );
78
+ }
31
79
}
80
+
81
+ class DummyClass {
82
+ public function sum (array $ numbers ) {
83
+ return array_sum ($ numbers );
84
+ }
85
+ }
0 commit comments