diff --git a/tests/unit/modules/calendar.php b/tests/unit/modules/calendar.php deleted file mode 100644 index f326b5cb..00000000 --- a/tests/unit/modules/calendar.php +++ /dev/null @@ -1,52 +0,0 @@ -path_helper = new \phpbb\path_helper( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - new \phpbb\filesystem(), - $phpbb_root_path, - 'php' - ); - $this->calendar = new \board3\portal\modules\calendar(array(), null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper); - $this->offset = strtotime('17.06.1990') - 645580800; - } - - public function data_date_to_time() - { - return array( - array(1402855200, '2014-06-15 18:00'), - array(1402855200, '15.06.2014 18:00'), - array(1402855200, '06/15/2014 6:00 PM'), - array(false, '15/06'), - ); - } - - /** - * @dataProvider data_date_to_time - */ - public function test_date_to_time($expected, $date) - { - $this->assertEquals($expected, $this->calendar->date_to_time($date) + $this->offset); - } - -} diff --git a/tests/unit/modules/calendar_test.php b/tests/unit/modules/calendar_test.php new file mode 100644 index 00000000..7a620a5c --- /dev/null +++ b/tests/unit/modules/calendar_test.php @@ -0,0 +1,121 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml'); + } + + public function setUp() + { + parent::setUp(); + global $cache, $phpbb_root_path; + + $this->path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new \phpbb_mock_request() + ), + new \phpbb\filesystem(), + $phpbb_root_path, + 'php' + ); + self::$config = new \phpbb\config\config(array()); + $this->calendar = new \board3\portal\modules\calendar(array(), null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper); + $this->offset = strtotime('17.06.1990') - 645573600; + define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules'); + define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config'); + $cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put')); + $cache->expects($this->any()) + ->method('destroy') + ->with($this->equalTo('portal_config')); + $cache->expects($this->any()) + ->method('get') + ->with($this->anything()) + ->will($this->returnValue(false)); + $cache->expects($this->any()) + ->method('sql_exists') + ->with($this->anything()); + $cache->expects($this->any()) + ->method('put') + ->with($this->anything()); + } + + public function data_date_to_time() + { + return array( + array(1402848000, '2014-06-15 18:00'), + array(1402848000, '15.06.2014 18:00'), + array(1402848000, '06/15/2014 6:00 PM'), + array(false, '15/06'), + ); + } + + /** + * @dataProvider data_date_to_time + */ + public function test_date_to_time($expected, $date) + { + $this->assertEquals($expected, $this->calendar->date_to_time($date) + $this->offset); + } + + public function test_install() + { + $this->assertTrue($this->calendar->install(1)); + + foreach (self::$config as $key => $value) + { + $this->expected_config[$key] = $value; + } + + $portal_config = obtain_portal_config(); + + foreach ($portal_config as $key => $value) + { + $this->expected_portal_config[$key] = $value; + } + } + + /** + * @dependsOn test_install + */ + public function test_uninstall() + { + $this->assertTrue($this->calendar->uninstall(1, $this->db)); + + foreach ($this->expected_config as $key => $value) + { + $this->assertFalse(isset(self::$config[$key])); + } + + $portal_config = obtain_portal_config(); + + foreach ($this->expected_config as $key => $value) + { + $this->assertFalse(isset($portal_config[$key])); + } + } +} + +function set_config($config_name, $config_value, $is_dynamic = false) +{ + phpbb_unit_modules_calendar_test::$config->set($config_name, $config_value, !$is_dynamic); +} diff --git a/tests/unit/modules/fixtures/configs.xml b/tests/unit/modules/fixtures/configs.xml new file mode 100644 index 00000000..5173d042 --- /dev/null +++ b/tests/unit/modules/fixtures/configs.xml @@ -0,0 +1,11 @@ + + + + config_name + config_value +
+ + config_name + config_value +
+