コード例 #1
0
 /**
  * resets the init code to the base config file
  */
 public static function clear_init_code()
 {
     self::$init_code = array();
     self::$vars = array();
     self::$silverstripe_db_included = false;
     if (self::$base_init_code) {
         array_unshift(self::$init_code, self::$base_init_code);
     }
 }
コード例 #2
0
 /**
  * tests the functionality related to the init code
  */
 public function testInitCode()
 {
     LivePubHelper::$vars = array();
     LivePubHelper::init_pub();
     // after this is called, there should be one entry - the base_init_code
     LivePubHelper::clear_init_code();
     $this->assertEquals(count(LivePubHelper::$init_code), 1);
     $this->assertEquals(LivePubHelper::get_init_code(), LivePubHelper::$base_init_code . "\n");
     // try a few things to make sure the php tags are added appropriately
     LivePubHelper::$init_code = array('test');
     $this->assertEquals("<?php test ?>\n", LivePubHelper::get_init_code());
     LivePubHelper::$init_code = array('<?php test');
     $this->assertEquals("<?php test ?>\n", LivePubHelper::get_init_code());
     LivePubHelper::$init_code = array('test ?>');
     $this->assertEquals("<?php test ?>\n", LivePubHelper::get_init_code());
     LivePubHelper::$init_code = array('<?php test ?>');
     $this->assertEquals("<?php test ?>\n", LivePubHelper::get_init_code());
     LivePubHelper::$init_code = array();
     $this->assertEquals("", LivePubHelper::get_init_code());
     // test variables
     LivePubHelper::$vars = array('a' => "'b'", 'b' => true, 'c' => "4");
     $this->assertEquals("\n<?php\n\$a = 'b';\n\$c = 4;\n\n?>\n", LivePubHelper::get_init_code());
     LivePubHelper::stop_pub();
 }