1+ <?php
2+
3+ /**
4+ *
5+ * @package testing
6+ * @copyright (c) 2015 phpBB.de, gn#36
7+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8+ *
9+ */
10+
11+ class phpbbde_cron_main_test extends phpbb_database_test_case
12+ {
13+ static protected function setup_extensions ()
14+ {
15+ return array ('phpbbde/pastebin ' );
16+ }
17+
18+ public function getDataSet ()
19+ {
20+ return $ this ->createXMLDataSet (dirname (__FILE__ ) . '/fixtures/three_pastebin_entries.xml ' );
21+ }
22+
23+ public function setUp ()
24+ {
25+ parent ::setUp ();
26+
27+ $ this ->cache = $ this ->getMockBuilder ('\phpbb\cache\service ' )->disableOriginalConstructor ()->getMock ();
28+ $ this ->log = $ this ->getMockBuilder ('\phpbb\log\log ' )->disableOriginalConstructor ()->getMock ();
29+ }
30+
31+ public function test_construct ()
32+ {
33+ $ task = $ this ->get_task ();
34+ $ this ->assertInstanceOf ('\phpbb\cron\task\base ' , $ task );
35+ }
36+
37+ public function test_is_runnable ()
38+ {
39+ $ task = $ this ->get_task ();
40+ $ this ->assertTrue ($ task ->is_runnable ());
41+ }
42+
43+ public function test_should_run ()
44+ {
45+ // 1: Has not run ever
46+ $ task = $ this ->get_task ();
47+ $ this ->assertTrue ($ task ->should_run ());
48+
49+ // 2: Has just run
50+ $ task = $ this ->get_task (time () - 1 );
51+ $ this ->assertTrue (!$ task ->should_run ());
52+ }
53+
54+ public function test_run ()
55+ {
56+ $ task = $ this ->get_task ();
57+ $ task ->run ();
58+ $ sql = 'SELECT count(*) as cnt FROM phpbb_pastebin ' ;
59+
60+ $ result = $ this ->db ->sql_query ($ sql );
61+ $ row = $ this ->db ->sql_fetchrow ($ result );
62+ $ this ->db ->sql_freeresult ($ result );
63+ $ this ->assertEquals ($ row ['cnt ' ], 2 );
64+
65+ $ sql = 'SELECT snippet_id FROM phpbb_pastebin ' ;
66+ $ result = $ this ->db ->sql_query ($ sql );
67+ $ rows = $ this ->db ->sql_fetchrowset ($ result );
68+ $ this ->db ->sql_freeresult ($ result );
69+ $ this ->assertEquals ($ rows , array (array ('snippet_id ' => 1 ), array ('snippet_id ' => 3 )));
70+ }
71+
72+ private function get_task ($ last_run = 0 )
73+ {
74+ global $ phpbb_root_path , $ phpEx ;
75+ $ pastebin_path = dirname (__FILE__ ) . '/../../ ' ;
76+ $ db = $ this ->new_dbal ();
77+ $ this ->db = $ db ;
78+
79+ $ this ->config = new \phpbb \config \config (array (
80+ 'phpbbde_pastebin_prune_last_run ' => $ last_run ,
81+ 'phpbbde_pastebin_version ' => '0.2.2 ' ,
82+ ));
83+
84+ return new \phpbbde \pastebin \cron \main ($ this ->cache , $ this ->config , $ db , $ this ->log , $ pastebin_path , $ phpbb_root_path , $ phpEx , 86400 , 'phpbb_pastebin ' );
85+ }
86+ }
0 commit comments