@@ -29,11 +29,11 @@ public function __construct($test)
2929 $ this ->config ['dbengine ' ] = $ test ->getEngineName ();
3030 }
3131
32- private function action ($ method ,$ url ,$ data ='' )
32+ private function action ($ method , $ url , $ data ='' )
3333 {
3434 $ url = parse_url ($ url );
3535 $ query = isset ($ url ['query ' ])?$ url ['query ' ]:'' ;
36- parse_str ($ query ,$ get );
36+ parse_str ($ query , $ get );
3737
3838 $ this ->api = new \PHP_CRUD_API (array (
3939 'dbengine ' =>$ this ->config ['dbengine ' ],
@@ -42,14 +42,37 @@ private function action($method,$url,$data='')
4242 'password ' =>$ this ->config ['password ' ],
4343 'database ' =>$ this ->config ['database ' ],
4444 // callbacks
45- 'table_authorizer ' =>function ($ action ,$ database ,$ table ) { return true ; },
46- 'column_authorizer ' =>function ($ action ,$ database ,$ table ,$ column ) { return !($ column =='password ' &&$ action =='list ' ); },
47- 'record_filter ' =>function ($ action ,$ database ,$ table ) { return ($ table =='posts ' )?array ('id,neq,13 ' ):false ; },
48- 'tenancy_function ' =>function ($ action ,$ database ,$ table ,$ column ) { return ($ table =='users ' &&$ column =='id ' )?1 :null ; },
49- 'input_sanitizer ' =>function ($ action ,$ database ,$ table ,$ column ,$ type ,$ value ) { return is_string ($ value )?strip_tags ($ value ):$ value ; },
50- 'input_validator ' =>function ($ action ,$ database ,$ table ,$ column ,$ type ,$ value ,$ context ) { return ($ column =='category_id ' && !is_numeric ($ value ))?'must be numeric ' :true ; },
51- 'before ' =>function (&$ action ,&$ database ,&$ table ,&$ id ,&$ input ) { if ($ table =='products ' ) if ($ action =='create ' ) $ input ->created_at = '2013-12-11 10:09:08 ' ; else if ($ action =='delete ' ) { $ action ='update ' ; $ input = (object )array ('deleted_at ' => '2013-12-11 11:10:09 ' ); } },
52- 'after ' =>function ($ action ,$ database ,$ table ,$ id ,$ input ,$ output ) { file_put_contents ('log.txt ' ,var_export (array ($ action ,$ database ,$ table ,$ id ,$ input ,$ output ),true ),FILE_APPEND ); },
45+ 'table_authorizer ' =>function ($ action , $ database , $ table ) {
46+ return true ;
47+ },
48+ 'column_authorizer ' =>function ($ action , $ database , $ table , $ column ) {
49+ return !($ column =='password ' &&$ action =='list ' );
50+ },
51+ 'record_filter ' =>function ($ action , $ database , $ table ) {
52+ return ($ table =='posts ' )?array ('id,neq,13 ' ):false ;
53+ },
54+ 'tenancy_function ' =>function ($ action , $ database , $ table , $ column ) {
55+ return ($ table =='users ' &&$ column =='id ' )?1 :null ;
56+ },
57+ 'input_sanitizer ' =>function ($ action , $ database , $ table , $ column , $ type , $ value ) {
58+ return is_string ($ value )?strip_tags ($ value ):$ value ;
59+ },
60+ 'input_validator ' =>function ($ action , $ database , $ table , $ column , $ type , $ value , $ context ) {
61+ return ($ column =='category_id ' && !is_numeric ($ value ))?'must be numeric ' :true ;
62+ },
63+ 'before ' =>function (&$ action , &$ database , &$ table , &$ id , &$ input ) {
64+ if ($ table =='products ' ) {
65+ if ($ action =='create ' ) {
66+ $ input ->created_at = '2013-12-11 10:09:08 ' ;
67+ } elseif ($ action =='delete ' ) {
68+ $ action ='update ' ;
69+ $ input = (object )array ('deleted_at ' => '2013-12-11 11:10:09 ' );
70+ }
71+ }
72+ },
73+ 'after ' =>function ($ action , $ database , $ table , $ id , $ input , $ output ) {
74+ file_put_contents ('log.txt ' , var_export (array ($ action ,$ database ,$ table ,$ id ,$ input ,$ output ), true ), FILE_APPEND );
75+ },
5376 // for tests
5477 'method ' =>$ method ,
5578 'request ' =>$ url ['path ' ],
@@ -61,32 +84,32 @@ private function action($method,$url,$data='')
6184
6285 public function get ($ url )
6386 {
64- return $ this ->action ('GET ' ,$ url );
87+ return $ this ->action ('GET ' , $ url );
6588 }
6689
67- public function post ($ url ,$ data )
90+ public function post ($ url , $ data )
6891 {
69- return $ this ->action ('POST ' ,$ url ,$ data );
92+ return $ this ->action ('POST ' , $ url , $ data );
7093 }
7194
72- public function put ($ url ,$ data )
95+ public function put ($ url , $ data )
7396 {
74- return $ this ->action ('PUT ' ,$ url ,$ data );
97+ return $ this ->action ('PUT ' , $ url , $ data );
7598 }
7699
77100 public function delete ($ url )
78101 {
79- return $ this ->action ('DELETE ' ,$ url );
102+ return $ this ->action ('DELETE ' , $ url );
80103 }
81104
82105 public function options ($ url )
83106 {
84- return $ this ->action ('OPTIONS ' ,$ url );
107+ return $ this ->action ('OPTIONS ' , $ url );
85108 }
86109
87- public function patch ($ url ,$ data )
110+ public function patch ($ url , $ data )
88111 {
89- return $ this ->action ('PATCH ' ,$ url ,$ data );
112+ return $ this ->action ('PATCH ' , $ url , $ data );
90113 }
91114
92115 public function expectAny ()
@@ -97,7 +120,7 @@ public function expectAny()
97120 return $ this ;
98121 }
99122
100- public function expect ($ output ,$ error =false )
123+ public function expect ($ output , $ error =false )
101124 {
102125 $ exception = false ;
103126 ob_start ();
@@ -108,8 +131,11 @@ public function expect($output,$error=false)
108131 }
109132 $ data = ob_get_contents ();
110133 ob_end_clean ();
111- if ($ exception ) $ this ->test ->assertEquals ($ error , $ exception );
112- else $ this ->test ->assertEquals ($ output , $ data );
134+ if ($ exception ) {
135+ $ this ->test ->assertEquals ($ error , $ exception );
136+ } else {
137+ $ this ->test ->assertEquals ($ output , $ data );
138+ }
113139 return $ this ;
114140 }
115- }
141+ }
0 commit comments