1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
require_once 'include/utils/layout_utils.php'; |
5
|
|
|
class layout_utilsTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
public function testget_form_header() |
10
|
|
|
{ |
11
|
|
|
error_reporting(E_ERROR | E_PARSE); |
12
|
|
|
|
13
|
|
|
//execute the method and test if it returns html and contains the values provided in parameters |
14
|
|
|
|
15
|
|
|
//help param true |
16
|
|
|
$html1 = get_form_header("test Header", "test subheader", true); |
17
|
|
|
$this->assertGreaterThan(0,strlen($html1)); |
18
|
|
|
$this->assertNotFalse(strpos($html1,"test Header")); |
19
|
|
|
$this->assertNotFalse(strpos($html1,"test subheader")); |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
// help param false |
23
|
|
|
$html2 = get_form_header("new test Header", "new test subheader", false); |
24
|
|
|
$this->assertGreaterThan(0,strlen($html2)); |
25
|
|
|
$this->assertNotFalse(strpos($html2,"new test Header")); |
26
|
|
|
$this->assertNotFalse(strpos($html2,"new test subheader")); |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
$this->assertGreaterThan(strlen($html2),strlen($html1)); |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testget_module_title( ) |
35
|
|
|
{ |
36
|
|
|
//execute the method and test if it returns html and contains the values provided in parameters |
37
|
|
|
|
38
|
|
|
//with show_create true, generates more html |
39
|
|
|
$html1 = get_module_title("Users", "Users Home", true ); |
|
|
|
|
40
|
|
|
$this->assertGreaterThan(0,strlen($html1)); |
41
|
|
|
$this->assertNotFalse(strpos($html1,"Users")); |
42
|
|
|
$this->assertNotFalse(strpos($html1,"Users Home")); |
43
|
|
|
|
44
|
|
|
//with show_create false, generates less html |
45
|
|
|
$html2 = get_module_title("Users", "Users Home", false ); |
|
|
|
|
46
|
|
|
$this->assertGreaterThan(0,strlen($html2)); |
47
|
|
|
$this->assertNotFalse(strpos($html2,"Users")); |
48
|
|
|
$this->assertNotFalse(strpos($html2,"Users Home")); |
49
|
|
|
$this->assertGreaterThan(strlen($html2),strlen($html1)); |
50
|
|
|
|
51
|
|
|
//with show_create flase and count > 1, generates more html compared to count =0 |
52
|
|
|
$html3 = get_module_title("Users", "Users Home", false, 2 ); |
|
|
|
|
53
|
|
|
$this->assertGreaterThan(0,strlen($html3)); |
54
|
|
|
$this->assertNotFalse(strpos($html3,"Users")); |
55
|
|
|
$this->assertNotFalse(strpos($html3,"Users Home")); |
56
|
|
|
$this->assertGreaterThan(strlen($html2),strlen($html3)); |
57
|
|
|
$this->assertGreaterThan(strlen($html3),strlen($html1)); |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testgetClassicModuleTitle() |
63
|
|
|
{ |
64
|
|
|
//execute the method and test if it returns html and contains the values provided in parameters |
65
|
|
|
|
66
|
|
|
//with show_create false, generates less html |
67
|
|
|
$html1 = getClassicModuleTitle("users", Array('Users Home')); |
68
|
|
|
$this->assertGreaterThan(0,strlen($html1)); |
69
|
|
|
$this->assertNotFalse(strpos($html1,"Users Home")); |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
//with show_create true, generates more html |
73
|
|
|
$html2 = getClassicModuleTitle("users", Array('Users Home'),true); |
74
|
|
|
$this->assertGreaterThan(0,strlen($html2)); |
75
|
|
|
$this->assertNotFalse(strpos($html2,"Users Home")); |
76
|
|
|
$this->assertGreaterThan(strlen($html1),strlen($html2)); |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testinsert_popup_header() |
82
|
|
|
{ |
83
|
|
|
//execute the method and test if it returns html/JS |
84
|
|
|
|
85
|
|
|
//with includeJS true, generates more html |
86
|
|
|
ob_start(); |
87
|
|
|
insert_popup_header(); |
88
|
|
|
$renderedContent1 = ob_get_contents(); |
89
|
|
|
ob_end_clean(); |
90
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent1)); |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
//with includeJS false, generates less html |
94
|
|
|
ob_start(); |
95
|
|
|
insert_popup_header('',false); |
96
|
|
|
$renderedContent2 = ob_get_contents(); |
97
|
|
|
ob_end_clean(); |
98
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent2)); |
99
|
|
|
|
100
|
|
|
$this->assertGreaterThan(strlen($renderedContent2),strlen($renderedContent1)); |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testinsert_popup_footer() |
106
|
|
|
{ |
107
|
|
|
//execute the method and test if it returns html |
108
|
|
|
|
109
|
|
|
ob_start(); |
110
|
|
|
insert_popup_footer(); |
111
|
|
|
$renderedContent = ob_get_contents(); |
112
|
|
|
ob_end_clean(); |
113
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent)); |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
?> |
119
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.