1010 * class for default config handler test
1111 *
1212 * @runTestsInSeparateProcess
13- * @preserveGlobalState disabled
13+ * @preserveGlobalState disabled
1414 * @backupStaticAttributes enabled
1515 */
1616class DefaultConfigHandlerTest extends PHPUnit_Smarty
@@ -29,9 +29,8 @@ public function setUp()
2929
3030 /**
3131 * @expectedException SmartyException
32- * @expectedExceptionMessage Unable to read
33- * @expectedExceptionMessage file 'foo.conf'
34- *
32+ * @expectedExceptionMessage Unable to load config 'file:foo.conf'
33+ *
3534 * test unknown config file
3635 */
3736 public function testUnknownConfigFile ()
@@ -54,7 +53,7 @@ public function testRegisterUnknownDefaultConfigHandler()
5453
5554 /**
5655 * test default config handler replacement (config data)
57- *
56+ *
5857 * @throws \Exception
5958 * @throws \SmartyException
6059 */
@@ -80,21 +79,49 @@ public function testDefaultConfigHandlerReplacementByConfigFile()
8079
8180 /**
8281 * @expectedException SmartyException
83- * @expectedExceptionMessage Unable to read
84- * @expectedExceptionMessage file 'foo.conf'
85- *
82+ * @expectedExceptionMessage Unable to load config default file 'no.conf' for 'file:fo.conf'
83+ *
84+ *
85+ */
86+ public function testDefaultConfigHandlerReplacementByConfigFileFail ()
87+ {
88+ $ this ->smarty ->registerDefaultConfigHandler ('configHandlerFile ' );
89+ $ this ->smarty ->configLoad ('fo.conf ' );
90+ $ this ->assertEquals ("123.4 " , $ this ->smarty ->fetch ('eval:{#Number#} ' ));
91+ }
92+
93+ /**
94+ * @expectedException SmartyException
95+ * @expectedExceptionMessage Unable to load config 'file:foo.conf'
96+ *
97+ *
8698 * test default config handler replacement (return false)
8799 *
88100 */
89101 public function testDefaultConfigHandlerReplacementReturningFalse ()
90102 {
91- $ this ->smarty ->configLoad ('foo.conf ' );
103+ $ this ->smarty ->configLoad ('foo.conf ' );
92104 }
105+
106+ /**
107+ * @expectedException SmartyException
108+ * @expectedExceptionMessage No config default content for 'file:bla.conf'
109+ *
110+ *
111+ * test default config handler replacement (return false)
112+ *
113+ */
114+ public function testDefaultConfigHandlerReplacementReturningFalse1 ()
115+ {
116+ $ this ->smarty ->registerDefaultConfigHandler ('configHandlerData ' );
117+ $ this ->smarty ->configLoad ('bla.conf ' );
118+ }
119+
93120}
94121
95122/**
96123 * config handler returning config data
97- *
124+ *
98125 * @param $resource_type
99126 * @param $resource_name
100127 * @param $config_source
@@ -105,6 +132,9 @@ public function testDefaultConfigHandlerReplacementReturningFalse()
105132 */
106133function configHandlerData ($ resource_type , $ resource_name , &$ config_source , &$ config_timestamp , Smarty $ smarty )
107134{
135+ if ($ resource_name !== 'foo.conf ' ) {
136+ return false ;
137+ }
108138 $ output = "foo = 'bar' \n" ;
109139 $ config_source = $ output ;
110140 $ config_timestamp = time ();
@@ -114,7 +144,7 @@ function configHandlerData($resource_type, $resource_name, &$config_source, &$co
114144
115145/**
116146 * config handler returning config file
117- *
147+ *
118148 * @param $resource_type
119149 * @param $resource_name
120150 * @param $config_source
@@ -125,12 +155,16 @@ function configHandlerData($resource_type, $resource_name, &$config_source, &$co
125155 */
126156function configHandlerFile ($ resource_type , $ resource_name , &$ config_source , &$ config_timestamp , Smarty $ smarty )
127157{
158+ if ($ resource_name !== 'foo.conf ' ) {
159+ return 'no.conf ' ;
160+ }
161+
128162 return $ smarty ->getConfigDir (0 ) . 'test.conf ' ;
129163}
130164
131165/**
132166 * config handler returning false
133- *
167+ *
134168 * @param $resource_type
135169 * @param $resource_name
136170 * @param $config_source
0 commit comments