From 5ab4dc298327d3a8d51387959d6905c6bb24fd99 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 5 Mar 2011 22:16:50 +0100 Subject: [ticket/10042] Add mt_rand() wrapper which allows swapping $min and $max. PHPBB3-10042 --- tests/random/mt_rand.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/random/mt_rand.php (limited to 'tests') diff --git a/tests/random/mt_rand.php b/tests/random/mt_rand.php new file mode 100644 index 0000000000..d6502c4e80 --- /dev/null +++ b/tests/random/mt_rand.php @@ -0,0 +1,46 @@ +assertEquals(42, $result); + } + + public function test_max_equals_min_negative() + { + $result = phpbb_mt_rand(-42, -42); + $this->assertEquals(-42, $result); + } + + public function test_max_greater_min() + { + $result = phpbb_mt_rand(3, 4); + $this->assertGreaterThanOrEqual(3, $result); + $this->assertLessThanOrEqual(4, $result); + } + + public function test_min_greater_max() + { + $result = phpbb_mt_rand(4, 3); + $this->assertGreaterThanOrEqual(3, $result); + $this->assertLessThanOrEqual(4, $result); + } + + public function test_min_greater_max_negative() + { + $result = phpbb_mt_rand(-3, -4); + $this->assertGreaterThanOrEqual(-4, $result); + $this->assertLessThanOrEqual(-3, $result); + } +} -- cgit v1.2.1 From 4b646c6c80712bbbc0737defc48f6fbb05bac0f3 Mon Sep 17 00:00:00 2001 From: "Marek A. Ruszczynski" Date: Mon, 7 Mar 2011 16:52:22 +0100 Subject: [feature/template-engine] Update tests. PHPBB3-9726 --- tests/template/template_test.php | 37 +++++++++++++++++++++---------- tests/template/templates/expressions.html | 29 ------------------------ tests/template/templates/if.html | 4 ++-- tests/template/templates/loop_nested.html | 2 -- tests/template/templates/loop_vars.html | 13 +++-------- 5 files changed, 30 insertions(+), 55 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 62f94f7d32..44f0ad2640 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_test extends phpbb_test_case private $template_path; // Keep the contents of the cache for debugging? - const PRESERVE_CACHE = false; + const PRESERVE_CACHE = true; private function display($handle) { @@ -39,7 +39,7 @@ class phpbb_template_template_test extends phpbb_test_case protected function setUp() { - $this->markTestIncomplete("template::display raises notices."); +// $this->markTestIncomplete("template::display raises notices."); // Test the engine can be used $this->setup_engine(); @@ -105,14 +105,14 @@ class phpbb_template_template_test extends phpbb_test_case array(), array(), array(), - '0', + '03', ), array( 'if.html', array('S_VALUE' => true), array(), array(), - "1\n0", + '1', ), array( 'if.html', @@ -161,22 +161,22 @@ class phpbb_template_template_test extends phpbb_test_case array(), array('loop' => array(array('VARIABLE' => 'x'))), array(), - "first\n0\nx\nset\nlast", - ),/* no nested top level loops + "first\n0 - a\nx - b\nset\nlast", + ), array( 'loop_vars.html', array(), array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), array(), - "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast", + "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast", ), array( 'loop_vars.html', array(), array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array(), - "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast\n0\n\n1\nlast inner\ninner loop", - ),*/ + "first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner\ninner loop", + ), array( 'loop_advanced.html', array(), @@ -196,7 +196,16 @@ class phpbb_template_template_test extends phpbb_test_case array(), array(), array(), - trim(str_repeat("pass", 39)), + trim(str_repeat("pass\n", 10) . "\n" + . str_repeat("pass\n", 4) . "\n" + . str_repeat("pass\n", 2) . "\n" + . str_repeat("pass\n", 6) . "\n" + . str_repeat("pass\n", 2) . "\n" + . str_repeat("pass\n", 6) . "\n" + . str_repeat("pass\n", 2) . "\n" + . str_repeat("pass\n", 2) . "\n" + . str_repeat("pass\n", 3) . "\n" + . str_repeat("pass\n", 2) . "\n"), ), array( 'php.html', @@ -258,7 +267,7 @@ class phpbb_template_template_test extends phpbb_test_case $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); $expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path . '/../') . '/templates/' . $filename); - $this->setExpectedTriggerError(E_USER_ERROR, $expecting); + // $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); } @@ -308,9 +317,12 @@ class phpbb_template_template_test extends phpbb_test_case { copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); } - throw $e; } + // TODO: Figure out why this wasn't considered. + catch (Exception $e) + { + } // For debugging if (self::PRESERVE_CACHE) @@ -507,5 +519,6 @@ EOT $this->template->alter_block_array($alter_block, $vararray, $key, $mode); $this->assertEquals($expect, $this->display('test'), $description); } + } diff --git a/tests/template/templates/expressions.html b/tests/template/templates/expressions.html index c40d967dab..e1283f165f 100644 --- a/tests/template/templates/expressions.html +++ b/tests/template/templates/expressions.html @@ -1,86 +1,57 @@ passfail - failpass - failpass - passfail - failpass - passfail - failpass - passfail - passfail - passfail passfail - passfail - passfail - passfail passfail - passfail passfail - passfail - passfail - passfail - passfail - passfail passfail - passfail passfail - passfail - passfail - passfail - passfail - passfail passfail - passfail passfail - passfail passfail - passfail - passfail passfail - passfail diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index c502e52f51..41ff024779 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -3,9 +3,9 @@ 2 -0 +03 -0 +04 diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html index 9b251cd453..45b1ef85d4 100644 --- a/tests/template/templates/loop_nested.html +++ b/tests/template/templates/loop_nested.html @@ -1,8 +1,6 @@ outer - {outer.S_ROW_COUNT} - {outer.VARIABLE} - middle - {middle.S_ROW_COUNT} - {middle.VARIABLE} - diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html index 4f02fd2e6c..d94a0ae0f7 100644 --- a/tests/template/templates/loop_vars.html +++ b/tests/template/templates/loop_vars.html @@ -1,21 +1,14 @@ first - -{loop.S_ROW_COUNT} - -{loop.VARIABLE} - +{loop.S_ROW_NUM} - a +{loop.VARIABLE} - b set - last - -{inner.S_ROW_COUNT} - +{inner.S_ROW_NUM} - c last inner - inner loop -- cgit v1.2.1 From 4dfe4c7f13ac8177dac5eb73cd3535d3c651bd75 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 00:13:19 -0400 Subject: [feature/template-engine] Adjust path in includephp template. Now that tests are run from top level the '..' is wrong. PHPBB3-9726 --- tests/template/templates/includephp.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp.html index 70ebdac0d0..0a8c1a070c 100644 --- a/tests/template/templates/includephp.html +++ b/tests/template/templates/includephp.html @@ -1 +1 @@ - + -- cgit v1.2.1 From 203187a8410c411b0bdd90729e19c257ec3a7820 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 00:22:41 -0400 Subject: [feature/template-engine] Fix recompilation logic. Do not change $recompile from true to false - any recompilation condition alone is sufficient to force recompilation. Also uncomment the nonexistent file test which passes with this fix. PHPBB3-9726 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 44f0ad2640..665b7a81ab 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -267,7 +267,7 @@ class phpbb_template_template_test extends phpbb_test_case $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); $expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path . '/../') . '/templates/' . $filename); - // $this->setExpectedTriggerError(E_USER_ERROR, $expecting); + $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); } -- cgit v1.2.1 From f29f32e0d67e88a271702264c37852406f4013d8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 00:44:19 -0400 Subject: [feature/template-engine] Allow leading underscores in variable names. Subsilver uses ._file in overall_header. PHPBB3-9726 --- tests/template/template_test.php | 9 +++++++++ tests/template/templates/loop_underscore.html | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/template/templates/loop_underscore.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 665b7a81ab..a7c49927f1 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -235,6 +235,15 @@ class phpbb_template_template_test extends phpbb_test_case array('loop.inner'), "first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast", ),*/ + array( + // Just like a regular loop but the name begins + // with an underscore + 'loop_underscore.html', + array(), + array(), + array(), + "noloop\nnoloop", + ), array( 'lang.html', array(), diff --git a/tests/template/templates/loop_underscore.html b/tests/template/templates/loop_underscore.html new file mode 100644 index 0000000000..dafce5dea6 --- /dev/null +++ b/tests/template/templates/loop_underscore.html @@ -0,0 +1,21 @@ + +loop + +noloop + + + +loop + +noloop + + + +loop + + + + +loop#{loop.S_ROW_COUNT}-block#{block.S_ROW_COUNT} + + -- cgit v1.2.1 From a2c75f60537ccf6a424c7f066eafbffc13c0c38d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 21:18:18 -0400 Subject: [feature/template-engine] Deleted $template from phpbb_template_compile class. phpbb_template_compile is now much simpler. It takes complete file paths as inputs, either source template path or source template path and output compiled template path. The number of methods also went down to two - compile template and returned compiled text or compile and write to file. phpbb_compile class is responsible for determining source and compiled paths. It already had all the data necessary for this, now the code is in the same place as the data it uses. PHPBB3-9726 --- tests/template/template_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index a7c49927f1..e549c9a0c8 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -275,7 +275,7 @@ class phpbb_template_template_test extends phpbb_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path . '/../') . '/templates/' . $filename); + $expecting = sprintf('_source_file_for_handle(): File %s does not exist', realpath($this->template_path . '/../') . '/templates/' . $filename); $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); @@ -530,4 +530,3 @@ EOT } } - -- cgit v1.2.1 From 5c3ebb3465eee36f9147a517d4f50f4032cd04d5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 21:22:43 -0400 Subject: [feature/template-engine] Deleted silencing of notices. The code is now supposed to be notice-free, therefore there is no need to have the notices silenced. PHPBB3-9726 --- tests/template/template_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index e549c9a0c8..b81a2a6152 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -381,14 +381,14 @@ class phpbb_template_template_test extends phpbb_test_case $this->template->destroy_block_vars($block); } - $error_level = error_reporting(); - error_reporting($error_level & ~E_NOTICE); + //$error_level = error_reporting(); + //error_reporting($error_level & ~E_NOTICE); $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)"); $this->template->assign_display('test', 'VARIABLE', false); - error_reporting($error_level); + //error_reporting($error_level); $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); } -- cgit v1.2.1 From e10d62badc2653d53f326cc1a3b8ab00617bc736 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 21:56:26 -0400 Subject: [feature/template-engine] Added a test for multilevel references in loops. This currently fails. This test is a reduced version of permission_mask template in acp, which is not correctly compiled by the current template engine code. PHPBB3-9726 --- tests/template/template_test.php | 14 ++++++++++++++ tests/template/templates/loop_nested_multilevel_ref.html | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/template/templates/loop_nested_multilevel_ref.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index b81a2a6152..6ac2f77a2c 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -265,6 +265,20 @@ class phpbb_template_template_test extends phpbb_test_case array(), "{ VARIABLE }\nValue'", ), + array( + 'loop_nested_multilevel_ref.html', + array(), + array(), + array(), + "top-level content", + ), + array( + 'loop_nested_multilevel_ref.html', + array(), + array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), + array(), + "top-level content", + ), ); } diff --git a/tests/template/templates/loop_nested_multilevel_ref.html b/tests/template/templates/loop_nested_multilevel_ref.html new file mode 100644 index 0000000000..00a199caee --- /dev/null +++ b/tests/template/templates/loop_nested_multilevel_ref.html @@ -0,0 +1,10 @@ +top-level content + + outer content + + inner content + + first row + + + -- cgit v1.2.1 From 5afc0b9b905814718ed0292fa5cc7342786c1fca Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Apr 2011 22:46:34 -0400 Subject: [feature/template-engine] Corrected an off-by-one error in nested namespaces. This error resulted in a dot from the namespace being placed into variable reference in compiled template code, thus creating bogus compiled template code. PHPBB3-9726 --- tests/template/template_test.php | 11 ++++++++++- .../template/templates/loop_nested_deep_multilevel_ref.html | 12 ++++++++++++ tests/template/templates/loop_nested_multilevel_ref.html | 4 ++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/template/templates/loop_nested_deep_multilevel_ref.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 6ac2f77a2c..5c43fe656e 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -277,7 +277,16 @@ class phpbb_template_template_test extends phpbb_test_case array(), array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), array(), - "top-level content", + // I don't completely understand this output, hopefully it's correct + "top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz", + ), + array( + 'loop_nested_deep_multilevel_ref.html', + array(), + array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), + array(), + // I don't completely understand this output, hopefully it's correct + "top-level content\nouter\n\ninner z\nfirst row\n\ninner zz", ), ); } diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref.html b/tests/template/templates/loop_nested_deep_multilevel_ref.html new file mode 100644 index 0000000000..60fad7b4cd --- /dev/null +++ b/tests/template/templates/loop_nested_deep_multilevel_ref.html @@ -0,0 +1,12 @@ +top-level content + + outer + + + inner {inner.VARIABLE} + + first row + + + + diff --git a/tests/template/templates/loop_nested_multilevel_ref.html b/tests/template/templates/loop_nested_multilevel_ref.html index 00a199caee..f2f1c746ed 100644 --- a/tests/template/templates/loop_nested_multilevel_ref.html +++ b/tests/template/templates/loop_nested_multilevel_ref.html @@ -1,8 +1,8 @@ top-level content - outer content + outer {outer.VARIABLE} - inner content + inner {inner.VARIABLE} first row -- cgit v1.2.1 From f97411b91143a0c75ef0ecec3ff03fc36a879728 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 25 Apr 2011 13:03:55 -0400 Subject: [feature/template-engine] Corrected miscompilation of loop size constructs. PHPBB3-9726 --- tests/template/template_test.php | 7 ++++++ tests/template/templates/loop_size.html | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/template/templates/loop_size.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 5c43fe656e..5a21d2f69c 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -288,6 +288,13 @@ class phpbb_template_template_test extends phpbb_test_case // I don't completely understand this output, hopefully it's correct "top-level content\nouter\n\ninner z\nfirst row\n\ninner zz", ), + array( + 'loop_size.html', + array(), + array('loop' => array(array()), 'empty_loop' => array()), + array(), + "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", + ), ); } diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html new file mode 100644 index 0000000000..f1938441df --- /dev/null +++ b/tests/template/templates/loop_size.html @@ -0,0 +1,39 @@ + + nonexistent + + + + nonexistent = 0 + + + + ! nonexistent + + + + empty + + + + empty = 0 + + + + ! empty + + + + loop + + + + loop = 0 + + + + ! loop + + + + in loop + -- cgit v1.2.1 From f0b97cfdcf851eec4660412e4c061a26b921c740 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 25 Apr 2011 21:45:10 -0400 Subject: [feature/template-engine] Added a test for reuse of loop identifiers. This currently does not pass, thus it is commented out. The reuse appears implausible in the same file, however it may be also done across template files where it is much harder to detect. PHPBB3-9726 --- tests/template/template_test.php | 10 ++++++++++ tests/template/templates/loop_reuse.html | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/template/templates/loop_reuse.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 5a21d2f69c..4304035192 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -295,6 +295,16 @@ class phpbb_template_template_test extends phpbb_test_case array(), "nonexistent = 0\n! nonexistent\n\nempty = 0\n! empty\nloop\n\nin loop", ), + /* Does not pass with the current implementation. + array( + 'loop_reuse.html', + array(), + array('one' => array(array('VAR' => 'a'), array('VAR' => 'b')), 'one.one' => array(array('VAR' => 'c'), array('VAR' => 'd'))), + array(), + // Not entirely sure what should be outputted but the current output of "a" is most certainly wrong + "a\nb\nc\nd", + ), + */ ); } diff --git a/tests/template/templates/loop_reuse.html b/tests/template/templates/loop_reuse.html new file mode 100644 index 0000000000..bd0354ae6f --- /dev/null +++ b/tests/template/templates/loop_reuse.html @@ -0,0 +1,6 @@ + + {one.VAR} + + {one.one.VAR} + + -- cgit v1.2.1 From 427a5122d55f06c861277297411f7e39a03a703c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 26 Apr 2011 02:09:51 +0200 Subject: [feature/template-engine] Fix negative variable expressions compile_tag_if had the flawed approach of adding an isset statement for all variables to the beginning of the if. This fails for negative expressions, and checking those takes a considerable effort. The easier solution is to make the variable expression itself conditional, defaulting to null if it is not set. Thanks to naderman for the solution. PHPBB3-9726 --- tests/template/template_test.php | 2 +- tests/template/templates/basic.html | 3 +++ tests/template/templates/if.html | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 4304035192..0a46ff4d23 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -91,7 +91,7 @@ class phpbb_template_template_test extends phpbb_test_case array(), array(), array(), - "pass\npass\n", + "pass\npass\npass\n", ), array( 'variable.html', diff --git a/tests/template/templates/basic.html b/tests/template/templates/basic.html index c1dd690260..e5c6f280fb 100644 --- a/tests/template/templates/basic.html +++ b/tests/template/templates/basic.html @@ -16,5 +16,8 @@ fail pass + +pass + diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html index 41ff024779..eed431019e 100644 --- a/tests/template/templates/if.html +++ b/tests/template/templates/if.html @@ -6,6 +6,6 @@ 03 - + 04 -- cgit v1.2.1 From b884573c1d322b207f9dcbcbc02806eed408fbab Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 1 May 2011 03:11:13 -0400 Subject: [feature/template-engine] Relax missing file exception check. As long as the exception message has the correct description and file name we should not care which function raised the exception. PHPBB3-9726 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0a46ff4d23..cb9563150a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -331,7 +331,7 @@ class phpbb_template_template_test extends phpbb_test_case public function test_invalid_handle() { - $expecting = 'template->_tpl_load(): No file specified for handle test'; + $expecting = 'No file specified for handle test'; $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); -- cgit v1.2.1 From 2aec6bb07cee438709e569b1cb3733ff3c9170b2 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 1 May 2011 03:12:23 -0400 Subject: [feature/template-engine] Only copy files to cache if they exist. When testing eval code path, compiled templates may not be written to the file system, and unconditionally trying to copy them breaks tests. PHPBB3-9726 --- tests/template/template_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index cb9563150a..e530b0f4e6 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -373,8 +373,9 @@ class phpbb_template_template_test extends phpbb_test_case { } - // For debugging - if (self::PRESERVE_CACHE) + // For debugging. + // When testing eval path the cache file may not exist. + if (self::PRESERVE_CACHE && file_exists($cache_file)) { copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); } -- cgit v1.2.1 From 87832d06cca520e27c5dbed1c36ab9c12240ae3d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 1 May 2011 04:03:06 -0400 Subject: [feature/template-engine] Delete template class, use phpbb_template instead. PHPBB3-9726 --- tests/template/template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index e530b0f4e6..5692fcf06f 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -33,7 +33,7 @@ class phpbb_template_template_test extends phpbb_test_case private function setup_engine() { $this->template_path = dirname(__FILE__) . '/templates'; - $this->template = new template(); + $this->template = new phpbb_template(); $this->template->set_custom_template($this->template_path, 'tests'); } -- cgit v1.2.1 From 0462ab3a4a5cea64699eaf4b2e9900e36d027e50 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 9 May 2011 22:00:38 -0400 Subject: [feature/template-engine] Add back IN_PHPBB preamble. PHPBB3-9726 --- tests/template/template_compile_test.php | 32 ++++++++++++++++++++++++++++++++ tests/template/templates/trivial.html | 1 + 2 files changed, 33 insertions(+) create mode 100644 tests/template/template_compile_test.php create mode 100644 tests/template/templates/trivial.html (limited to 'tests') diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php new file mode 100644 index 0000000000..2f12292870 --- /dev/null +++ b/tests/template/template_compile_test.php @@ -0,0 +1,32 @@ +template_compile = new phpbb_template_compile(); + $this->template_path = dirname(__FILE__) . '/templates'; + } + + public function test_in_phpbb() + { + $output = $this->template_compile->compile_file($this->template_path . '/trivial.html'); + $this->assertTrue(strlen($output) > 0); + $statements = explode(';', $output); + $first_statement = $statements[0]; + $this->assertTrue(!!preg_match('#if.*defined.*IN_PHPBB.*exit#', $first_statement)); + } +} diff --git a/tests/template/templates/trivial.html b/tests/template/templates/trivial.html new file mode 100644 index 0000000000..3a1c1c5324 --- /dev/null +++ b/tests/template/templates/trivial.html @@ -0,0 +1 @@ +This is a trivial template. -- cgit v1.2.1 From ac9a910c64c13d7a12cd7b0746956afa468c29db Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 11 May 2011 21:13:37 -0400 Subject: [feature/template-engine] Delete obsolete comments pertaining to notices. PHPBB3-9726 --- tests/template/template_test.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 5692fcf06f..0922599d74 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -39,8 +39,6 @@ class phpbb_template_template_test extends phpbb_test_case protected function setUp() { -// $this->markTestIncomplete("template::display raises notices."); - // Test the engine can be used $this->setup_engine(); @@ -422,15 +420,10 @@ class phpbb_template_template_test extends phpbb_test_case $this->template->destroy_block_vars($block); } - //$error_level = error_reporting(); - //error_reporting($error_level & ~E_NOTICE); - $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)"); $this->template->assign_display('test', 'VARIABLE', false); - //error_reporting($error_level); - $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); } -- cgit v1.2.1 From 581374c9c3c3429f0a07c19e3c8de81fd3e6f320 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 12 May 2011 09:59:17 -0400 Subject: [feature/template-engine] Deleted useless catch. In tests there is no need to catch unexpected exceptions. PHPBB3-9726 --- tests/template/template_test.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0922599d74..0553132484 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -366,10 +366,6 @@ class phpbb_template_template_test extends phpbb_test_case } throw $e; } - // TODO: Figure out why this wasn't considered. - catch (Exception $e) - { - } // For debugging. // When testing eval path the cache file may not exist. -- cgit v1.2.1 From d2ac05aa74d3a1c9723be41a4c0ffe86542f223f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 12 May 2011 18:08:36 -0400 Subject: [feature/template-engine] Replaced globals with dependency injection. PHPBB3-9726 --- tests/template/template_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0553132484..9b4023c62c 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -32,8 +32,10 @@ class phpbb_template_template_test extends phpbb_test_case private function setup_engine() { + global $phpbb_root_path, $phpEx, $config, $user; + $this->template_path = dirname(__FILE__) . '/templates'; - $this->template = new phpbb_template(); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); $this->template->set_custom_template($this->template_path, 'tests'); } -- cgit v1.2.1 From 94560d708649df876f8486d4ba5361475037f1ff Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 12 May 2011 20:09:41 -0400 Subject: [feature/template-engine] Make INCLUDEPHP relative to board root. PHPBB3-9726 --- tests/template/template_test.php | 10 +++++----- tests/template/templates/includephp.html | 1 - tests/template/templates/includephp_relative.html | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 tests/template/templates/includephp.html create mode 100644 tests/template/templates/includephp_relative.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 9b4023c62c..a9850cd5ef 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -438,16 +438,16 @@ class phpbb_template_template_test extends phpbb_test_case $GLOBALS['config']['tpl_allow_php'] = false; } - public function test_includephp() + public function test_includephp_relative() { $GLOBALS['config']['tpl_allow_php'] = true; - $cache_file = $this->template->cachepath . 'includephp.html.php'; + $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - $this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file); + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); - $this->template->set_filenames(array('test' => 'includephp.html')); - $this->assertEquals('testing included php', $this->display('test'), "Testing INCLUDEPHP"); + $this->template->set_filenames(array('test' => 'includephp_relative.html')); + $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); $GLOBALS['config']['tpl_allow_php'] = false; } diff --git a/tests/template/templates/includephp.html b/tests/template/templates/includephp.html deleted file mode 100644 index 0a8c1a070c..0000000000 --- a/tests/template/templates/includephp.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/template/templates/includephp_relative.html b/tests/template/templates/includephp_relative.html new file mode 100644 index 0000000000..297c9efcb0 --- /dev/null +++ b/tests/template/templates/includephp_relative.html @@ -0,0 +1,2 @@ +Path is relative to board root. + -- cgit v1.2.1 From be8fc0864c005e7240ba28b24de317a969c7f9b6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 13 May 2011 10:46:10 -0400 Subject: [feature/template-engine] Added a test for inclusion of php files from subdir. PHPBB3-9726 --- .../subdir/includephp_from_subdir_test.php | 33 ++++++ tests/template/template_test.php | 102 +------------------ tests/template/template_test_case.php | 113 +++++++++++++++++++++ 3 files changed, 148 insertions(+), 100 deletions(-) create mode 100644 tests/template/subdir/includephp_from_subdir_test.php create mode 100644 tests/template/template_test_case.php (limited to 'tests') diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php new file mode 100644 index 0000000000..7bfd852d9e --- /dev/null +++ b/tests/template/subdir/includephp_from_subdir_test.php @@ -0,0 +1,33 @@ +template->cachepath . 'includephp_relative.html.php'; + + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); + + $this->template->set_filenames(array('test' => 'includephp_relative.html')); + $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); + + $GLOBALS['config']['tpl_allow_php'] = false; + } +} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index a9850cd5ef..09f0de3046 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -9,68 +9,10 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/template.php'; +require_once dirname(__FILE__) . '/template_test_case.php'; -class phpbb_template_template_test extends phpbb_test_case +class phpbb_template_template_test extends phpbb_template_template_test_case { - private $template; - private $template_path; - - // Keep the contents of the cache for debugging? - const PRESERVE_CACHE = true; - - private function display($handle) - { - ob_start(); - $this->assertTrue($this->template->display($handle, false)); - return self::trim_template_result(ob_get_clean()); - } - - private static function trim_template_result($result) - { - return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result))))); - } - - private function setup_engine() - { - global $phpbb_root_path, $phpEx, $config, $user; - - $this->template_path = dirname(__FILE__) . '/templates'; - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); - $this->template->set_custom_template($this->template_path, 'tests'); - } - - protected function setUp() - { - // Test the engine can be used - $this->setup_engine(); - - if (!is_writable(dirname($this->template->cachepath))) - { - $this->markTestSkipped("Template cache directory is not writable."); - } - - foreach (glob($this->template->cachepath . '*') as $file) - { - unlink($file); - } - - $GLOBALS['config'] = array( - 'load_tplcompile' => true, - 'tpl_allow_php' => false, - ); - } - - protected function tearDown() - { - if (is_object($this->template)) - { - foreach (glob($this->template->cachepath . '*') as $file) - { - unlink($file); - } - } - } - /** * @todo put test data into templates/xyz.test */ @@ -337,46 +279,6 @@ class phpbb_template_template_test extends phpbb_test_case $this->display('test'); } - private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file) - { - $this->template->set_filenames(array('test' => $file)); - $this->template->assign_vars($vars); - - foreach ($block_vars as $block => $loops) - { - foreach ($loops as $_vars) - { - $this->template->assign_block_vars($block, $_vars); - } - } - - foreach ($destroy as $block) - { - $this->template->destroy_block_vars($block); - } - - try - { - $this->assertEquals($expected, $this->display('test'), "Testing $file"); - $this->assertFileExists($cache_file); - } - catch (ErrorException $e) - { - if (file_exists($cache_file)) - { - copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); - } - throw $e; - } - - // For debugging. - // When testing eval path the cache file may not exist. - if (self::PRESERVE_CACHE && file_exists($cache_file)) - { - copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); - } - } - /** * @dataProvider template_data */ diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php new file mode 100644 index 0000000000..e7c12065cc --- /dev/null +++ b/tests/template/template_test_case.php @@ -0,0 +1,113 @@ +assertTrue($this->template->display($handle, false)); + return self::trim_template_result(ob_get_clean()); + } + + protected static function trim_template_result($result) + { + return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result))))); + } + + protected function setup_engine() + { + global $phpbb_root_path, $phpEx, $config, $user; + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); + $this->template->set_custom_template($this->template_path, 'tests'); + } + + protected function setUp() + { + // Test the engine can be used + $this->setup_engine(); + + if (!is_writable(dirname($this->template->cachepath))) + { + $this->markTestSkipped("Template cache directory is not writable."); + } + + foreach (glob($this->template->cachepath . '*') as $file) + { + unlink($file); + } + + $GLOBALS['config'] = array( + 'load_tplcompile' => true, + 'tpl_allow_php' => false, + ); + } + + protected function tearDown() + { + if (is_object($this->template)) + { + foreach (glob($this->template->cachepath . '*') as $file) + { + unlink($file); + } + } + } + + protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file) + { + $this->template->set_filenames(array('test' => $file)); + $this->template->assign_vars($vars); + + foreach ($block_vars as $block => $loops) + { + foreach ($loops as $_vars) + { + $this->template->assign_block_vars($block, $_vars); + } + } + + foreach ($destroy as $block) + { + $this->template->destroy_block_vars($block); + } + + try + { + $this->assertEquals($expected, $this->display('test'), "Testing $file"); + $this->assertFileExists($cache_file); + } + catch (ErrorException $e) + { + if (file_exists($cache_file)) + { + copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); + } + throw $e; + } + + // For debugging. + // When testing eval path the cache file may not exist. + if (self::PRESERVE_CACHE && file_exists($cache_file)) + { + copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file)); + } + } +} -- cgit v1.2.1 From 20b4df2853c46b2ddf61a21911f1255d0a22af73 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 18 May 2011 10:36:17 -0400 Subject: [feature/template-engine] Delete useless template require. It is now handled by autoloading. PHPBB3-9726 --- tests/template/template_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 09f0de3046..ca43e89922 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/template.php'; require_once dirname(__FILE__) . '/template_test_case.php'; class phpbb_template_template_test extends phpbb_template_template_test_case -- cgit v1.2.1 From f24d858cff9d98674cdfe2cb44e1f8fe5afb4563 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 18 May 2011 10:47:03 -0400 Subject: [feature/template-engine] Added tests for template inheritance. PHPBB3-9726 --- .../parent_templates/parent_and_child.html | 1 + tests/template/parent_templates/parent_only.html | 1 + tests/template/template_inheritance_test.php | 74 ++++++++++++++++++++++ tests/template/templates/child_only.html | 1 + tests/template/templates/parent_and_child.html | 1 + 5 files changed, 78 insertions(+) create mode 100644 tests/template/parent_templates/parent_and_child.html create mode 100644 tests/template/parent_templates/parent_only.html create mode 100644 tests/template/template_inheritance_test.php create mode 100644 tests/template/templates/child_only.html create mode 100644 tests/template/templates/parent_and_child.html (limited to 'tests') diff --git a/tests/template/parent_templates/parent_and_child.html b/tests/template/parent_templates/parent_and_child.html new file mode 100644 index 0000000000..71984b48ad --- /dev/null +++ b/tests/template/parent_templates/parent_and_child.html @@ -0,0 +1 @@ +Parent template. diff --git a/tests/template/parent_templates/parent_only.html b/tests/template/parent_templates/parent_only.html new file mode 100644 index 0000000000..8cfb90eca2 --- /dev/null +++ b/tests/template/parent_templates/parent_only.html @@ -0,0 +1 @@ +Only in parent. diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php new file mode 100644 index 0000000000..ed78cc7ee5 --- /dev/null +++ b/tests/template/template_inheritance_test.php @@ -0,0 +1,74 @@ +template->cachepath . str_replace('/', '.', $file) . '.php'; + + $this->assertFileNotExists($cache_file); + + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + + // Reset the engine state + $this->setup_engine(); + + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + } + + protected function setup_engine() + { + global $phpbb_root_path, $phpEx, $config, $user; + + $this->template_path = dirname(__FILE__) . '/templates'; + $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); + $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path); + } +} diff --git a/tests/template/templates/child_only.html b/tests/template/templates/child_only.html new file mode 100644 index 0000000000..6121fef5c5 --- /dev/null +++ b/tests/template/templates/child_only.html @@ -0,0 +1 @@ +Only in child. diff --git a/tests/template/templates/parent_and_child.html b/tests/template/templates/parent_and_child.html new file mode 100644 index 0000000000..16223d91e7 --- /dev/null +++ b/tests/template/templates/parent_and_child.html @@ -0,0 +1 @@ +Child template. -- cgit v1.2.1 From efda4da19fedd0e5bd67835034cfc689b8f5a740 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 18 May 2011 10:57:04 -0400 Subject: [feature/template-engine] Moved includephp test to its own file. PHPBB3-9726 --- tests/template/includephp_test.php | 27 ++++++++++++++++++++++ .../subdir/includephp_from_subdir_test.php | 4 +--- tests/template/template_test.php | 14 ----------- 3 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 tests/template/includephp_test.php (limited to 'tests') diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php new file mode 100644 index 0000000000..6c1cdb0fd6 --- /dev/null +++ b/tests/template/includephp_test.php @@ -0,0 +1,27 @@ +template->cachepath . 'includephp_relative.html.php'; + + $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); + + $this->template->set_filenames(array('test' => 'includephp_relative.html')); + $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); + + $GLOBALS['config']['tpl_allow_php'] = false; + } +} diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php index 7bfd852d9e..d6148c7032 100644 --- a/tests/template/subdir/includephp_from_subdir_test.php +++ b/tests/template/subdir/includephp_from_subdir_test.php @@ -7,13 +7,11 @@ * */ -require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../../phpBB/includes/template.php'; require_once dirname(__FILE__) . '/../template_test_case.php'; class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_template_test_case { - // Exact copy of test_includephp_relatve from ../template_test.php. + // Exact copy of test_includephp_relatve from ../includephp_test.php. // Verifies that relative php inclusion works when including script // (and thus current working directory) is in a subdirectory of // board root. diff --git a/tests/template/template_test.php b/tests/template/template_test.php index ca43e89922..71cf9d38f3 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -339,20 +339,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $GLOBALS['config']['tpl_allow_php'] = false; } - public function test_includephp_relative() - { - $GLOBALS['config']['tpl_allow_php'] = true; - - $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; - - $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file); - - $this->template->set_filenames(array('test' => 'includephp_relative.html')); - $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); - - $GLOBALS['config']['tpl_allow_php'] = false; - } - public static function alter_block_array_data() { return array( -- cgit v1.2.1 From 6ae5a64f6c12937367ad56cac5e38104b445c780 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 19 May 2011 12:18:16 -0400 Subject: [feature/template-engine] Fixed absolute path PHP includes, added test. PHPBB3-9726 --- tests/template/includephp_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index 6c1cdb0fd6..45dc8dc39e 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -24,4 +24,28 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $GLOBALS['config']['tpl_allow_php'] = false; } + + public function test_includephp_absolute() + { + $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; + $this->assertTrue(is_absolute($path_to_php)); + $template_text = "Path is absolute.\n"; + + $cache_dir = dirname($this->template->cachepath) . '/'; + $fp = fopen($cache_dir . 'includephp_absolute.html', 'w'); + fputs($fp, $template_text); + fclose($fp); + + $GLOBALS['config']['tpl_allow_php'] = true; + + $this->template->set_custom_template($cache_dir, 'tests'); + $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; + + $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); + + $this->template->set_filenames(array('test' => 'includephp_absolute.html')); + $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); + + $GLOBALS['config']['tpl_allow_php'] = false; + } } -- cgit v1.2.1 From 1d26398faab3459e52dd951299df6e0a2fc66e7d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 19 May 2011 22:55:08 -0400 Subject: [feature/template-engine] Fixed copyright year. PHPBB3-9726 --- tests/template/template_compile_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index 2f12292870..bfd4e03406 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From f0287f7e57919619e7b8085a7e7071975e18da93 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 2 Jun 2011 06:09:21 +0200 Subject: [ticket/9685] Test for databases that are able to nest transactions If a database is unable to nest transactions the dbal should implement sql_buffer_nested_transactions to signal that buffering of the outer results and closing of the outer transaction is required to open the inner transaction. PHPBB3-9685 --- tests/dbal/select_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 533416f14b..e0d08d9306 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -8,6 +8,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; class phpbb_dbal_select_test extends phpbb_database_test_case { @@ -317,4 +318,27 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } + + function test_nested_transactions() + { + $db = $this->new_dbal(); + + // nested transactions should work on systems that do not require + // buffering of nested transactions, so ignore the ones that need + // buffering + if ($db->sql_buffer_nested_transactions()) + { + return; + } + + $sql = 'SELECT user_id FROM phpbb_users ORDER BY user_id ASC'; + $result1 = $db->sql_query($sql); + + $db->sql_transaction('begin'); + $result2 = $db->sql_query($sql); + $row = $db->sql_fetchrow($result2); + $db->sql_transaction('commit'); + + $this->assertEquals('1', $row['user_id']); + } } -- cgit v1.2.1 From 7b10f859decdb5d97ffe97e647db52f29f4661f8 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 2 Jun 2011 08:45:48 +0200 Subject: [ticket/10005] Add validation of dropdown custom profile field values PHPBB3-10005 --- tests/profile/custom_test.php | 52 +++++++++++++++++++++++++++++++ tests/profile/fixtures/profile_fields.xml | 31 ++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/profile/custom_test.php create mode 100644 tests/profile/fixtures/profile_fields.xml (limited to 'tests') diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php new file mode 100644 index 0000000000..06926d4af6 --- /dev/null +++ b/tests/profile/custom_test.php @@ -0,0 +1,52 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/profile_fields.xml'); + } + + static public function dropdownFields() + { + return array( + // novalue, required, value, expected + array(1, 1, '0', 'FIELD_INVALID_VALUE'), + array(1, 1, '1', 'FIELD_REQUIRED'), + array(1, 1, '2', false), + array(1, 0, '0', 'FIELD_INVALID_VALUE'), + array(1, 0, '1', false), + array(1, 0, '2', false), + ); + } + + /** + * @dataProvider dropdownFields + */ + public function test_dropdown_validate($field_novalue, $field_required, $field_value, $expected) + { + global $db; + $db = $this->new_dbal(); + + $field_data = array( + 'field_id' => 1, + 'lang_id' => 1, + 'field_novalue' => $field_novalue, + 'field_required' => $field_required, + ); + + $cp = new custom_profile; + $result = $cp->validate_profile_field(FIELD_DROPDOWN, &$field_value, $field_data); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/profile/fixtures/profile_fields.xml b/tests/profile/fixtures/profile_fields.xml new file mode 100644 index 0000000000..0b2929f625 --- /dev/null +++ b/tests/profile/fixtures/profile_fields.xml @@ -0,0 +1,31 @@ + + + + field_id + lang_id + option_id + field_type + lang_value + + 1 + 1 + 0 + 5 + Default Option + + + 1 + 1 + 1 + 5 + First Alternative + + + 1 + 1 + 2 + 5 + Third Alternative + +
+
-- cgit v1.2.1 From a2b6605ce8d5d4c156fda44c5fc44b11aae22b02 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 3 Jun 2011 03:12:13 +0200 Subject: [ticket/10005] Add description to test cases PHPBB3-10005 --- tests/profile/custom_test.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php index 06926d4af6..0e0a851243 100644 --- a/tests/profile/custom_test.php +++ b/tests/profile/custom_test.php @@ -19,20 +19,23 @@ class phpbb_profile_custom_test extends phpbb_database_test_case static public function dropdownFields() { return array( - // novalue, required, value, expected - array(1, 1, '0', 'FIELD_INVALID_VALUE'), - array(1, 1, '1', 'FIELD_REQUIRED'), - array(1, 1, '2', false), - array(1, 0, '0', 'FIELD_INVALID_VALUE'), - array(1, 0, '1', false), - array(1, 0, '2', false), + // note, there is an offset of 1 between option_id (0-indexed) + // in the database and values (1-indexed) to avoid problems with + // transmitting 0 in an HTML form + // required, value, expected + array(1, '0', 'FIELD_INVALID_VALUE', 'Required field should throw error for out-of-range value'), + array(1, '1', 'FIELD_REQUIRED', 'Required field should throw error for default value'), + array(1, '2', false, 'Required field should accept non-default value'), + array(0, '0', 'FIELD_INVALID_VALUE', 'Optional field should throw error for out-of-range value'), + array(0, '1', false, 'Optional field should accept default value'), + array(0, '2', false, 'Optional field should accept non-default value'), ); } /** * @dataProvider dropdownFields */ - public function test_dropdown_validate($field_novalue, $field_required, $field_value, $expected) + public function test_dropdown_validate($field_required, $field_value, $expected, $description) { global $db; $db = $this->new_dbal(); @@ -40,13 +43,13 @@ class phpbb_profile_custom_test extends phpbb_database_test_case $field_data = array( 'field_id' => 1, 'lang_id' => 1, - 'field_novalue' => $field_novalue, + 'field_novalue' => 1, 'field_required' => $field_required, ); $cp = new custom_profile; $result = $cp->validate_profile_field(FIELD_DROPDOWN, &$field_value, $field_data); - $this->assertEquals($expected, $result); + $this->assertEquals($expected, $result, $description); } } -- cgit v1.2.1 From 6585d938d2c441900d8af6d25da2433d3beec856 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 5 Jun 2011 21:55:28 +0800 Subject: [ticket/217] Adjust patch, add tests PHPBB3-217 --- tests/bbcode/url_bbcode_test.php | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/bbcode/url_bbcode_test.php (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php new file mode 100644 index 0000000000..6d9e51664d --- /dev/null +++ b/tests/bbcode/url_bbcode_test.php @@ -0,0 +1,41 @@ +message = $message; + $bbcode->bbcode_init(true); + $bbcode->parse_bbcode(); + $this->assertNotEquals($bbcode->message, '[url][/url]'); + $this->assertNotEquals($bbcode->message, $message); + $this->assertNotEquals($bbcode->message, NULL); + } +} -- cgit v1.2.1 From d44b6ba5caeafe220b4959a6de99d035fe10b4f1 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 6 Jun 2011 00:50:53 +0800 Subject: [ticket/217] Use positive parameter statement for bbcode_init() PHPBB3-217 --- tests/bbcode/url_bbcode_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index 6d9e51664d..597933c6f8 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -32,7 +32,7 @@ class phpbb_url_bbcode_test extends phpbb_test_case { $bbcode = new bbcode_firstpass(); $bbcode->message = $message; - $bbcode->bbcode_init(true); + $bbcode->bbcode_init(false); $bbcode->parse_bbcode(); $this->assertNotEquals($bbcode->message, '[url][/url]'); $this->assertNotEquals($bbcode->message, $message); -- cgit v1.2.1 From 2d1e426ba745fa5b0b7666e5fe4a5fee97caccd7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 5 Jun 2011 13:23:55 -0400 Subject: [ticket/217] Silence errors in tests, not code. Use a mock user object for testing bbcode. PHPBB3-217 --- tests/bbcode/url_bbcode_test.php | 4 ++++ tests/mock_user.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/mock_user.php (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index 597933c6f8..7bbf731c74 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -11,6 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; +require_once dirname(__FILE__) . '/../mock_user.php'; class phpbb_url_bbcode_test extends phpbb_test_case { @@ -30,6 +31,9 @@ class phpbb_url_bbcode_test extends phpbb_test_case */ public function test_url($message) { + global $user; + $user = new phpbb_mock_user; + $bbcode = new bbcode_firstpass(); $bbcode->message = $message; $bbcode->bbcode_init(false); diff --git a/tests/mock_user.php b/tests/mock_user.php new file mode 100644 index 0000000000..74d31c4c4a --- /dev/null +++ b/tests/mock_user.php @@ -0,0 +1,20 @@ + '/'); +} -- cgit v1.2.1 From c93164db587391aaff7dd810d07cd0671c8bce3c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 5 Jun 2011 13:48:37 -0400 Subject: [ticket/217] Use positive assertions in tests. PHPBB3-217 --- tests/bbcode/url_bbcode_test.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index 7bbf731c74..cd85dbd0d9 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -18,18 +18,38 @@ class phpbb_url_bbcode_test extends phpbb_test_case public function url_bbcode_test_data() { return array( - array('[url]http://www.phpbb.com/community/[/url]'), - array('[url=http://www.phpbb.com/community/]One line URL text[/url]'), - array("[url=http://www.phpbb.com/community/]Multiline\x0AURL\x0Atext[/url]"), - array("test [url] test \x0A test [url=http://www.phpbb.com/]test[/url] test"), - array("test [url=http://www.phpbb.com/]test \x0A [url]http://phpbb.com[/url] test"), + array( + 'url only', + '[url]http://www.phpbb.com/community/[/url]', + '[url:]http://www.phpbb.com/community/[/url:]' + ), + array( + 'url with title', + '[url=http://www.phpbb.com/community/]One line URL text[/url]', + '[url=http://www.phpbb.com/community/:]One line URL text[/url:]' + ), + array( + 'url with multiline title', + "[url=http://www.phpbb.com/community/]Multiline\x0AURL\x0Atext[/url]", + "[url=http://www.phpbb.com/community/:]Multiline\x0AURL\x0Atext[/url:]" + ), + array( + 'unclosed url with multiline', + "test [url] test \x0A test [url=http://www.phpbb.com/]test[/url] test", + "test [url] test \x0A test [url=http://www.phpbb.com/:]test[/url:] test" + ), + array( + 'unclosed url with multiline and title', + "test [url=http://www.phpbb.com/]test \x0A [url]http://phpbb.com[/url] test", + "test [url=http://www.phpbb.com/:]test \x0A [url]http://phpbb.com[/url:] test" + ), ); } /** * @dataProvider url_bbcode_test_data */ - public function test_url($message) + public function test_url($description, $message, $expected) { global $user; $user = new phpbb_mock_user; @@ -38,8 +58,6 @@ class phpbb_url_bbcode_test extends phpbb_test_case $bbcode->message = $message; $bbcode->bbcode_init(false); $bbcode->parse_bbcode(); - $this->assertNotEquals($bbcode->message, '[url][/url]'); - $this->assertNotEquals($bbcode->message, $message); - $this->assertNotEquals($bbcode->message, NULL); + $this->assertEquals($expected, $bbcode->message); } } -- cgit v1.2.1 From 545e9658a36528c5d3b9cda227650c2e6f70db3a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 9 Jun 2011 13:41:13 +0200 Subject: [ticket/8138] Fix unit test for build_cfg_template PHPBB3-8138 --- tests/functions_acp/build_cfg_template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 7bf85a3532..76e133181f 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -29,7 +29,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name' => '2'), 'config_key_name', array(), - '', + '', ), array( array('text', 0, 255), -- cgit v1.2.1 From 70f9dec810e3104357b6cf13978cb52ea8cd8e99 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 01:37:19 +0200 Subject: [ticket/10198] Verify behaviour of validate_range with multibyte strings Using str_repeat instead of custom function to repeat characters. PHPBB3-10198 --- tests/functions_acp/validate_range_test.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index a9c9612ad7..11b7f87957 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -8,23 +8,11 @@ */ require_once dirname(__FILE__) . '/../mock/lang.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_range_test extends phpbb_test_case { - /** - * Helper function which returns a string in a given length. - */ - static public function return_string($length) - { - $string = ''; - for ($i = 0; $i < $length; $i++) - { - $string .= 'a'; - } - return $string; - } - /** * Data sets that don't throw an error. */ @@ -53,8 +41,10 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case array(array(array('column_type' => 'TINT:-32:64', 'lang' => 'TEST', 'value' => 16))), array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => ''))), - array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(255)))), - array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(128)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 255)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 255)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 128)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 128)))), ); } @@ -157,8 +147,10 @@ class phpbb_functions_acp_validate_range_test extends phpbb_test_case public function validate_range_data_too_long() { return array( - array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => self::return_string(256)))), - array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => self::return_string(129)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat('a', 256)))), + array(array(array('column_type' => 'VCHAR', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 256)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat('a', 129)))), + array(array(array('column_type' => 'VCHAR:128', 'lang' => 'TEST', 'value' => str_repeat("\xC3\x84", 129)))), ); } -- cgit v1.2.1 From 48a0bec971625e3654cc825f6a4dff2dbb4e1f6d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 01:44:25 +0200 Subject: [ticket/10198] Verify behaviour of validate_config_vars with multibyte strings Using str_repeat instead of custom function to repeat characters. PHPBB3-10198 --- tests/functions_acp/validate_config_vars_test.php | 46 +++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php index aa63bc38df..761788e264 100644 --- a/tests/functions_acp/validate_config_vars_test.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -12,19 +12,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case { - /** - * Helper function which returns a string in a given length. - */ - static public function return_string($length) - { - $string = ''; - for ($i = 0; $i < $length; $i++) - { - $string .= 'a'; - } - return $string; - } - /** * Data sets that don't throw an error. */ @@ -35,8 +22,11 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case array( 'test_bool' => array('lang' => 'TEST_BOOL', 'validate' => 'bool'), 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'), + 'test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string'), + 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'), 'test_string_128' => array('lang' => 'TEST_STRING_128', 'validate' => 'string:128'), 'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'), + 'test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64'), 'test_int' => array('lang' => 'TEST_INT', 'validate' => 'int'), 'test_int_32' => array('lang' => 'TEST_INT', 'validate' => 'int:32'), 'test_int_32_64' => array('lang' => 'TEST_INT', 'validate' => 'int:32:64'), @@ -51,9 +41,12 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case ), array( 'test_bool' => true, - 'test_string' => self::return_string(255), - 'test_string_128' => self::return_string(128), - 'test_string_32_64' => self::return_string(48), + 'test_string' => str_repeat('a', 255), + 'test_string' => str_repeat("\xC3\x84", 255), + 'test_string_128' => str_repeat('a', 128), + 'test_string_128' => str_repeat("\xC3\x84", 128), + 'test_string_32_64' => str_repeat('a', 48), + 'test_string_32_64' => str_repeat("\xC3\x84", 48), 'test_int' => 128, 'test_int_32' => 32, 'test_int_32_64' => 48, @@ -86,17 +79,32 @@ class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case return array( array( array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), - array('test_string_32_64' => self::return_string(20)), + array('test_string_32_64' => str_repeat('a', 20)), + array('SETTING_TOO_SHORT'), + ), + array( + array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), + array('test_string_32_64' => str_repeat("\xC3\x84", 20)), array('SETTING_TOO_SHORT'), ), array( array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), - array('test_string' => self::return_string(256)), + array('test_string' => str_repeat('a', 256)), + array('SETTING_TOO_LONG'), + ), + array( + array('test_string' => array('lang' => 'TEST_STRING', 'validate' => 'string')), + array('test_string' => str_repeat("\xC3\x84", 256)), + array('SETTING_TOO_LONG'), + ), + array( + array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), + array('test_string_32_64' => str_repeat('a', 65)), array('SETTING_TOO_LONG'), ), array( array('test_string_32_64' => array('lang' => 'TEST_STRING_32_64', 'validate' => 'string:32:64')), - array('test_string_32_64' => self::return_string(65)), + array('test_string_32_64' => str_repeat("\xC3\x84", 65)), array('SETTING_TOO_LONG'), ), -- cgit v1.2.1 From d004ef093fd96e5e84b22b5461f8e82594cd1f5e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 02:00:33 +0200 Subject: [ticket/10198] Test if schema allows reading & writing multibyte config values PHPBB3-10198 --- tests/dbal/schema_test.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/dbal/schema_test.php (limited to 'tests') diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php new file mode 100644 index 0000000000..2475a85708 --- /dev/null +++ b/tests/dbal/schema_test.php @@ -0,0 +1,38 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_config_value_multibyte() + { + $db = $this->new_dbal(); + + $value = str_repeat("\xC3\x84", 255); + $sql = "INSERT INTO phpbb_config + (config_name, config_value) + VALUES ('name', '$value')"; + $result = $db->sql_query($sql); + + $sql = "SELECT config_value + FROM phpbb_config + WHERE config_name = 'name'"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $this->assertEquals($value, $row['config_value']); + } +} -- cgit v1.2.1 From 28801d01985dcee7c94ad5c54ca5f9ee34592026 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 02:16:19 +0200 Subject: [ticket/10206] Failed unicode.org downloads no longer terminate tests Instead a warning is triggered and an explanation echo'd. PHPBB3-10206 --- tests/utf/normalizer_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php index 38b4ec1b6b..f78dba8004 100644 --- a/tests/utf/normalizer_test.php +++ b/tests/utf/normalizer_test.php @@ -298,12 +298,14 @@ class phpbb_utf_normalizer_test extends phpbb_test_case if (!$fpr = fopen($url, 'rb')) { - throw new RuntimeException("Failed to download $url"); + echo "Failed to download $url\n"; + return; } if (!$fpw = fopen($target, 'wb')) { - throw new RuntimeException("Failed to open $target for writing"); + echo "Failed to open $target for writing\n"; + return; } $chunk = 32768; -- cgit v1.2.1 From 025649e14cf4a4678f26790fa4328b25a3f040cf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 10:34:43 +0200 Subject: [ticket/9892] Adding a number of tests for db_tools The test creates a table and runs a number of queries on it to judge whether the selected column types can hold the data they are expected to contain. Additional test methods check the auto increment feature and a few of the basic commands of db_tools. This is only a starting point. Plenty more tests need to be added. PHPBB3-9892 --- tests/dbal/db_tools_test.php | 268 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 tests/dbal/db_tools_test.php (limited to 'tests') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php new file mode 100644 index 0000000000..b9206b622e --- /dev/null +++ b/tests/dbal/db_tools_test.php @@ -0,0 +1,268 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->tools = new phpbb_db_tools($this->db); + + $this->table_data = array( + 'COLUMNS' => array( + 'c_id' => array('UINT', NULL, 'auto_increment'), + 'c_int_size' => array('INT:4', 4), + 'c_bint' => array('BINT', 4), + 'c_uint' => array('UINT', 4), + 'c_uint_size' => array('UINT:4', 4), + 'c_tint_size' => array('TINT:2', 4), + 'c_usint' => array('USINT', 4), + 'c_bool' => array('BOOL', 1), + 'c_vchar' => array('VCHAR', 'foo'), + 'c_vchar_size' => array('VCHAR:4', 'foo'), + 'c_char_size' => array('CHAR:4', 'foo'), + 'c_xstext' => array('XSTEXT', 'foo'), + 'c_stext' => array('STEXT', 'foo'), + 'c_text' => array('TEXT', 'foo'), + 'c_mtext' => array('MTEXT', 'foo'), + 'c_xstext_uni' => array('XSTEXT_UNI', 'foo'), + 'c_stext_uni' => array('STEXT_UNI', 'foo'), + 'c_text_uni' => array('TEXT_UNI', 'foo'), + 'c_mtext_uni' => array('MTEXT_UNI', 'foo'), + 'c_timestamp' => array('TIMESTAMP', 4), + 'c_decimal' => array('DECIMAL', 4.2), + 'c_decimal_size' => array('DECIMAL:6', 4.2), + 'c_pdecimal' => array('PDECIMAL', 4.2), + 'c_pdecimal_size' => array('PDECIMAL:7', 4.2), + 'c_vchar_uni' => array('VCHAR_UNI', 'foo'), + 'c_vchar_uni_size' => array('VCHAR_UNI:4', 'foo'), + 'c_vchar_ci' => array('VCHAR_CI', 'foo'), + 'c_varbinary' => array('VARBINARY', 'foo'), + ), + 'PRIMARY_KEY' => 'c_id', + 'KEYS' => array( + 'i_simple' => array('INDEX', 'c_uint'), + 'i_uniq' => array('UNIQUE', 'c_vchar'), + 'i_comp' => array('INDEX', array('c_vchar_uni', 'c_bool')), + 'i_comp_uniq' => array('UNIQUE', array('c_vchar_size', 'c_usint')), + ), + ); + $this->tools->sql_create_table('prefix_table_name', $this->table_data); + $this->table_exists = true; + } + + protected function tearDown() + { + if ($this->table_exists) + { + $this->tools->sql_table_drop('prefix_table_name'); + } + + parent::tearDown(); + } + + public function test_created_and_drop_table() + { + // table is empty after creation and queryable + $sql = 'SELECT * FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + $this->assertTrue(! $this->db->sql_fetchrow($result)); + $this->db->sql_freeresult($result); + + $this->table_exists = false; + $this->tools->sql_table_drop('prefix_table_name'); + } + + static protected function get_default_values() + { + return array( + 'c_int_size' => 0, + 'c_bint' => 0, + 'c_uint' => 0, + 'c_uint_size' => 0, + 'c_tint_size' => 0, + 'c_usint' => 0, + 'c_bool' => 0, + 'c_vchar' => '', + 'c_vchar_size' => '', + 'c_char_size' => '', + 'c_xstext' => '', + 'c_stext' => '', + 'c_text' => '', + 'c_mtext' => '', + 'c_xstext_uni' => '', + 'c_stext_uni' => '', + 'c_text_uni' => '', + 'c_mtext_uni' => '', + 'c_timestamp' => 0, + 'c_decimal' => 0, + 'c_decimal_size' => 0, + 'c_pdecimal' => 0, + 'c_pdecimal_size' => 0, + 'c_vchar_uni' => '', + 'c_vchar_uni_size' => '', + 'c_vchar_ci' => '', + 'c_varbinary' => '', + ); + } + + static public function columnValues() + { + return array( + array('c_int_size', -9999), + array('c_bint', '99999999999999999'), + array('c_uint', 16777215), + array('c_uint_size', 9999), + array('c_tint_size', -99), + array('c_usint', 99), + array('c_bool', 0), + array('c_vchar', str_repeat('a', 255)), + array('c_vchar_size', str_repeat('a', 4)), + array('c_char_size', str_repeat('a', 4)), + array('c_xstext', str_repeat('a', 1000)), + array('c_stext', str_repeat('a', 3000)), + array('c_text', str_repeat('a', 8000)), + array('c_mtext', str_repeat('a', 10000)), + array('c_xstext_uni', str_repeat("\xC3\x84", 100)), + array('c_stext_uni', str_repeat("\xC3\x84", 255)), + array('c_text_uni', str_repeat("\xC3\x84", 4000)), + array('c_mtext_uni', str_repeat("\xC3\x84", 10000)), + array('c_timestamp', 2147483647), + array('c_decimal', 999.99), + array('c_decimal_size', 9999.99), + array('c_pdecimal', 999.999), + array('c_pdecimal_size', 9999.999), + array('c_vchar_uni', str_repeat("\xC3\x84", 255)), + array('c_vchar_uni_size', str_repeat("\xC3\x84", 4)), + array('c_vchar_ci', str_repeat("\xC3\x84", 255)), + array('c_varbinary', str_repeat("\x00\xFF", 127)), + ); + } + + /** + * @dataProvider columnValues + */ + public function test_created_column($column_name, $column_value) + { + $row_insert = self::get_default_values(); + $row_insert[$column_name] = $column_value; + + // empty table + $sql = 'DELETE FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row_insert); + $result = $this->db->sql_query($sql); + + $sql = "SELECT * + FROM prefix_table_name"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row_expect = $row_insert; + + unset($row_actual['id']); // auto increment id changes, so ignore + + $type = $this->table_data['COLUMNS'][$column_name][0]; + $this->assertEquals($row_expect[$column_name], $row_actual[$column_name], "Column $column_name of type $type should have equal return and input value."); + } + + public function test_auto_increment() + { + $sql = 'DELETE FROM prefix_table_name'; + $result = $this->db->sql_query($sql); + + $row1 = array_merge(self::get_default_values(), array( + 'c_uint' => 1, + 'c_vchar' => '1', // these values are necessary to avoid unique index issues + 'c_vchar_size' => '1', + )); + $row2 = array_merge(self::get_default_values(), array( + 'c_uint' => 2, + 'c_vchar' => '2', + 'c_vchar_size' => '2', + )); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row1); + $result = $this->db->sql_query($sql); + $id1 = $this->db->sql_nextid(); + + $sql = 'INSERT INTO prefix_table_name ' . $this->db->sql_build_array('INSERT', $row2); + $result = $this->db->sql_query($sql); + $id2 = $this->db->sql_nextid(); + + $this->assertGreaterThan($id1, $id2, 'Auto increment should increase the id value'); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id1"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row1['c_id'] = $id1; + $this->assertEquals($row1, $row_actual); + + $sql = "SELECT * + FROM prefix_table_name WHERE c_id = $id2"; + $result = $this->db->sql_query($sql); + $row_actual = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $row2['c_id'] = $id2; + $this->assertEquals($row2, $row_actual); + } + + public function test_column_exists() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist')); + } + + public function test_column_remove() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id')); + + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_id')); + } + + public function test_table_exists() + { + $this->assertTrue($this->tools->sql_table_exists('prefix_table_name')); + $this->assertFalse($this->tools->sql_table_exists('prefix_does_not_exist')); + } + + public function test_table_drop() + { + $this->tools->sql_create_table('prefix_test_table', + array('COLUMNS' => array( + 'foo' => array('UINT', 42))) + ); + + $this->tools->sql_table_drop('prefix_test_table'); + } + +} -- cgit v1.2.1 From 11750bdccc168568148de68df2ceca258e5a7da5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 12:24:57 +0200 Subject: [ticket/9892] Remove incorrect use of camel case PHPBB3-9892 --- tests/dbal/db_tools_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index b9206b622e..48406d40a3 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -127,7 +127,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case ); } - static public function columnValues() + static public function column_values() { return array( array('c_int_size', -9999), @@ -161,7 +161,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case } /** - * @dataProvider columnValues + * @dataProvider column_values */ public function test_created_column($column_name, $column_value) { -- cgit v1.2.1 From 4e0717b4d7da58469c795191236ad4256a20c72a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 12 Jun 2011 12:26:49 +0200 Subject: [ticket/9892] Correct copyright year PHPBB3-9892 --- tests/dbal/db_tools_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 48406d40a3..eb2af4c4cc 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From 96eab49a7a5d803fcc121fe5490b2484c6499d40 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 3 Jul 2011 18:09:56 -0400 Subject: [ticket/10247] Add a db_tools test for the removal of a primary key column. The previous drop column test already deleted the primary key, so that one was replaced with an ordinary column. PHPBB3-10247 --- tests/dbal/db_tools_test.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index eb2af4c4cc..ddea500f83 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -241,6 +241,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case } public function test_column_remove() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); + + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_int_size')); + + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); + } + + public function test_column_remove_primary() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); @@ -264,5 +273,4 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->tools->sql_table_drop('prefix_test_table'); } - } -- cgit v1.2.1 From f7b06ca12db9da519d49ce334eaf96573d003c0f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 9 Jul 2011 23:33:44 +0200 Subject: [feature/template-engine] Move template.php to includes/template This allows making use of autoloading. PHPBB3-9726 --- tests/template/template_compile_test.php | 1 - tests/template/template_test_case.php | 1 - 2 files changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index bfd4e03406..769c7c2680 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/template.php'; class phpbb_template_template_compile_test extends phpbb_test_case { diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index e7c12065cc..cab1aa3d4f 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/template.php'; class phpbb_template_template_test_case extends phpbb_test_case { -- cgit v1.2.1 From ae53623230a45eeedf50cc3f6220164d8cd256c3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 10 Jul 2011 00:35:07 +0200 Subject: [feature/template-engine] Refactor $config dependency out of the filter The template stream filter no longer depends on the $config global. Instead it uses a 'allow_php' param that is passed via stream_bucket_append's last argument. Tests also adjusted. PHPBB3-9726 --- tests/template/includephp_test.php | 8 ++------ tests/template/subdir/includephp_from_subdir_test.php | 4 +--- tests/template/template_compile_test.php | 2 +- tests/template/template_test.php | 4 +--- tests/template/template_test_case.php | 16 ++++++++++------ 5 files changed, 15 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index 45dc8dc39e..64240e1be8 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -13,7 +13,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case { public function test_includephp_relative() { - $GLOBALS['config']['tpl_allow_php'] = true; + $this->setup_engine(array('tpl_allow_php' => true)); $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; @@ -21,8 +21,6 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => 'includephp_relative.html')); $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); - - $GLOBALS['config']['tpl_allow_php'] = false; } public function test_includephp_absolute() @@ -36,7 +34,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case fputs($fp, $template_text); fclose($fp); - $GLOBALS['config']['tpl_allow_php'] = true; + $this->setup_engine(array('tpl_allow_php' => true)); $this->template->set_custom_template($cache_dir, 'tests'); $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; @@ -45,7 +43,5 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => 'includephp_absolute.html')); $this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); - - $GLOBALS['config']['tpl_allow_php'] = false; } } diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php index d6148c7032..3cc632485d 100644 --- a/tests/template/subdir/includephp_from_subdir_test.php +++ b/tests/template/subdir/includephp_from_subdir_test.php @@ -17,7 +17,7 @@ class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_t // board root. public function test_includephp_relative() { - $GLOBALS['config']['tpl_allow_php'] = true; + $this->setup_engine(array('tpl_allow_php' => true)); $cache_file = $this->template->cachepath . 'includephp_relative.html.php'; @@ -25,7 +25,5 @@ class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_t $this->template->set_filenames(array('test' => 'includephp_relative.html')); $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); - - $GLOBALS['config']['tpl_allow_php'] = false; } } diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index 769c7c2680..8c136c9985 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case protected function setUp() { - $this->template_compile = new phpbb_template_compile(); + $this->template_compile = new phpbb_template_compile(false); $this->template_path = dirname(__FILE__) . '/templates'; } diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 71cf9d38f3..df3f927c22 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -328,15 +328,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case public function test_php() { - $GLOBALS['config']['tpl_allow_php'] = true; + $this->setup_engine(array('tpl_allow_php' => true)); $cache_file = $this->template->cachepath . 'php.html.php'; $this->assertFileNotExists($cache_file); $this->run_template('php.html', array(), array(), array(), 'test', $cache_file); - - $GLOBALS['config']['tpl_allow_php'] = false; } public static function alter_block_array_data() diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index cab1aa3d4f..ed5afdc643 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -29,9 +29,16 @@ class phpbb_template_template_test_case extends phpbb_test_case return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result))))); } - protected function setup_engine() + protected function setup_engine(array $new_config = array()) { - global $phpbb_root_path, $phpEx, $config, $user; + global $phpbb_root_path, $phpEx, $user; + + $defaults = array( + 'load_tplcompile' => true, + 'tpl_allow_php' => false, + ); + + $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); @@ -53,10 +60,7 @@ class phpbb_template_template_test_case extends phpbb_test_case unlink($file); } - $GLOBALS['config'] = array( - 'load_tplcompile' => true, - 'tpl_allow_php' => false, - ); + $this->setup_engine(); } protected function tearDown() -- cgit v1.2.1 From c58b09e65d428b53d2e69abf00c5847829f18fc7 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 10 Jul 2011 01:05:54 +0200 Subject: [feature/template-engine] Remove $include_once argument of display() PHPBB3-9726 --- tests/template/template_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index ed5afdc643..c87b54f973 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -20,7 +20,7 @@ class phpbb_template_template_test_case extends phpbb_test_case protected function display($handle) { ob_start(); - $this->assertTrue($this->template->display($handle, false)); + $this->assertTrue($this->template->display($handle)); return self::trim_template_result(ob_get_clean()); } -- cgit v1.2.1 From 0e85704d75c2edefdbdfb9d5542ab366744e65fb Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 13 Jul 2011 00:44:10 +0200 Subject: [ticket/10243] Adding a few unit tests for phpbb_gmgetdate(). PHPBB3-10243 --- tests/wrapper/gmgetdate_test.php | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/wrapper/gmgetdate_test.php (limited to 'tests') diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php new file mode 100644 index 0000000000..0b4c3378a9 --- /dev/null +++ b/tests/wrapper/gmgetdate_test.php @@ -0,0 +1,49 @@ +run_gmgetdate_assertion(); + $this->run_test_with_timezone('UTC'); + $this->run_test_with_timezone('Europe/Berlin'); + $this->run_test_with_timezone('America/Los_Angeles'); + $this->run_test_with_timezone('Antarctica/South_Pole'); + } + + protected function run_test_with_timezone($timezone_identifier) + { + $current_timezone = date_default_timezone_get(); + + date_default_timezone_set($timezone_identifier); + $this->run_gmgetdate_assertion(); + date_default_timezone_set($current_timezone); + } + + protected function run_gmgetdate_assertion() + { + $expected = time(); + + $date_array = phpbb_gmgetdate($expected); + + $actual = gmmktime( + $date_array['hours'], + $date_array['minutes'], + $date_array['seconds'], + $date_array['mon'], + $date_array['mday'], + $date_array['year'] + ); + + $this->assertEquals($expected, $actual); + } +} -- cgit v1.2.1 From e11f9afdce7649cebbe3f40d8af6ef62f8042434 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 13 Jul 2011 00:49:48 +0200 Subject: [ticket/10265] Move mt_rand.php to wrapper folder and add _test suffix. PHPBB3-10265 --- tests/random/mt_rand.php | 46 ------------------------------------------ tests/wrapper/mt_rand_test.php | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 46 deletions(-) delete mode 100644 tests/random/mt_rand.php create mode 100644 tests/wrapper/mt_rand_test.php (limited to 'tests') diff --git a/tests/random/mt_rand.php b/tests/random/mt_rand.php deleted file mode 100644 index d6502c4e80..0000000000 --- a/tests/random/mt_rand.php +++ /dev/null @@ -1,46 +0,0 @@ -assertEquals(42, $result); - } - - public function test_max_equals_min_negative() - { - $result = phpbb_mt_rand(-42, -42); - $this->assertEquals(-42, $result); - } - - public function test_max_greater_min() - { - $result = phpbb_mt_rand(3, 4); - $this->assertGreaterThanOrEqual(3, $result); - $this->assertLessThanOrEqual(4, $result); - } - - public function test_min_greater_max() - { - $result = phpbb_mt_rand(4, 3); - $this->assertGreaterThanOrEqual(3, $result); - $this->assertLessThanOrEqual(4, $result); - } - - public function test_min_greater_max_negative() - { - $result = phpbb_mt_rand(-3, -4); - $this->assertGreaterThanOrEqual(-4, $result); - $this->assertLessThanOrEqual(-3, $result); - } -} diff --git a/tests/wrapper/mt_rand_test.php b/tests/wrapper/mt_rand_test.php new file mode 100644 index 0000000000..c8bcb3d14c --- /dev/null +++ b/tests/wrapper/mt_rand_test.php @@ -0,0 +1,46 @@ +assertEquals(42, $result); + } + + public function test_max_equals_min_negative() + { + $result = phpbb_mt_rand(-42, -42); + $this->assertEquals(-42, $result); + } + + public function test_max_greater_min() + { + $result = phpbb_mt_rand(3, 4); + $this->assertGreaterThanOrEqual(3, $result); + $this->assertLessThanOrEqual(4, $result); + } + + public function test_min_greater_max() + { + $result = phpbb_mt_rand(4, 3); + $this->assertGreaterThanOrEqual(3, $result); + $this->assertLessThanOrEqual(4, $result); + } + + public function test_min_greater_max_negative() + { + $result = phpbb_mt_rand(-3, -4); + $this->assertGreaterThanOrEqual(-4, $result); + $this->assertLessThanOrEqual(-3, $result); + } +} -- cgit v1.2.1 From fdfd4ce5fdec03f3341a6b477e242f2674f20b1e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 13 Jul 2011 02:35:11 +0200 Subject: [ticket/10263] Adding unit tests for phpbb_version_compare(). PHPBB3-10263 --- tests/wrapper/version_compare_test.php | 130 +++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 tests/wrapper/version_compare_test.php (limited to 'tests') diff --git a/tests/wrapper/version_compare_test.php b/tests/wrapper/version_compare_test.php new file mode 100644 index 0000000000..f718cfd16b --- /dev/null +++ b/tests/wrapper/version_compare_test.php @@ -0,0 +1,130 @@ +assertEquals(-1, phpbb_version_compare('1.0.0', '1.0.1')); + $this->assertEquals(0, phpbb_version_compare('1.0.0', '1.0.0')); + $this->assertEquals(1, phpbb_version_compare('1.0.1', '1.0.0')); + } + + public function test_three_parameters() + { + $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.1', '<')); + $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '<=')); + $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '=')); + $this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '>=')); + $this->assertEquals(true, phpbb_version_compare('1.0.1', '1.0.0', '>')); + } + + public function test_strict_order() + { + $releases = array( + '2.0.0', + '2.0.1', + // Those are not version_compare() compatible + //'2.0.6a', + //'2.0.6b', + //'2.0.6c', + //'2.0.6d', + '2.0.7', + '2.0.23', + '3.0.A1', + '3.0.A2', + '3.0.A3', + '3.0.B1', + '3.0.B2', + '3.0.B4', + '3.0.B5', + '3.0.RC1', + '3.0.RC5', + '3.0.0', + '3.0.1', + '3.0.2', + '3.0.7', + '3.0.7-PL1', + '3.0.8-RC1', + '3.0.8', + '3.0.9-dev', + '3.0.9-RC1', + '3.0.9-RC2', + '3.0.9-RC4', + '3.0.10-RC1', + '3.1-dev', + '3.2-A1', + ); + + for ($i = 0, $size = sizeof($releases); $i < $size - 1; ++$i) + { + $version1 = $releases[$i]; + $version2 = $releases[$i + 1]; + + $this->assertEquals( + true, + phpbb_version_compare($version1, $version2, '<'), + "Result of version comparison $version1 < $version2 is incorrect." + ); + } + } + + /** + * @dataProvider equality_test_data + */ + public function test_equality($version1, $version2) + { + $this->assertEquals( + 0, + phpbb_version_compare($version1, $version2), + "Result of version comparison $version1 = $version2 is incorrect." + ); + + $this->assertEquals( + true, + phpbb_version_compare($version1, $version2, '='), + "Result of version comparison $version1 = $version2 is incorrect." + ); + } + + public function equality_test_data() + { + return array( + array('1.1.0-A2', '1.1.0-a2'), + array('1.1.0-B1', '1.1.0-b1'), + ); + } + + /** + * @dataProvider alpha_beta_test_data + */ + public function test_alpha_beta($expected, $version1, $version2) + { + $this->assertEquals( + $expected, + phpbb_version_compare($version1, $version2), + "Result of version comparison ($version1, $version2) = $expected is incorrect." + ); + + } + + public function alpha_beta_test_data() + { + return array( + array(-1, '1.1.0-A2', '1.1.0-B1'), + array(-1, '1.1.0-a2', '1.1.0-b1'), + + array(-1, '1.1.0-a2', '1.1.0-B1'), + array(-1, '1.1.0-A2', '1.1.0-b1'), + ); + } + +} -- cgit v1.2.1 From 0bf6966c5228d446c4f0d3862619db0f619c7369 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 13 Jul 2011 19:20:16 +0200 Subject: [feature/request-class] Add server(), header() and is_ajax() to request Extend the request class with helpers for reading server vars (server()) and HTTP request headers (header()). Refactor the existing code base to make use of these helpers, make $_SERVER a deactivated super global. Also introduce an is_ajax() method, which checks the X-Requested-With header for the value 'XMLHttpRequest', which is sent by JavaScript libraries, such as jQuery. PHPBB3-9716 --- tests/bbcode/url_bbcode_test.php | 4 +++- tests/download/http_byte_range_test.php | 12 ++++++---- tests/mock/request.php | 35 +++++++++++++++++++++++++-- tests/request/request_test.php | 15 +++++++++++- tests/request/type_cast_helper_test.php | 10 ++++++++ tests/security/base.php | 36 +++++++++++++++------------- tests/security/extract_current_page_test.php | 16 +++++++++---- 7 files changed, 100 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index cd85dbd0d9..68c97ede50 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -12,6 +12,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/request.php'; class phpbb_url_bbcode_test extends phpbb_test_case { @@ -51,8 +52,9 @@ class phpbb_url_bbcode_test extends phpbb_test_case */ public function test_url($description, $message, $expected) { - global $user; + global $user, $request; $user = new phpbb_mock_user; + $request = new phpbb_mock_request; $bbcode = new bbcode_firstpass(); $bbcode->message = $message; diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php index ba2caee192..36cbcab0b0 100644 --- a/tests/download/http_byte_range_test.php +++ b/tests/download/http_byte_range_test.php @@ -8,23 +8,27 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; +require_once dirname(__FILE__) . '/../mock/request.php'; class phpbb_download_http_byte_range_test extends phpbb_test_case { public function test_find_range_request() { // Missing 'bytes=' prefix - $_SERVER['HTTP_RANGE'] = 'bztes='; + $GLOBALS['request'] = new phpbb_mock_request(); + $GLOBALS['request']->set_header('Range', 'bztes='); $this->assertEquals(false, phpbb_find_range_request()); - unset($_SERVER['HTTP_RANGE']); + unset($GLOBALS['request']); + $GLOBALS['request'] = new phpbb_mock_request(); $_ENV['HTTP_RANGE'] = 'bztes='; $this->assertEquals(false, phpbb_find_range_request()); unset($_ENV['HTTP_RANGE']); - $_SERVER['HTTP_RANGE'] = 'bytes=0-0,123-125'; + $GLOBALS['request'] = new phpbb_mock_request(); + $GLOBALS['request']->set_header('Range', 'bytes=0-0,123-125'); $this->assertEquals(array('0-0', '123-125'), phpbb_find_range_request()); - unset($_SERVER['HTTP_RANGE']); + unset($GLOBALS['request']); } /** diff --git a/tests/mock/request.php b/tests/mock/request.php index da4015e78b..63f3f820ba 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -11,12 +11,13 @@ class phpbb_mock_request implements phpbb_request_interface { protected $data; - public function __construct($get = array(), $post = array(), $cookie = array(), $request = false) + public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false) { $this->data[phpbb_request_interface::GET] = $get; $this->data[phpbb_request_interface::POST] = $post; $this->data[phpbb_request_interface::COOKIE] = $cookie; $this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request; + $this->data[phpbb_request_interface::SERVER] = $server; } public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) @@ -24,11 +25,23 @@ class phpbb_mock_request implements phpbb_request_interface $this->data[$super_global][$var_name] = $value; } - public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) + public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true) { return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; } + public function server($var_name, $default = '', $html_encode = false) + { + $super_global = phpbb_request_interface::SERVER; + return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; + } + + public function header($header_name, $default = '', $html_encode = false) + { + $var_name = 'HTTP_'.str_replace('-', '_', strtoupper($header_name)); + return $this->server($var_name, $default, $html_encode); + } + public function is_set_post($name) { return $this->is_set($name, phpbb_request_interface::POST); @@ -39,8 +52,26 @@ class phpbb_mock_request implements phpbb_request_interface return isset($this->data[$super_global][$var]); } + public function is_ajax() + { + return false; + } + public function variable_names($super_global = phpbb_request_interface::REQUEST) { return array_keys($this->data[$super_global]); } + + /* custom methods */ + + public function set_header($header_name, $value) + { + $var_name = 'HTTP_'.str_replace('-', '_', strtoupper($header_name)); + $this->data[phpbb_request_interface::SERVER][$var_name] = $value; + } + + public function merge($super_global = phpbb_request_interface::REQUEST, $values) + { + $this->data[$super_global] = array_merge($this->data[$super_global], $values); + } } diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 203c9fd880..9999e88121 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -23,7 +23,6 @@ class phpbb_request_test extends phpbb_test_case $_GET['unset'] = ''; $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $this->request = new phpbb_request($this->type_cast_helper); } @@ -60,6 +59,20 @@ class phpbb_request_test extends phpbb_test_case $this->assertFalse($this->request->is_set_post('unset')); } + public function test_is_ajax_without_ajax() + { + $this->assertFalse($this->request->is_ajax()); + } + + public function test_is_ajax_with_ajax() + { + $this->request->enable_super_globals(); + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->request = new phpbb_request($this->type_cast_helper); + + $this->assertTrue($this->request->is_ajax()); + } + public function test_variable_names() { $expected = array('test', 'unset'); diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 06cf2e1bf6..0103c51561 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -48,4 +48,14 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->assertEquals($expected, $data); } + + public function test_simple_set_var_without_html_encoding() + { + $data = 'eviL<3'; + $expected = 'eviL<3'; + + $this->type_cast_helper->recursive_set_var($data, '', true, false); + + $this->assertEquals($expected, $data); + } } diff --git a/tests/security/base.php b/tests/security/base.php index db9c884cf4..4b259a2aac 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/../mock/request.php'; + abstract class phpbb_security_test_base extends phpbb_test_case { /** @@ -14,20 +16,20 @@ abstract class phpbb_security_test_base extends phpbb_test_case */ protected function setUp() { - global $user, $phpbb_root_path; + global $user, $phpbb_root_path, $request; // Put this into a global function being run by every test to init a proper user session - $_SERVER['HTTP_HOST'] = 'localhost'; - $_SERVER['SERVER_NAME'] = 'localhost'; - $_SERVER['SERVER_ADDR'] = '127.0.0.1'; - $_SERVER['SERVER_PORT'] = 80; - $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - $_SERVER['QUERY_STRING'] = ''; - $_SERVER['REQUEST_URI'] = '/tests/'; - $_SERVER['SCRIPT_NAME'] = '/tests/index.php'; - $_SERVER['PHP_SELF'] = '/tests/index.php'; - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; + $server['HTTP_HOST'] = 'localhost'; + $server['SERVER_NAME'] = 'localhost'; + $server['SERVER_ADDR'] = '127.0.0.1'; + $server['SERVER_PORT'] = 80; + $server['REMOTE_ADDR'] = '127.0.0.1'; + $server['QUERY_STRING'] = ''; + $server['REQUEST_URI'] = '/tests/'; + $server['SCRIPT_NAME'] = '/tests/index.php'; + $server['PHP_SELF'] = '/tests/index.php'; + $server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; + $server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; /* [HTTP_ACCEPT_ENCODING] => gzip,deflate @@ -36,13 +38,15 @@ abstract class phpbb_security_test_base extends phpbb_test_case [SCRIPT_FILENAME] => /var/www/tests/index.php */ + $request = new phpbb_mock_request(array(), array(), array(), $server); + // Set no user and trick a bit to circumvent errors $user = new user(); $user->lang = true; - $user->browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : ''; - $user->referer = (!empty($_SERVER['HTTP_REFERER'])) ? htmlspecialchars((string) $_SERVER['HTTP_REFERER']) : ''; - $user->forwarded_for = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? (string) $_SERVER['HTTP_X_FORWARDED_FOR'] : ''; - $user->host = (!empty($_SERVER['HTTP_HOST'])) ? (string) strtolower($_SERVER['HTTP_HOST']) : ((!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : getenv('SERVER_NAME')); + $user->browser = $server['HTTP_USER_AGENT']; + $user->referer = ''; + $user->forwarded_for = ''; + $user->host = $server['HTTP_HOST']; $user->page = session::extract_current_page($phpbb_root_path); } diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 71c7a3a397..34c7b52f49 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -27,8 +27,12 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base */ public function test_query_string_php_self($url, $query_string, $expected) { - $_SERVER['PHP_SELF'] = $url; - $_SERVER['QUERY_STRING'] = $query_string; + global $request; + + $request->merge(phpbb_request_interface::SERVER, array( + 'PHP_SELF' => $url, + 'QUERY_STRING' => $query_string, + )); $result = session::extract_current_page('./'); @@ -41,8 +45,12 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base */ public function test_query_string_request_uri($url, $query_string, $expected) { - $_SERVER['REQUEST_URI'] = $url . '?' . $query_string; - $_SERVER['QUERY_STRING'] = $query_string; + global $request; + + $request->merge(phpbb_request_interface::SERVER, array( + 'PHP_SELF' => $url, + 'QUERY_STRING' => $query_string, + )); $result = session::extract_current_page('./'); -- cgit v1.2.1 From 76aa24e6b7d4c17f2494782b11a6d13b22905f38 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 16 Jul 2011 14:59:52 +0200 Subject: [feature/request-class] Minor spacing CS adjustments PHPBB3-9716 --- tests/mock/request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mock/request.php b/tests/mock/request.php index 63f3f820ba..86b8695e32 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -38,7 +38,7 @@ class phpbb_mock_request implements phpbb_request_interface public function header($header_name, $default = '', $html_encode = false) { - $var_name = 'HTTP_'.str_replace('-', '_', strtoupper($header_name)); + $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); return $this->server($var_name, $default, $html_encode); } @@ -66,7 +66,7 @@ class phpbb_mock_request implements phpbb_request_interface public function set_header($header_name, $value) { - $var_name = 'HTTP_'.str_replace('-', '_', strtoupper($header_name)); + $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); $this->data[phpbb_request_interface::SERVER][$var_name] = $value; } -- cgit v1.2.1 From ee203b46328f3a0e1297197e50b30487d1eab248 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 17 Jul 2011 01:42:42 -0400 Subject: [feature/template-engine] Test template DEFINE statements across files PHPBB3-9726 --- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ tests/template/templates/define_include.html | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/template/templates/define_include.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index df3f927c22..2a5a53637d 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -130,7 +130,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc", + "xyz\nabc\nabc\nbar\nbar\nabc", ), array( 'expressions.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 82237d21a3..4459fffbe0 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -2,6 +2,9 @@ {$VALUE} {$VALUE} + +{$INCLUDED_VALUE} +{$VALUE} {$VALUE} diff --git a/tests/template/templates/define_include.html b/tests/template/templates/define_include.html new file mode 100644 index 0000000000..9c470c296a --- /dev/null +++ b/tests/template/templates/define_include.html @@ -0,0 +1,3 @@ +{$VALUE} + +{$INCLUDED_VALUE} -- cgit v1.2.1 From e116561348b7bd3400bfe6acccf5eebaaaa7f562 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 24 Jul 2011 13:37:46 -0400 Subject: [feature/template-engine] Rename is_absolute to phpbb_is_absolute. PHPBB3-9726 --- tests/template/includephp_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index 64240e1be8..aac9cccc8a 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -26,7 +26,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case public function test_includephp_absolute() { $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; - $this->assertTrue(is_absolute($path_to_php)); + $this->assertTrue(phpbb_is_absolute($path_to_php)); $template_text = "Path is absolute.\n"; $cache_dir = dirname($this->template->cachepath) . '/'; -- cgit v1.2.1 From 05b71ca04e8584428d335512a199e8c71c53a74f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 30 Jul 2011 17:06:22 -0400 Subject: [feature/template-engine] Factor template locator out of template class. Template locator is responsible for maintaining mapping from template handles to filenames and paths, and provides resolution services using these mappings. Template locator is aware of template inheritance and is capable of checking template file existence on the filesystem. PHPBB3-9726 --- tests/template/template_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 2a5a53637d..44baeaf8f0 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -256,7 +256,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $expecting = sprintf('_source_file_for_handle(): File %s does not exist', realpath($this->template_path . '/../') . '/templates/' . $filename); + $expecting = sprintf('template locator: File %s does not exist', realpath($this->template_path . '/../') . '/templates/' . $filename); $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); @@ -264,7 +264,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case public function test_empty_file() { - $expecting = 'template->set_filenames: Empty filename specified for test'; + $expecting = 'template locator: set_filenames: Empty filename specified for test'; $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->template->set_filenames(array('test' => '')); -- cgit v1.2.1 From 24e9fb24d105b8e475dbaf66fd99be2839b86675 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 6 Aug 2011 19:47:12 +0200 Subject: [feature/request-class] Make server() use the $html_encode parameter $request->server() should not auto html-escape values. header() however should. Also introduce some tests for this behaviour. Thanks to nn- for catching this. PHPBB3-9716 --- tests/request/request_test.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 9999e88121..24c9ae5112 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -22,6 +22,10 @@ class phpbb_request_test extends phpbb_test_case $_REQUEST['test'] = 3; $_GET['unset'] = ''; + $_SERVER['HTTP_HOST'] = 'example.com'; + $_SERVER['HTTP_ACCEPT'] = 'application/json'; + $_SERVER['HTTP_SOMEVAR'] = ''; + $this->type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); $this->request = new phpbb_request($this->type_cast_helper); } @@ -43,6 +47,46 @@ class phpbb_request_test extends phpbb_test_case $this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']'); } + public function test_server() + { + $this->assertEquals('example.com', $this->request->server('HTTP_HOST')); + } + + public function test_server_escaping() + { + $this->type_cast_helper + ->expects($this->once()) + ->method('recursive_set_var') + ->with( + $this->anything(), + '', + true, + false + ); + + $this->request->server('HTTP_SOMEVAR'); + } + + public function test_header() + { + $this->assertEquals('application/json', $this->request->header('Accept')); + } + + public function test_header_escaping() + { + $this->type_cast_helper + ->expects($this->once()) + ->method('recursive_set_var') + ->with( + $this->anything(), + '', + true, + true + ); + + $this->request->header('SOMEVAR'); + } + /** * Checks that directly accessing $_POST will trigger * an error. -- cgit v1.2.1 From f99719967955244b63ae01659a39f8b0890a6856 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 7 Aug 2011 16:12:48 -0400 Subject: [ticket/10309] Write unicode data to tests/tmp. When the tests are run by a different user than the one which owns phpbb source tree, writes will go into a single, known directory. PHPBB3-10309 --- tests/utf/normalizer_test.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php index f78dba8004..5cd68bccfa 100644 --- a/tests/utf/normalizer_test.php +++ b/tests/utf/normalizer_test.php @@ -14,10 +14,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_normalizer.php'; */ class phpbb_utf_normalizer_test extends phpbb_test_case { + private static $data_dir; + static public function setUpBeforeClass() { - self::download('http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt', dirname(__FILE__).'/data'); - self::download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt', dirname(__FILE__).'/data'); + self::$data_dir = dirname(__file__) . '/../tmp'; + self::download('http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt', self::$data_dir); + self::download('http://www.unicode.org/Public/UNIDATA/UnicodeData.txt', self::$data_dir); } public function test_normalizer() @@ -62,7 +65,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case $tested_chars = array(); - $fp = fopen(dirname(__FILE__).'/data/NormalizationTest.txt', 'rb'); + $fp = fopen(self::$data_dir . '/NormalizationTest.txt', 'rb'); while (!feof($fp)) { $line = fgets($fp); @@ -117,7 +120,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case */ public function test_invariants(array $tested_chars) { - $fp = fopen(dirname(__FILE__).'/data/UnicodeData.txt', 'rb'); + $fp = fopen(self::$data_dir . '/UnicodeData.txt', 'rb'); while (!feof($fp)) { -- cgit v1.2.1 From 3df8b214cc15d8539f89df5f4a4c19d4cf8f37d0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 9 Aug 2011 21:16:38 -0400 Subject: [ticket/10309] Coding guidelines fix. PHPBB3-10309 --- tests/utf/normalizer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php index 5cd68bccfa..a0ba470416 100644 --- a/tests/utf/normalizer_test.php +++ b/tests/utf/normalizer_test.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_normalizer.php'; */ class phpbb_utf_normalizer_test extends phpbb_test_case { - private static $data_dir; + static private $data_dir; static public function setUpBeforeClass() { -- cgit v1.2.1 From acb767f14d6300ebff793f87b1a62ebbb4bde82a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 9 Aug 2011 23:28:40 -0400 Subject: [feature/template-engine] Dependency inject locator into template. PHPBB3-9726 --- tests/template/template_inheritance_test.php | 3 ++- tests/template/template_test_case.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php index ed78cc7ee5..d62562ff0d 100644 --- a/tests/template/template_inheritance_test.php +++ b/tests/template/template_inheritance_test.php @@ -68,7 +68,8 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t $this->template_path = dirname(__FILE__) . '/templates'; $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); + $this->template_locator = new phpbb_template_locator(); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator); $this->template->set_custom_template($this->template_path, 'tests', $this->parent_template_path); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index c87b54f973..e475e4012f 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -13,6 +13,7 @@ class phpbb_template_template_test_case extends phpbb_test_case { protected $template; protected $template_path; + protected $template_locator; // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; @@ -41,7 +42,8 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->template_path = dirname(__FILE__) . '/templates'; - $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user); + $this->template_locator = new phpbb_template_locator(); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->template_locator); $this->template->set_custom_template($this->template_path, 'tests'); } -- cgit v1.2.1 From 18f19b03ab703d0eb09627dcd162ba556316a451 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 10 Aug 2011 16:43:43 +0200 Subject: [ticket/9297] Unit tests for ftp_fsock PASV and EPSV. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/network/ftp_fsock_test.php (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php new file mode 100644 index 0000000000..c6364f7383 --- /dev/null +++ b/tests/network/ftp_fsock_test.php @@ -0,0 +1,48 @@ +assert_ls_contains_debian($ipv4); + $this->assert_ls_contains_debian("[$ipv6]"); + } + + protected function assert_ls_contains_debian($hostname) + { + $o = $this->get_object($hostname); + $o->_init(); + $this->assertContains('debian', $o->_ls()); + $o->_close(); + } + + protected function get_object($hostname) + { + return new ftp_fsock($hostname, 'anonymous', 'anonymous@localost.tld', '/'); + } +} -- cgit v1.2.1 From 83fa6cffc3be5e89c9c5a992f02366d79aaf0406 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 11 Aug 2011 23:10:53 +0200 Subject: [ticket/9297] Make EPSV unit tests work without IPv6. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index c6364f7383..8b97a1c59d 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -17,20 +17,19 @@ class phpbb_ftp_fsock_test extends phpbb_test_case { public function test_pasv_epsv() { - foreach (dns_get_record('ftp.debian.org', DNS_A | DNS_AAAA) as $row) + $hostname = 'ftp.debian.org.'; + $ipv4 = gethostbyname($hostname); + + if ($ipv4 == $hostname) { - if (isset($row['ip'])) - { - $ipv4 = $row['ip']; - } - else if (isset($row['ipv6'])) - { - $ipv6 = $row['ipv6']; - } + $this->markTestSkipped("Got no A record back from DNS query for $hostname"); } + // PASV $this->assert_ls_contains_debian($ipv4); - $this->assert_ls_contains_debian("[$ipv6]"); + + // EPSV + $this->assert_ls_contains_debian("[::ffff:$ipv4]"); } protected function assert_ls_contains_debian($hostname) -- cgit v1.2.1 From 7a40ab8f7a520ee5d446ce3cdebe130338c74fd5 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 14 Aug 2011 18:17:16 +0200 Subject: [ticket/9297] Update copyright year of unit test file. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index 8b97a1c59d..0470e63126 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2010 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From 386883cda1b0be64a77ddeaff1b5a52acaa97648 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 14 Aug 2011 13:19:09 -0400 Subject: [ticket/9297] Separate ipv4 and ipv6 tests into separate functions. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index 0470e63126..ab45c0202b 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -15,19 +15,28 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_transfer.php'; */ class phpbb_ftp_fsock_test extends phpbb_test_case { - public function test_pasv_epsv() + static protected $ipv4; + + static public function setUpBeforeClass() { $hostname = 'ftp.debian.org.'; - $ipv4 = gethostbyname($hostname); + self::$ipv4 = gethostbyname($hostname); - if ($ipv4 == $hostname) + if (self::$ipv4 == $hostname) { $this->markTestSkipped("Got no A record back from DNS query for $hostname"); } + } + public function test_pasv() + { // PASV - $this->assert_ls_contains_debian($ipv4); + $this->assert_ls_contains_debian(self::$ipv4); + } + public function test_epsv() + { + $ipv4 = self::$ipv4; // EPSV $this->assert_ls_contains_debian("[::ffff:$ipv4]"); } -- cgit v1.2.1 From 2973ccbd48f9cc8a16cfad8f3ab0e9fc36b36763 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 14 Aug 2011 14:11:58 -0400 Subject: [ticket/9297] Skip FTP PASV/EPSV test if FTP connection fails. It is possible to configure PHP without IPv6, in which case IPv6-encapsulated IPv4 addresses won't be accepted by PHP. Instead of failing the test suite on such setups, skip the offending test. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index ab45c0202b..93b15074db 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -44,7 +44,16 @@ class phpbb_ftp_fsock_test extends phpbb_test_case protected function assert_ls_contains_debian($hostname) { $o = $this->get_object($hostname); - $o->_init(); + $result = $o->_init(); + // PHP can connect to IPv6 addresses which are IPv6-encapsulated + // IPv4 addresses on systems that don't have IPv6 connectivity, + // provided that PHP was built with IPv6 support. + // If this test fails on such an IPv6-encapsulated IPv4 address, + // check whether you disabled IPv6 support in your PHP. + if ($result !== true) + { + $this->markTestSkipped("Failed to connect to $hostname: $result"); + } $this->assertContains('debian', $o->_ls()); $o->_close(); } -- cgit v1.2.1 From c2114920925d753e7286145c01c7ef7486362619 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 14 Aug 2011 14:33:00 -0400 Subject: [ticket/9297] Fix markTestSkipped call in setUpBeforeClass. Need to use the static version here. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index 93b15074db..b801ae4037 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -24,7 +24,7 @@ class phpbb_ftp_fsock_test extends phpbb_test_case if (self::$ipv4 == $hostname) { - $this->markTestSkipped("Got no A record back from DNS query for $hostname"); + self::markTestSkipped("Got no A record back from DNS query for $hostname"); } } -- cgit v1.2.1 From 2a0c9e4026d3f8e1f5bcfc9e00319ba4515f0b2f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 14 Aug 2011 14:42:53 -0400 Subject: [ticket/9297] Adjust comment - IPv6 is needed for IPv6 connections to work. Looks like IPv6-encapsulated IPv4 addresses do not actually work if the host has no IPv6 connectivity. PHPBB3-9297 --- tests/network/ftp_fsock_test.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php index b801ae4037..cfffe8fd67 100644 --- a/tests/network/ftp_fsock_test.php +++ b/tests/network/ftp_fsock_test.php @@ -45,11 +45,9 @@ class phpbb_ftp_fsock_test extends phpbb_test_case { $o = $this->get_object($hostname); $result = $o->_init(); - // PHP can connect to IPv6 addresses which are IPv6-encapsulated - // IPv4 addresses on systems that don't have IPv6 connectivity, - // provided that PHP was built with IPv6 support. - // If this test fails on such an IPv6-encapsulated IPv4 address, - // check whether you disabled IPv6 support in your PHP. + // This test may fail on IPv6 addresses if IPv6 support is + // not available. PHP must be compiled with IPv6 support enabled, + // and your operating system must be configured for IPv6 as well. if ($result !== true) { $this->markTestSkipped("Failed to connect to $hostname: $result"); -- cgit v1.2.1 From a7e709d92092de1eb9b0e35f45f1679ee10ce39b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 14 Aug 2011 14:47:16 -0400 Subject: [ticket/9297] Rename test class to reflect its contents. setUpBeforeClass logic makes this test specific to PASV/EPSV tests. PHPBB3-9297 --- tests/network/ftp_fsock_pasv_epsv_test.php | 63 ++++++++++++++++++++++++++++++ tests/network/ftp_fsock_test.php | 63 ------------------------------ 2 files changed, 63 insertions(+), 63 deletions(-) create mode 100644 tests/network/ftp_fsock_pasv_epsv_test.php delete mode 100644 tests/network/ftp_fsock_test.php (limited to 'tests') diff --git a/tests/network/ftp_fsock_pasv_epsv_test.php b/tests/network/ftp_fsock_pasv_epsv_test.php new file mode 100644 index 0000000000..af45fc2d61 --- /dev/null +++ b/tests/network/ftp_fsock_pasv_epsv_test.php @@ -0,0 +1,63 @@ +assert_ls_contains_debian(self::$ipv4); + } + + public function test_epsv() + { + $ipv4 = self::$ipv4; + // EPSV + $this->assert_ls_contains_debian("[::ffff:$ipv4]"); + } + + protected function assert_ls_contains_debian($hostname) + { + $o = $this->get_object($hostname); + $result = $o->_init(); + // This test may fail on IPv6 addresses if IPv6 support is + // not available. PHP must be compiled with IPv6 support enabled, + // and your operating system must be configured for IPv6 as well. + if ($result !== true) + { + $this->markTestSkipped("Failed to connect to $hostname: $result"); + } + $this->assertContains('debian', $o->_ls()); + $o->_close(); + } + + protected function get_object($hostname) + { + return new ftp_fsock($hostname, 'anonymous', 'anonymous@localost.tld', '/'); + } +} diff --git a/tests/network/ftp_fsock_test.php b/tests/network/ftp_fsock_test.php deleted file mode 100644 index cfffe8fd67..0000000000 --- a/tests/network/ftp_fsock_test.php +++ /dev/null @@ -1,63 +0,0 @@ -assert_ls_contains_debian(self::$ipv4); - } - - public function test_epsv() - { - $ipv4 = self::$ipv4; - // EPSV - $this->assert_ls_contains_debian("[::ffff:$ipv4]"); - } - - protected function assert_ls_contains_debian($hostname) - { - $o = $this->get_object($hostname); - $result = $o->_init(); - // This test may fail on IPv6 addresses if IPv6 support is - // not available. PHP must be compiled with IPv6 support enabled, - // and your operating system must be configured for IPv6 as well. - if ($result !== true) - { - $this->markTestSkipped("Failed to connect to $hostname: $result"); - } - $this->assertContains('debian', $o->_ls()); - $o->_close(); - } - - protected function get_object($hostname) - { - return new ftp_fsock($hostname, 'anonymous', 'anonymous@localost.tld', '/'); - } -} -- cgit v1.2.1 From 702985c9279eb9b4704deb9e4356fe37e60b68a2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 14 Aug 2011 20:55:21 +0200 Subject: [ticket/9297] Fix typo in localhost. PHPBB3-9297 --- tests/network/ftp_fsock_pasv_epsv_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_pasv_epsv_test.php b/tests/network/ftp_fsock_pasv_epsv_test.php index af45fc2d61..110bd702a5 100644 --- a/tests/network/ftp_fsock_pasv_epsv_test.php +++ b/tests/network/ftp_fsock_pasv_epsv_test.php @@ -58,6 +58,6 @@ class phpbb_ftp_fsock_pasv_epsv_test extends phpbb_test_case protected function get_object($hostname) { - return new ftp_fsock($hostname, 'anonymous', 'anonymous@localost.tld', '/'); + return new ftp_fsock($hostname, 'anonymous', 'anonymous@localhost.tld', '/'); } } -- cgit v1.2.1 From 02a8cebd65111442f63d4819b74e27c8cbd61006 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 14 Aug 2011 21:40:02 +0200 Subject: [ticket/9297] Add network to class name of unit tests. PHPBB3-9297 --- tests/network/ftp_fsock_pasv_epsv_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/network/ftp_fsock_pasv_epsv_test.php b/tests/network/ftp_fsock_pasv_epsv_test.php index 110bd702a5..6ad811e3ca 100644 --- a/tests/network/ftp_fsock_pasv_epsv_test.php +++ b/tests/network/ftp_fsock_pasv_epsv_test.php @@ -13,7 +13,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_transfer.php'; /** * @group slow */ -class phpbb_ftp_fsock_pasv_epsv_test extends phpbb_test_case +class phpbb_network_ftp_fsock_pasv_epsv_test extends phpbb_test_case { static protected $ipv4; -- cgit v1.2.1 From a48889fed83b007202e76ddf1ba5436eca310df0 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 18 Aug 2011 22:21:50 +0200 Subject: [feature/request-class] Add is_secure method to request for HTTPS PHPBB3-9716 --- tests/mock/request.php | 5 +++++ tests/request/request_test.php | 11 +++++++++++ 2 files changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/mock/request.php b/tests/mock/request.php index 86b8695e32..18aa2e724c 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -57,6 +57,11 @@ class phpbb_mock_request implements phpbb_request_interface return false; } + public function is_secure() + { + return false; + } + public function variable_names($super_global = phpbb_request_interface::REQUEST) { return array_keys($this->data[$super_global]); diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 24c9ae5112..2e56841601 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -117,6 +117,17 @@ class phpbb_request_test extends phpbb_test_case $this->assertTrue($this->request->is_ajax()); } + public function test_is_secure() + { + $this->assertFalse($this->request->is_secure()); + + $this->request->enable_super_globals(); + $_SERVER['HTTPS'] = 'on'; + $this->request = new phpbb_request($this->type_cast_helper); + + $this->assertTrue($this->request->is_secure()); + } + public function test_variable_names() { $expected = array('test', 'unset'); -- cgit v1.2.1 From fd08cd8dd013c0d1bf8e18611f798c6987d9de9c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 18 Aug 2011 23:19:48 +0200 Subject: [feature/request-class] Remove $html_encode arg, force manual decoding PHPBB3-9716 --- tests/mock/request.php | 8 ++++---- tests/request/request_test.php | 4 +--- tests/request/type_cast_helper_test.php | 10 ---------- 3 files changed, 5 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/mock/request.php b/tests/mock/request.php index 18aa2e724c..8b2708304c 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -25,21 +25,21 @@ class phpbb_mock_request implements phpbb_request_interface $this->data[$super_global][$var_name] = $value; } - public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true) + public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) { return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; } - public function server($var_name, $default = '', $html_encode = false) + public function server($var_name, $default = '') { $super_global = phpbb_request_interface::SERVER; return isset($this->data[$super_global][$var_name]) ? $this->data[$super_global][$var_name] : $default; } - public function header($header_name, $default = '', $html_encode = false) + public function header($header_name, $default = '') { $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name)); - return $this->server($var_name, $default, $html_encode); + return $this->server($var_name, $default); } public function is_set_post($name) diff --git a/tests/request/request_test.php b/tests/request/request_test.php index 2e56841601..e492fa5cf1 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -60,8 +60,7 @@ class phpbb_request_test extends phpbb_test_case ->with( $this->anything(), '', - true, - false + true ); $this->request->server('HTTP_SOMEVAR'); @@ -80,7 +79,6 @@ class phpbb_request_test extends phpbb_test_case ->with( $this->anything(), '', - true, true ); diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 0103c51561..06cf2e1bf6 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -48,14 +48,4 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->assertEquals($expected, $data); } - - public function test_simple_set_var_without_html_encoding() - { - $data = 'eviL<3'; - $expected = 'eviL<3'; - - $this->type_cast_helper->recursive_set_var($data, '', true, false); - - $this->assertEquals($expected, $data); - } } -- cgit v1.2.1 From b05382d226d2c5d68ff5a483d8885f65e754c90d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 19 Aug 2011 00:13:34 +0200 Subject: [feature/request-class] Fix session_testable_factory PHPBB3-9716 --- tests/session/testable_factory.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index 2b6a1683d3..3d4fbcc7cb 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -73,7 +73,8 @@ class phpbb_session_testable_factory $request = $this->request = new phpbb_mock_request( array(), array(), - $this->cookies + $this->cookies, + $this->server_data ); request_var(null, null, null, null, $request); @@ -85,8 +86,6 @@ class phpbb_session_testable_factory $cache = $this->cache = new phpbb_mock_cache($this->get_cache_data()); $SID = $_SID = null; - $_SERVER = $this->server_data; - $session = new phpbb_mock_session_testable; return $session; } -- cgit v1.2.1 From 57accade85a431725af7745230ac26b000ff831a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 20 Aug 2011 14:34:02 -0400 Subject: [ticket/10309] Update .gitignore and move .gitkeep. PHPBB3-10309 --- tests/tmp/.gitkeep | 0 tests/utf/data/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/tmp/.gitkeep delete mode 100644 tests/utf/data/.gitkeep (limited to 'tests') diff --git a/tests/tmp/.gitkeep b/tests/tmp/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/utf/data/.gitkeep b/tests/utf/data/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 -- cgit v1.2.1 From dc149a43e49c1c2160549e25792c5ee650861e02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Aug 2011 13:14:15 +0200 Subject: [ticket/10321] Do not append the ? if the param-list is empty anyway. PHPBB3-10321 --- tests/session/append_sid_test.php | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/session/append_sid_test.php (limited to 'tests') diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php new file mode 100644 index 0000000000..4a95b2d20e --- /dev/null +++ b/tests/session/append_sid_test.php @@ -0,0 +1,51 @@ + 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php'), + array('viewtopic.php', '', true, false, 'viewtopic.php'), + array('viewtopic.php', array(), true, false, 'viewtopic.php'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected) + { + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} + -- cgit v1.2.1 From 5d66faafc159da90fbbc6d9888b0a6eee9570cd8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 21 Aug 2011 18:56:47 +0200 Subject: [ticket/10321] Add descriptions to the unit tests PHPBB3-10321 --- tests/session/append_sid_test.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 4a95b2d20e..1a3ad633e3 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -15,35 +15,35 @@ class phpbb_session_append_sid_test extends phpbb_test_case public function append_sid_data() { return array( - array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2'), - array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2'), - array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2'), - array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2'), + array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2', 'parameters in url-argument'), + array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using amp'), + array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'), + array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), // Custom sid parameter - array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid'), + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), // Testing anchors - array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor'), - array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor'), + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), // Anchors and custom sid - array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), - array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor'), + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), // Empty parameters should not append the ? - array('viewtopic.php', false, true, false, 'viewtopic.php'), - array('viewtopic.php', '', true, false, 'viewtopic.php'), - array('viewtopic.php', array(), true, false, 'viewtopic.php'), + array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), + array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), + array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), ); } /** * @dataProvider append_sid_data */ - public function test_append_sid($url, $params, $is_amp, $session_id, $expected) + public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) { $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); } -- cgit v1.2.1 From fa5c7f6440282891dba1142920157971b90b5ad1 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Mon, 22 Aug 2011 15:35:47 +0100 Subject: [ticket/10240] Added censor_text tests. PHPBB-10240 --- tests/mock/cache.php | 22 +++++++++ tests/mock_user.php | 12 +++++ tests/text_processing/censor_text_test.php | 73 ++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 tests/text_processing/censor_text_test.php (limited to 'tests') diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 11e525ff79..020574b0bb 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -41,6 +41,28 @@ class phpbb_mock_cache { return $this->data['_bots']; } + + /** + * Obtain list of word censors. We don't need to parse them here, + * that is tested elsewhere. + */ + public function obtain_word_list() + { + return array( + 'match' => array( + '#(? array( + 'replacement1', + 'replacement2', + 'replacement3', + 'replacement4', + ), + ); + } public function set_bots($bots) { diff --git a/tests/mock_user.php b/tests/mock_user.php index 74d31c4c4a..a6ff5f6628 100644 --- a/tests/mock_user.php +++ b/tests/mock_user.php @@ -17,4 +17,16 @@ class phpbb_mock_user { public $host = "testhost"; public $page = array('root_script_path' => '/'); + + public function optionget($item) + { + switch ($item) + { + case 'viewcensors': + return false; + + default: + trigger_error('Option not found, add it to the mock user object.'); + } + } } diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php new file mode 100644 index 0000000000..3820a1135f --- /dev/null +++ b/tests/text_processing/censor_text_test.php @@ -0,0 +1,73 @@ +assertEquals(censor_text($input), $expected, $label); + } +} -- cgit v1.2.1 From e7ab7f5f7a3e72c94df6e16360a1594c96618caa Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 10:56:36 +0100 Subject: [ticket/10240] Added censor_text tests for special characters. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 3820a1135f..ac620597b9 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -59,6 +59,16 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case array('badword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'), array('badword1 badword2 badword3 badword4d', 'replacement1 replacement2 replacement3 badword4d'), array('abadword1 badword2 badword3 badword4', 'replacement1 replacement2 replacement3 replacement4'), + + array("new\nline\ntest", "new\nline\ntest"), + array("tab\ttest\t", "tab\ttest\t"), + array('öäü', 'öäü'), + array('badw' . chr(1) . 'ord1', 'badw' . chr(1) . 'ord1'), + array('badw' . chr(2) . 'ord1', 'badw' . chr(2) . 'ord1'), + array('badw' . chr(3) . 'ord1', 'badw' . chr(3) . 'ord1'), + array('badw' . chr(4) . 'ord1', 'badw' . chr(4) . 'ord1'), + array('badw' . chr(5) . 'ord1', 'badw' . chr(5) . 'ord1'), + array('badw' . chr(6) . 'ord1', 'badw' . chr(6) . 'ord1'), ); } -- cgit v1.2.1 From 0d104b00c887db311576ab390ed2c79d2fb8ec99 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 11:32:35 +0100 Subject: [ticket/10240] Fixed censor_text test assetEquals param order. Before, expected and input were the wrong way round. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index ac620597b9..1d4b3fa943 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -78,6 +78,6 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case public function test_censor_text($input, $expected) { $label = 'Testing word censor: ' . $input; - $this->assertEquals(censor_text($input), $expected, $label); + $this->assertEquals($expected, censor_text($input), $label); } } -- cgit v1.2.1 From d4f1b92479aeaab313d18c172e5e2fede7035281 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 11:38:59 +0100 Subject: [ticket/10240] Fixed copyright year in censor_text_test.php. PHPBB3-10240 --- tests/text_processing/censor_text_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 1d4b3fa943..6138d92e65 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From 03da3c7c4c2d3957b738485935386723c536671b Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 23 Aug 2011 12:21:20 +0100 Subject: [ticket/10240] Added optionset to mock_user in the tests. Also made optionset use the value set by optionset. We're not checking whether the option is set or not, because we would just throw an error if it wasn't set, and it throws an error anyway. PHPBB3-10240 --- tests/mock_user.php | 16 ++++++++++------ tests/text_processing/censor_text_test.php | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/mock_user.php b/tests/mock_user.php index a6ff5f6628..5b89ea3e19 100644 --- a/tests/mock_user.php +++ b/tests/mock_user.php @@ -18,15 +18,19 @@ class phpbb_mock_user public $host = "testhost"; public $page = array('root_script_path' => '/'); + private $options = array(); public function optionget($item) { - switch ($item) + if (!isset($this->options[$item])) { - case 'viewcensors': - return false; - - default: - trigger_error('Option not found, add it to the mock user object.'); + throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item)); } + + return $this->options[$item]; + } + + public function optionset($item, $value) + { + $this->options[$item] = $value; } } diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 6138d92e65..2843f0b20b 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -19,6 +19,8 @@ class phpbb_text_processing_censor_text_test extends phpbb_test_case global $cache, $user; $cache = new phpbb_mock_cache; $user = new phpbb_mock_user; + + $user->optionset('viewcensors', false); return array( array('', ''), -- cgit v1.2.1 From 0f2e45800e9e88c86bdf335cac6a9974ec8f0385 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 14:24:50 -0400 Subject: [ticket/10346] Add drop_tables to perform_schema_changes and add tests PHPBB3-10346 --- tests/dbal/db_tools_test.php | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index ddea500f83..753cc08fc5 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -271,6 +271,66 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case 'foo' => array('UINT', 42))) ); + $this->assertTrue($this->tools->sql_table_exists('prefix_test_table')); + $this->tools->sql_table_drop('prefix_test_table'); + + $this->assertFalse($this->tools->sql_table_exists('prefix_test_table')); + } + + public function test_peform_schema_changes_drop_tables() + { + $db_tools = $this->getMock('phpbb_db_tools', array( + 'sql_table_exists', + 'sql_table_drop', + ), array(&$this->db)); + + // pretend all tables exist + $db_tools->expects($this->any())->method('sql_table_exists') + ->will($this->returnValue(true)); + + // drop tables + $db_tools->expects($this->exactly(2))->method('sql_table_drop'); + $db_tools->expects($this->at(1))->method('sql_table_drop') + ->with($this->equalTo('dropped_table_1')); + $db_tools->expects($this->at(3))->method('sql_table_drop') + ->with($this->equalTo('dropped_table_2')); + + $db_tools->perform_schema_changes(array( + 'drop_tables' => array( + 'dropped_table_1', + 'dropped_table_2', + ), + )); + } + + public function test_peform_schema_changes_drop_columns() + { + $db_tools = $this->getMock('phpbb_db_tools', array( + 'sql_column_exists', + 'sql_column_remove', + ), array(&$this->db)); + + // pretend all columns exist + $db_tools->expects($this->any())->method('sql_column_exists') + ->will($this->returnValue(true)); + $db_tools->expects($this->any())->method('sql_column_exists') + ->will($this->returnValue(true)); + + // drop columns + $db_tools->expects($this->exactly(2))->method('sql_column_remove'); + $db_tools->expects($this->at(1))->method('sql_column_remove') + ->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_1')); + $db_tools->expects($this->at(3))->method('sql_column_remove') + ->with($this->equalTo('existing_table'), $this->equalTo('dropped_column_2')); + + $db_tools->perform_schema_changes(array( + 'drop_columns' => array( + 'existing_table' => array( + 'dropped_column_1', + 'dropped_column_2', + ), + ), + )); } } -- cgit v1.2.1 From bcaf65d7cd951b9a453cac413c420cb418b42f8d Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sat, 3 Sep 2011 17:26:36 -0500 Subject: [ticket/10349] Unit tests: Remove comments while loading schema files Perform the same operations that the installer does when preparing the schema files. These functions come straight from /includes/functions_install.php and /includes/functions_admin.php. PHPBB3-10349 --- .../phpbb_database_test_connection_manager.php | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index a7559e2183..78be831ecb 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -234,7 +234,12 @@ class phpbb_database_test_connection_manager } $filename = $directory . $schema . '_schema.sql'; - $sql = $this->split_sql(file_get_contents($filename)); + $remove_remarks = $this->dbms['COMMENTS']; + + $queries = file_get_contents($filename); + $this->$remove_remarks($queries); + + $sql = $this->split_sql($queries); foreach ($sql as $query) { @@ -279,6 +284,49 @@ class phpbb_database_test_connection_manager return $data; } + /** + * remove_remarks will strip the sql comment lines out of an uploaded sql file + */ + protected function remove_remarks(&$sql) + { + $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); + } + + /** + * remove_comments will strip the sql comment lines out of an uploaded sql file + * specifically for mssql and postgres type files in the install.... + */ + protected function remove_comments(&$output) + { + $lines = explode("\n", $output); + $output = ''; + + // try to keep mem. use down + $linecount = sizeof($lines); + + $in_comment = false; + for ($i = 0; $i < $linecount; $i++) + { + if (trim($lines[$i]) == '/*') + { + $in_comment = true; + } + + if (!$in_comment) + { + $output .= $lines[$i] . "\n"; + } + + if (trim($lines[$i]) == '*/') + { + $in_comment = false; + } + } + + unset($lines); + return $output; + } + /** * Map a phpBB dbms driver name to dbms data array */ @@ -289,46 +337,55 @@ class phpbb_database_test_connection_manager 'SCHEMA' => 'firebird', 'DELIM' => ';;', 'PDO' => 'firebird', + 'COMMENTS' => 'remove_remarks', ), 'mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', 'PDO' => 'mysql', + 'COMMENTS' => 'remove_remarks', ), 'mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', 'PDO' => 'mysql', + 'COMMENTS' => 'remove_remarks', ), 'mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', + 'COMMENTS' => 'remove_comments', ), 'mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', + 'COMMENTS' => 'remove_comments', ), 'mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'sqlsrv', + 'COMMENTS' => 'remove_comments', ), 'oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', 'PDO' => 'oci', + 'COMMENTS' => 'remove_comments', ), 'postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', 'PDO' => 'pgsql', + 'COMMENTS' => 'remove_comments', ), 'sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', 'PDO' => 'sqlite2', + 'COMMENTS' => 'remove_remarks', ), ); -- cgit v1.2.1 From 1061e881bd21f0308ce33a395084d291cf2fd0e3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 5 Sep 2011 01:20:57 -0400 Subject: [ticket/10354] Include cache directory path in unwritable message. When template tests are skipped because cache directory is not writable, include path to the cache directory into the message saying it is not writable. PHPBB3-10354 --- tests/template/template_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 33c82d53ad..5005710220 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -63,9 +63,10 @@ class phpbb_template_template_test extends phpbb_test_case // Test the engine can be used $this->setup_engine(); - if (!is_writable(dirname($this->template->cachepath))) + $template_cache_dir = dirname($this->template->cachepath); + if (!is_writable($template_cache_dir)) { - $this->markTestSkipped("Template cache directory is not writable."); + $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable."); } foreach (glob($this->template->cachepath . '*') as $file) -- cgit v1.2.1 From 511f2e04350e08ba1412a92e86427ed97775e1f4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 5 Sep 2011 02:07:44 -0400 Subject: [ticket/10355] Correctly end output buffering in template tests. This code was copied verbatim from develop-olympus. PHPBB3-10355 --- tests/template/template_test_case.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index e475e4012f..7cf995f194 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -21,8 +21,22 @@ class phpbb_template_template_test_case extends phpbb_test_case protected function display($handle) { ob_start(); - $this->assertTrue($this->template->display($handle)); - return self::trim_template_result(ob_get_clean()); + + try + { + $this->assertTrue($this->template->display($handle, false)); + } + catch (Exception $exception) + { + // reset output buffering even when an error occured + // PHPUnit turns trigger_error into exceptions as well + ob_end_clean(); + throw $exception; + } + + $result = self::trim_template_result(ob_get_clean()); + + return $result; } protected static function trim_template_result($result) -- cgit v1.2.1 From d8f4f92dae2af2acba1719c9532561ec1143af66 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 5 Sep 2011 11:57:18 +0300 Subject: [ticket/10350] Script for testing eval renderer Script for testing eval renderer (fixed) PHPBB3-10350 --- tests/template/renderer_eval_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/template/renderer_eval_test.php (limited to 'tests') diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php new file mode 100644 index 0000000000..c30516ba97 --- /dev/null +++ b/tests/template/renderer_eval_test.php @@ -0,0 +1,31 @@ +">'; + $valid_code = ''; + $context = new phpbb_template_context(); + $template = new phpbb_template_renderer_eval($compiled_code, NULL); + ob_start(); + try + { + $template->render($context, array()); + } + catch (Exception $exception) + { + ob_end_clean(); + throw $exception; + } + $output = ob_get_clean(); + $this->assertEquals($valid_code, $output); + } +} -- cgit v1.2.1 From b5ecb2f7a84fc53185572e2a603e8c49fdc85c7a Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Thu, 8 Sep 2011 17:54:59 -0500 Subject: [ticket/10322] Dynamic template include test PHPBB3-10322 --- tests/template/template_test.php | 7 +++++++ tests/template/templates/include_variable.html | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 tests/template/templates/include_variable.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 44baeaf8f0..a200148a29 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -162,6 +162,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'value', ), + array( + 'include_variable.html', + array('FILE' => 'variable.html', 'VARIABLE' => 'value'), + array(), + array(), + "value\nvalue", + ), array( 'loop_vars.html', array(), diff --git a/tests/template/templates/include_variable.html b/tests/template/templates/include_variable.html new file mode 100644 index 0000000000..a126372195 --- /dev/null +++ b/tests/template/templates/include_variable.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file -- cgit v1.2.1 From b5a79009cebe926058b745621158a105a45648a1 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Fri, 16 Sep 2011 01:46:42 -0500 Subject: [ticket/10322] Separate template varref resolution from output generation Most template variables can now have their PHP variable name resolved instead of only compiling directly. This allows for the use of block vars in INCLUDE statements. This does not work for language variables since they require multiple checks. Added tests for the new types of allowed INCLUDEs. PHPBB3-10322 --- tests/template/template_test.php | 16 +++++++++++++++- tests/template/templates/include_define.html | 2 ++ tests/template/templates/include_loop.html | 4 ++++ tests/template/templates/include_loop1.html | 1 + tests/template/templates/include_loop2.html | 1 + tests/template/templates/include_loop3.html | 1 + tests/template/templates/include_variable.html | 2 -- 7 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/template/templates/include_define.html create mode 100644 tests/template/templates/include_loop.html create mode 100644 tests/template/templates/include_loop1.html create mode 100644 tests/template/templates/include_loop2.html create mode 100644 tests/template/templates/include_loop3.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index a200148a29..28eba05217 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -162,12 +162,26 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'value', ), + array( + 'include_define.html', + array('VARIABLE' => 'value'), + array(), + array(), + 'value', + ), + array( + 'include_loop.html', + array(), + array('loop' => array(array('NESTED_FILE' => 'include_loop1.html')), 'loop.inner' => array(array('NESTED_FILE' => 'include_loop1.html'), array('NESTED_FILE' => 'include_loop2.html'), array('NESTED_FILE' => 'include_loop3.html'))), + array(), + "1\n_1\n_02\n_3", + ), array( 'include_variable.html', array('FILE' => 'variable.html', 'VARIABLE' => 'value'), array(), array(), - "value\nvalue", + 'value', ), array( 'loop_vars.html', diff --git a/tests/template/templates/include_define.html b/tests/template/templates/include_define.html new file mode 100644 index 0000000000..2419c8cba1 --- /dev/null +++ b/tests/template/templates/include_define.html @@ -0,0 +1,2 @@ + + diff --git a/tests/template/templates/include_loop.html b/tests/template/templates/include_loop.html new file mode 100644 index 0000000000..d5c3d9bc82 --- /dev/null +++ b/tests/template/templates/include_loop.html @@ -0,0 +1,4 @@ + + +_ + diff --git a/tests/template/templates/include_loop1.html b/tests/template/templates/include_loop1.html new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/template/templates/include_loop1.html @@ -0,0 +1 @@ +1 diff --git a/tests/template/templates/include_loop2.html b/tests/template/templates/include_loop2.html new file mode 100644 index 0000000000..9e22bcb8e3 --- /dev/null +++ b/tests/template/templates/include_loop2.html @@ -0,0 +1 @@ +02 diff --git a/tests/template/templates/include_loop3.html b/tests/template/templates/include_loop3.html new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tests/template/templates/include_loop3.html @@ -0,0 +1 @@ +3 diff --git a/tests/template/templates/include_variable.html b/tests/template/templates/include_variable.html index a126372195..b907e0b44f 100644 --- a/tests/template/templates/include_variable.html +++ b/tests/template/templates/include_variable.html @@ -1,3 +1 @@ - - \ No newline at end of file -- cgit v1.2.1 From 7b3f6cb219cac448ba470f016ed5068bdc7ffc56 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 18 Sep 2011 00:55:24 +0200 Subject: [ticket/10369] Always include errfile and errline in format_errors(). We remove the phpBB root path from errfile. This is consistent with how msg_handler handles E_WARNING messages etc. PHPBB3-10369 --- tests/error_collector_test.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/error_collector_test.php (limited to 'tests') diff --git a/tests/error_collector_test.php b/tests/error_collector_test.php new file mode 100644 index 0000000000..e1ac32f5ac --- /dev/null +++ b/tests/error_collector_test.php @@ -0,0 +1,35 @@ +install(); + + // Cause a warning + 1/0; $line = __LINE__; + + $collector->uninstall(); + + list($errno, $msg_text, $errfile, $errline) = $collector->errors[0]; + $error_contents = $collector->format_errors(); + + $this->assertEquals($errno, 2); + + // Unfortunately $error_contents will contain the full path here, + // because the tests directory is outside of phpbb root path. + $this->assertStringStartsWith('Errno 2: Division by zero at ', $error_contents); + $this->assertStringEndsWith(" line $line", $error_contents); + } +} -- cgit v1.2.1 From 4bc11db0ffc3b387e4ad38b0d9ceccfa58f2738d Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 20 Sep 2011 23:23:03 -0500 Subject: [ticket/10349] Unit tests: Consolidate schema comment removal functions PHPBB3-10349 --- .../phpbb_database_test_connection_manager.php | 69 ++++------------------ 1 file changed, 11 insertions(+), 58 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 78be831ecb..547361b41d 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -234,12 +234,11 @@ class phpbb_database_test_connection_manager } $filename = $directory . $schema . '_schema.sql'; - $remove_remarks = $this->dbms['COMMENTS']; $queries = file_get_contents($filename); - $this->$remove_remarks($queries); + $sql = $this->remove_comments($queries); - $sql = $this->split_sql($queries); + $sql = $this->split_sql($sql); foreach ($sql as $query) { @@ -271,60 +270,23 @@ class phpbb_database_test_connection_manager unset($data[key($data)]); } - if ($this->config['dbms'] == 'sqlite') - { - // remove comment lines starting with # - they are not proper sqlite - // syntax and break sqlite2 - foreach ($data as $i => $query) - { - $data[$i] = preg_replace('/^#.*$/m', "\n", $query); - } - } - return $data; } /** - * remove_remarks will strip the sql comment lines out of an uploaded sql file - */ - protected function remove_remarks(&$sql) - { - $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); - } - - /** - * remove_comments will strip the sql comment lines out of an uploaded sql file - * specifically for mssql and postgres type files in the install.... + * Removes comments from schema files + * + * Note: This performs the functions of remove_remarks() and remove_comments() used during installation */ - protected function remove_comments(&$output) + protected function remove_comments($sql) { - $lines = explode("\n", $output); - $output = ''; - - // try to keep mem. use down - $linecount = sizeof($lines); + // Remove /* */ comments (http://ostermiller.org/findcomment.html) + $sql = preg_replace('#/\*(.|[\r\n])*?\*/#', "\n", $sql); - $in_comment = false; - for ($i = 0; $i < $linecount; $i++) - { - if (trim($lines[$i]) == '/*') - { - $in_comment = true; - } - - if (!$in_comment) - { - $output .= $lines[$i] . "\n"; - } - - if (trim($lines[$i]) == '*/') - { - $in_comment = false; - } - } + // Remove # style comments + $sql = preg_replace('/\n{2,}/', "\n", preg_replace('/^#.*$/m', "\n", $sql)); - unset($lines); - return $output; + return $sql; } /** @@ -337,55 +299,46 @@ class phpbb_database_test_connection_manager 'SCHEMA' => 'firebird', 'DELIM' => ';;', 'PDO' => 'firebird', - 'COMMENTS' => 'remove_remarks', ), 'mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', 'PDO' => 'mysql', - 'COMMENTS' => 'remove_remarks', ), 'mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', 'PDO' => 'mysql', - 'COMMENTS' => 'remove_remarks', ), 'mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', - 'COMMENTS' => 'remove_comments', ), 'mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', - 'COMMENTS' => 'remove_comments', ), 'mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'sqlsrv', - 'COMMENTS' => 'remove_comments', ), 'oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', 'PDO' => 'oci', - 'COMMENTS' => 'remove_comments', ), 'postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', 'PDO' => 'pgsql', - 'COMMENTS' => 'remove_comments', ), 'sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', 'PDO' => 'sqlite2', - 'COMMENTS' => 'remove_remarks', ), ); -- cgit v1.2.1 From fbb5c641b8163861bcb68b87fc08f0481ee54fac Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sat, 24 Sep 2011 20:48:37 +0100 Subject: [ticket/10384] Update unit tests to test for failing variable. PHPBB3-10384 --- tests/template/template_test.php | 10 +++++----- tests/template/templates/lang.html | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 28eba05217..8ea21444f3 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -211,21 +211,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array(), array(), - "{ VARIABLE }\n{ VARIABLE }", + "{ VARIABLE }\n{ 1_VARIABLE }\n{ VARIABLE }\n{ 1_VARIABLE }", ), array( 'lang.html', - array('L_VARIABLE' => "Value'"), + array('L_VARIABLE' => "Value'", 'L_1_VARIABLE' => "1 O'Clock"), array(), array(), - "Value'\nValue\'", + "Value'\n1 O'Clock\nValue\'\n1 O\'Clock", ), array( 'lang.html', - array('LA_VARIABLE' => "Value'"), + array('LA_VARIABLE' => "Value'", 'LA_1_VARIABLE' => "1 O'Clock"), array(), array(), - "{ VARIABLE }\nValue'", + "{ VARIABLE }\n{ 1_VARIABLE }\nValue'\n1 O'Clock", ), array( 'loop_nested_multilevel_ref.html', diff --git a/tests/template/templates/lang.html b/tests/template/templates/lang.html index 2b5ea1cafe..3eecc298cb 100644 --- a/tests/template/templates/lang.html +++ b/tests/template/templates/lang.html @@ -1,3 +1,5 @@ {L_VARIABLE} +{L_1_VARIABLE} {LA_VARIABLE} +{LA_1_VARIABLE} -- cgit v1.2.1 From 118bc6198e87ffd21835d2477039744e23b04cb7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 27 Sep 2011 01:02:58 +0100 Subject: [ticket/10392] Test for magic loop variables with nested namespaces. PHPBB3-10392 --- tests/template/template_test.php | 2 +- tests/template/templates/loop_nested_deep_multilevel_ref.html | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 28eba05217..cf772a5284 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -248,7 +248,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))), array(), // I don't completely understand this output, hopefully it's correct - "top-level content\nouter\n\ninner z\nfirst row\n\ninner zz", + "top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz", ), array( 'loop_size.html', diff --git a/tests/template/templates/loop_nested_deep_multilevel_ref.html b/tests/template/templates/loop_nested_deep_multilevel_ref.html index 60fad7b4cd..bcc2a7c07b 100644 --- a/tests/template/templates/loop_nested_deep_multilevel_ref.html +++ b/tests/template/templates/loop_nested_deep_multilevel_ref.html @@ -2,10 +2,11 @@ top-level content outer + {outer.middle.S_BLOCK_NAME} inner {inner.VARIABLE} - first row + first row of {outer.middle.inner.S_NUM_ROWS} in {middle.inner.S_BLOCK_NAME} -- cgit v1.2.1 From b571b3e0326cc6fe987ceb317ee803d4921cc133 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 27 Sep 2011 17:31:24 +0200 Subject: [ticket/10394] Remove call-time pass by reference from tests for PHP 5.4 PHPBB3-10394 --- tests/profile/custom_test.php | 2 +- tests/utf/normalizer_test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/profile/custom_test.php b/tests/profile/custom_test.php index 0e0a851243..585182e583 100644 --- a/tests/profile/custom_test.php +++ b/tests/profile/custom_test.php @@ -48,7 +48,7 @@ class phpbb_profile_custom_test extends phpbb_database_test_case ); $cp = new custom_profile; - $result = $cp->validate_profile_field(FIELD_DROPDOWN, &$field_value, $field_data); + $result = $cp->validate_profile_field(FIELD_DROPDOWN, $field_value, $field_data); $this->assertEquals($expected, $result, $description); } diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php index a0ba470416..f8f2467082 100644 --- a/tests/utf/normalizer_test.php +++ b/tests/utf/normalizer_test.php @@ -102,7 +102,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case foreach ($tests as $test) { $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), &$utf_result); + call_user_func(array('utf_normalizer', $form), $utf_result); $hex_result = $this->utf_to_hexseq($utf_result); $this->assertEquals($utf_expected, $utf_result, "$expected == $form($test) ($hex_expected != $hex_result)"); @@ -154,7 +154,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) { $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), &$utf_result); + call_user_func(array('utf_normalizer', $form), $utf_result); $hex_result = $this->utf_to_hexseq($utf_result); $this->assertEquals($utf_expected, $utf_result, "$hex_expected == $form($hex_tested) ($hex_expected != $hex_result)"); -- cgit v1.2.1 From b197ea56c23188f4fd160c736c2d1840e987180a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 27 Sep 2011 22:32:20 +0200 Subject: [ticket/10394] Use call_user_func_array to pass a ref into a dynamic function PHPBB3-10394 --- tests/utf/normalizer_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/utf/normalizer_test.php b/tests/utf/normalizer_test.php index f8f2467082..1dc69e283e 100644 --- a/tests/utf/normalizer_test.php +++ b/tests/utf/normalizer_test.php @@ -102,7 +102,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case foreach ($tests as $test) { $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), $utf_result); + call_user_func_array(array('utf_normalizer', $form), array(&$utf_result)); $hex_result = $this->utf_to_hexseq($utf_result); $this->assertEquals($utf_expected, $utf_result, "$expected == $form($test) ($hex_expected != $hex_result)"); @@ -154,7 +154,7 @@ class phpbb_utf_normalizer_test extends phpbb_test_case foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) { $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), $utf_result); + call_user_func_array(array('utf_normalizer', $form), array(&$utf_result)); $hex_result = $this->utf_to_hexseq($utf_result); $this->assertEquals($utf_expected, $utf_result, "$hex_expected == $form($hex_tested) ($hex_expected != $hex_result)"); -- cgit v1.2.1 From b4dcd4193e7ea52753eb3957bb247b768dc48d12 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Wed, 28 Sep 2011 11:27:39 -0500 Subject: [ticket/10349] Update function comment PHPBB3-10349 --- tests/test_framework/phpbb_database_test_connection_manager.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 547361b41d..5feab16496 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -275,8 +275,6 @@ class phpbb_database_test_connection_manager /** * Removes comments from schema files - * - * Note: This performs the functions of remove_remarks() and remove_comments() used during installation */ protected function remove_comments($sql) { -- cgit v1.2.1 From 14f1e581faa3b66e7689c55c1e9c0485c0872b1e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 9 Jun 2011 05:13:26 +0200 Subject: [feature/extension-manager] Extension Manager & Finder Extensions RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41499 Ticket: http://tracker.phpbb.com/browse/PHPBB3-10323 PHPBB3-10323 --- tests/bootstrap.php | 2 +- tests/class_loader/class_loader_test.php | 9 +- tests/class_loader/ext/foo/class.php | 6 + tests/extension/ext/bar/my/hidden_class.php | 5 + tests/extension/ext/foo/a_class.php | 5 + tests/extension/ext/foo/b_class.php | 5 + tests/extension/ext/foo/foo.php | 5 + tests/extension/ext/foo/sub/type/alternative.php | 5 + tests/extension/ext/foo/type/alternative.php | 5 + tests/extension/ext/foo/typewrong/error.php | 5 + tests/extension/ext/moo/feature_class.php | 5 + tests/extension/finder_test.php | 133 +++++++++++++++++++++ tests/extension/fixtures/extensions.xml | 15 +++ .../extension/includes/default/implementation.php | 5 + tests/extension/manager_test.php | 89 ++++++++++++++ tests/mock/extension_manager.php | 16 +++ 16 files changed, 312 insertions(+), 3 deletions(-) create mode 100644 tests/class_loader/ext/foo/class.php create mode 100644 tests/extension/ext/bar/my/hidden_class.php create mode 100644 tests/extension/ext/foo/a_class.php create mode 100644 tests/extension/ext/foo/b_class.php create mode 100644 tests/extension/ext/foo/foo.php create mode 100644 tests/extension/ext/foo/sub/type/alternative.php create mode 100644 tests/extension/ext/foo/type/alternative.php create mode 100644 tests/extension/ext/foo/typewrong/error.php create mode 100644 tests/extension/ext/moo/feature_class.php create mode 100644 tests/extension/finder_test.php create mode 100644 tests/extension/fixtures/extensions.xml create mode 100644 tests/extension/includes/default/implementation.php create mode 100644 tests/extension/manager_test.php create mode 100644 tests/mock/extension_manager.php (limited to 'tests') diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b7c3534cde..fbe23c1835 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,7 +32,7 @@ else require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; -$class_loader = new phpbb_class_loader($phpbb_root_path, '.php'); +$class_loader = new phpbb_class_loader($phpbb_root_path . 'includes/', $phpbb_root_path . 'ext/', '.php'); $class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 0c7fe3f97a..7d5f57aac3 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -26,7 +26,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase public function test_resolve_path() { $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix); + $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/'); $prefix .= 'includes/'; @@ -56,6 +56,11 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $class_loader->resolve_path('phpbb_dir2'), 'Class with name of dir within dir (short class name)' ); + $this->assertEquals( + dirname(__FILE__) . '/ext/foo/class.php', + $class_loader->resolve_path('phpbb_ext_foo_class'), + 'Extension class' + ); } public function test_resolve_cached() @@ -64,7 +69,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $cache = new phpbb_mock_cache($cacheMap); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix, '.php', $cache); + $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/', '.php', $cache); $prefix .= 'includes/'; diff --git a/tests/class_loader/ext/foo/class.php b/tests/class_loader/ext/foo/class.php new file mode 100644 index 0000000000..7b1555c98d --- /dev/null +++ b/tests/class_loader/ext/foo/class.php @@ -0,0 +1,6 @@ +extension_manager = new phpbb_mock_extension_manager(array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/bar/', + ), + )); + + $this->finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/'); + } + + public function test_suffix_get_classes() + { + $classes = $this->finder + ->default_path('includes/default/') + ->suffix('_class') + ->default_suffix('') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_default_implementation', + 'phpbb_ext_bar_my_hidden_class', + 'phpbb_ext_foo_a_class', + 'phpbb_ext_foo_b_class', + ), + $classes + ); + } + + public function test_directory_get_classes() + { + $classes = $this->finder + ->default_path('includes/default/') + ->directory('type') + ->default_directory('') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_default_implementation', + 'phpbb_ext_foo_sub_type_alternative', + 'phpbb_ext_foo_type_alternative', + ), + $classes + ); + } + + public function test_absolute_directory_get_classes() + { + $classes = $this->finder + ->directory('/type/') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_type_alternative', + ), + $classes + ); + } + + public function test_sub_directory_get_classes() + { + $classes = $this->finder + ->directory('/sub/type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_sub_type_alternative', + ), + $classes + ); + } + + public function test_cached_get_files() + { + $query = array( + 'default_path' => 'includes/foo', + 'default_suffix' => false, + 'default_directory' => 'bar', + 'suffix' => false, + 'directory' => false, + ); + + + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( + '_extension_finder' => array( + md5(serialize($query)) => array('file_name'), + ), + ))); + + $classes = $finder + ->default_path($query['default_path']) + ->default_directory($query['default_directory']) + ->get_files(); + + sort($classes); + $this->assertEquals( + array('file_name'), + $classes + ); + } +} diff --git a/tests/extension/fixtures/extensions.xml b/tests/extension/fixtures/extensions.xml new file mode 100644 index 0000000000..f3acdd2575 --- /dev/null +++ b/tests/extension/fixtures/extensions.xml @@ -0,0 +1,15 @@ + + + + ext_name + ext_active + + foo + 1 + + + moo + 0 + +
+
diff --git a/tests/extension/includes/default/implementation.php b/tests/extension/includes/default/implementation.php new file mode 100644 index 0000000000..91d5f8aa2f --- /dev/null +++ b/tests/extension/includes/default/implementation.php @@ -0,0 +1,5 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + // disable the regular class loader to replace it with one that loads + // test extensions + global $class_loader; + $class_loader->unregister(); + + $prefix = dirname(__FILE__) . '/'; + $this->class_loader = new phpbb_class_loader($prefix . '../../phpBB/includes/', $prefix . 'ext/'); + $this->class_loader->register(); + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + 'phpbb_ext', + $prefix, + '.php', + new phpbb_mock_cache + ); + } + + protected function tearDown() + { + global $class_loader; + $class_loader->register(); + } + + public function test_available() + { + $this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_available())); + } + + public function test_enabled() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + } + + public function test_configured() + { + $this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_enable() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->extension_manager->enable('bar'); + $this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_disable() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->extension_manager->disable('foo'); + $this->assertEquals(array(), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured())); + } + + public function test_purge() + { + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured())); + $this->extension_manager->purge('moo'); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); + } +} diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php new file mode 100644 index 0000000000..49d727db37 --- /dev/null +++ b/tests/mock/extension_manager.php @@ -0,0 +1,16 @@ +extensions = $extensions; + } +} -- cgit v1.2.1 From fabde989a2676c762f58e17b06772c9a3ba2f85e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 13 Jul 2011 08:22:27 -0400 Subject: [feature/extension-manager] Porting cron tasks over to the extension finder PHPBB3-10323 --- tests/cron/ext/testext/cron/dummy_task.php | 23 ++++++++++++ tests/cron/includes/cron/task/core/dummy_task.php | 23 ++++++++++++ .../includes/cron/task/core/second_dummy_task.php | 23 ++++++++++++ tests/cron/manager_test.php | 43 +++++++++++----------- .../cron/task/core/simple_not_runnable.php | 13 +++++++ .../root2/includes/cron/task/core/simple_ready.php | 8 ++++ .../cron/task/core/simple_should_not_run.php | 13 +++++++ tests/cron/task/testmod/dummy_task.php | 23 ------------ tests/cron/task/testmod/second_dummy_task.php | 23 ------------ tests/cron/task2/testmod/simple_not_runnable.php | 13 ------- tests/cron/task2/testmod/simple_ready.php | 8 ---- tests/cron/task2/testmod/simple_should_not_run.php | 13 ------- tests/extension/finder_test.php | 30 ++++++++------- tests/mock/extension_manager.php | 4 +- 14 files changed, 144 insertions(+), 116 deletions(-) create mode 100644 tests/cron/ext/testext/cron/dummy_task.php create mode 100644 tests/cron/includes/cron/task/core/dummy_task.php create mode 100644 tests/cron/includes/cron/task/core/second_dummy_task.php create mode 100644 tests/cron/root2/includes/cron/task/core/simple_not_runnable.php create mode 100644 tests/cron/root2/includes/cron/task/core/simple_ready.php create mode 100644 tests/cron/root2/includes/cron/task/core/simple_should_not_run.php delete mode 100644 tests/cron/task/testmod/dummy_task.php delete mode 100644 tests/cron/task/testmod/second_dummy_task.php delete mode 100644 tests/cron/task2/testmod/simple_not_runnable.php delete mode 100644 tests/cron/task2/testmod/simple_ready.php delete mode 100644 tests/cron/task2/testmod/simple_should_not_run.php (limited to 'tests') diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php new file mode 100644 index 0000000000..06546ada05 --- /dev/null +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -0,0 +1,23 @@ +manager = new phpbb_cron_manager(dirname(__FILE__) . '/task/', 'php'); - $this->task_name = 'phpbb_cron_task_testmod_dummy_task'; + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'testext' => array( + 'ext_name' => 'testext', + 'ext_active' => true, + 'ext_path' => dirname(__FILE__) . '/ext/testext/' + ), + )); + $this->manager = new phpbb_cron_manager($this->extension_manager); + $this->task_name = 'phpbb_cron_task_core_dummy_task'; } public function test_manager_finds_shipped_tasks() { $tasks = $this->manager->find_cron_task_names(); - $this->assertEquals(2, sizeof($tasks)); + $this->assertEquals(3, sizeof($tasks)); } public function test_manager_finds_shipped_task_by_name() @@ -45,7 +55,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_all_ready_tasks() { $tasks = $this->manager->find_all_ready_tasks(); - $this->assertEquals(2, sizeof($tasks)); + $this->assertEquals(3, sizeof($tasks)); } public function test_manager_finds_one_ready_task() @@ -54,21 +64,12 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); } - public function test_manager_finds_all_ready_tasks_cached() - { - $cache = new phpbb_mock_cache(array('_cron_tasks' => array($this->task_name))); - $manager = new phpbb_cron_manager(dirname(__FILE__) . '/../../phpBB/', 'php', $cache); - - $tasks = $manager->find_all_ready_tasks(); - $this->assertEquals(1, sizeof($tasks)); - } - public function test_manager_finds_only_ready_tasks() { - $manager = new phpbb_cron_manager(dirname(__FILE__) . '/task2/', 'php'); + $manager = new phpbb_cron_manager(new phpbb_mock_extension_manager(dirname(__FILE__) . '/root2/')); $tasks = $manager->find_all_ready_tasks(); $task_names = $this->tasks_to_names($tasks); - $this->assertEquals(array('phpbb_cron_task_testmod_simple_ready'), $task_names); + $this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names); } private function tasks_to_names($tasks) diff --git a/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php b/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php new file mode 100644 index 0000000000..837f28f1c0 --- /dev/null +++ b/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php @@ -0,0 +1,13 @@ +extension_manager = new phpbb_mock_extension_manager(array( - 'foo' => array( - 'ext_name' => 'foo', - 'ext_active' => '1', - 'ext_path' => dirname(__FILE__) . '/ext/foo/', - ), - 'bar' => array( - 'ext_name' => 'bar', - 'ext_active' => '1', - 'ext_path' => dirname(__FILE__) . '/ext/bar/', - ), - )); - - $this->finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/'); + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => dirname(__FILE__) . '/ext/bar/', + ), + )); + + $this->finder = $this->extension_manager->get_finder(); } public function test_suffix_get_classes() diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 49d727db37..5155716181 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -9,8 +9,10 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager { - public function __construct($extensions = array()) + public function __construct($phpbb_root_path, $extensions = array()) { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = '.php'; $this->extensions = $extensions; } } -- cgit v1.2.1 From 96209e022477d97b581b79cabace4caddd19501b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 15 Aug 2011 21:38:47 -0400 Subject: [feature/extension-manager] The class loader no longer knows about extensions Instead the class loader is instantiated twice. Once with the phpbb_ prefix and once with the phpbb_ext_ prefix. PHPBB3-10323 --- tests/bootstrap.php | 6 +++-- tests/class_loader/class_loader_test.php | 46 +++++++++++++++++++++----------- tests/class_loader/ext/foo/class.php | 6 ----- tests/extension/manager_test.php | 17 +----------- 4 files changed, 35 insertions(+), 40 deletions(-) delete mode 100644 tests/class_loader/ext/foo/class.php (limited to 'tests') diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fbe23c1835..a85091ce23 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -32,8 +32,10 @@ else require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; -$class_loader = new phpbb_class_loader($phpbb_root_path . 'includes/', $phpbb_root_path . 'ext/', '.php'); -$class_loader->register(); +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php"); +$phpbb_class_loader_ext->register(); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); +$phpbb_class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 7d5f57aac3..9744a1c703 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -13,20 +13,26 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase { public function setUp() { - global $class_loader; - $class_loader->unregister(); + global $phpbb_class_loader; + $phpbb_class_loader->unregister(); + + global $phpbb_class_loader_ext; + $phpbb_class_loader_ext->unregister(); } public function tearDown() { - global $class_loader; - $class_loader->register(); + global $phpbb_class_loader_ext; + $phpbb_class_loader_ext->register(); + + global $phpbb_class_loader; + $phpbb_class_loader->register(); } public function test_resolve_path() { $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/'); + $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/'); $prefix .= 'includes/'; @@ -56,20 +62,19 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $class_loader->resolve_path('phpbb_dir2'), 'Class with name of dir within dir (short class name)' ); - $this->assertEquals( - dirname(__FILE__) . '/ext/foo/class.php', - $class_loader->resolve_path('phpbb_ext_foo_class'), - 'Extension class' - ); } public function test_resolve_cached() { - $cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name')); - $cache = new phpbb_mock_cache($cacheMap); + $cache_map = array( + 'class_loader_phpbb_' => array('phpbb_a_cached_name' => 'a/cached_name'), + 'class_loader_phpbb_ext_' => array('phpbb_ext_foo' => 'foo'), + ); + $cache = new phpbb_mock_cache($cache_map); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader($prefix . 'includes/', $prefix . 'ext/', '.php', $cache); + $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', '.php', $cache); + $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', '.php', $cache); $prefix .= 'includes/'; @@ -79,13 +84,22 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase 'Class in a directory' ); + $this->assertFalse($class_loader->resolve_path('phpbb_ext_foo')); + $this->assertFalse($class_loader_ext->resolve_path('phpbb_a_cached_name')); + $this->assertEquals( $prefix . 'a/cached_name.php', $class_loader->resolve_path('phpbb_a_cached_name'), - 'Class in a directory' + 'Cached class found' + ); + + $this->assertEquals( + $prefix . 'foo.php', + $class_loader_ext->resolve_path('phpbb_ext_foo'), + 'Cached class found in alternative loader' ); - $cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name'; - $cache->check($this, $cacheMap); + $cache_map['class_loader_phpbb_']['phpbb_dir_class_name'] = 'dir/class_name'; + $cache->check($this, $cache_map); } } diff --git a/tests/class_loader/ext/foo/class.php b/tests/class_loader/ext/foo/class.php deleted file mode 100644 index 7b1555c98d..0000000000 --- a/tests/class_loader/ext/foo/class.php +++ /dev/null @@ -1,6 +0,0 @@ -unregister(); - - $prefix = dirname(__FILE__) . '/'; - $this->class_loader = new phpbb_class_loader($prefix . '../../phpBB/includes/', $prefix . 'ext/'); - $this->class_loader->register(); - $this->extension_manager = new phpbb_extension_manager( $this->new_dbal(), 'phpbb_ext', - $prefix, + dirname(__FILE__) . '/', '.php', new phpbb_mock_cache ); } - protected function tearDown() - { - global $class_loader; - $class_loader->register(); - } - public function test_available() { $this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_available())); -- cgit v1.2.1 From 5d5030a48be3d65df85d78e26690085c0889c6e3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 21 Aug 2011 02:57:01 -0400 Subject: [feature/extension-manager] Remove cron's dependency on the extension manager. Instead a separate cron provider supplies the manager with tasks from the extension finder. PHPBB3-10323 --- tests/cron/manager_test.php | 33 +++++++--------- tests/cron/provider_test.php | 45 ++++++++++++++++++++++ .../cron/task/core/simple_not_runnable.php | 13 ------- .../root2/includes/cron/task/core/simple_ready.php | 8 ---- .../cron/task/core/simple_should_not_run.php | 13 ------- tests/cron/tasks/simple_not_runnable.php | 13 +++++++ tests/cron/tasks/simple_ready.php | 8 ++++ tests/cron/tasks/simple_should_not_run.php | 13 +++++++ 8 files changed, 92 insertions(+), 54 deletions(-) create mode 100644 tests/cron/provider_test.php delete mode 100644 tests/cron/root2/includes/cron/task/core/simple_not_runnable.php delete mode 100644 tests/cron/root2/includes/cron/task/core/simple_ready.php delete mode 100644 tests/cron/root2/includes/cron/task/core/simple_should_not_run.php create mode 100644 tests/cron/tasks/simple_not_runnable.php create mode 100644 tests/cron/tasks/simple_ready.php create mode 100644 tests/cron/tasks/simple_should_not_run.php (limited to 'tests') diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index 80f2cd55a8..80c92e234b 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -11,33 +11,22 @@ require_once dirname(__FILE__) . '/../mock/extension_manager.php'; require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; -require_once dirname(__FILE__) . '/root2/includes/cron/task/core/simple_ready.php'; -require_once dirname(__FILE__) . '/root2/includes/cron/task/core/simple_not_runnable.php'; -require_once dirname(__FILE__) . '/root2/includes/cron/task/core/simple_should_not_run.php'; +require_once dirname(__FILE__) . '/tasks/simple_ready.php'; +require_once dirname(__FILE__) . '/tasks/simple_not_runnable.php'; +require_once dirname(__FILE__) . '/tasks/simple_should_not_run.php'; class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', - array( - 'testext' => array( - 'ext_name' => 'testext', - 'ext_active' => true, - 'ext_path' => dirname(__FILE__) . '/ext/testext/' - ), - )); - $this->manager = new phpbb_cron_manager($this->extension_manager); + $this->manager = new phpbb_cron_manager(array( + 'phpbb_cron_task_core_dummy_task', + 'phpbb_cron_task_core_second_dummy_task', + 'phpbb_ext_testext_cron_dummy_task', + )); $this->task_name = 'phpbb_cron_task_core_dummy_task'; } - public function test_manager_finds_shipped_tasks() - { - $tasks = $this->manager->find_cron_task_names(); - $this->assertEquals(3, sizeof($tasks)); - } - public function test_manager_finds_shipped_task_by_name() { $task = $this->manager->find_task($this->task_name); @@ -66,7 +55,11 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_only_ready_tasks() { - $manager = new phpbb_cron_manager(new phpbb_mock_extension_manager(dirname(__FILE__) . '/root2/')); + $manager = new phpbb_cron_manager(array( + 'phpbb_cron_task_core_simple_ready', + 'phpbb_cron_task_core_simple_not_runnable', + 'phpbb_cron_task_core_simple_should_not_run', + )); $tasks = $manager->find_all_ready_tasks(); $task_names = $this->tasks_to_names($tasks); $this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names); diff --git a/tests/cron/provider_test.php b/tests/cron/provider_test.php new file mode 100644 index 0000000000..781425e6ab --- /dev/null +++ b/tests/cron/provider_test.php @@ -0,0 +1,45 @@ +extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'testext' => array( + 'ext_name' => 'testext', + 'ext_active' => true, + 'ext_path' => dirname(__FILE__) . '/ext/testext/' + ), + )); + $this->provider = new phpbb_cron_provider($this->extension_manager); + } + + public function test_manager_finds_shipped_tasks() + { + $task_iterator = $this->provider->find_cron_task_names(); + + $tasks = array(); + foreach ($task_iterator as $task) + { + $tasks[] = $task; + } + sort($tasks); + + $this->assertEquals(array( + 'phpbb_cron_task_core_dummy_task', + 'phpbb_cron_task_core_second_dummy_task', + 'phpbb_ext_testext_cron_dummy_task', + ), $tasks); + } +} diff --git a/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php b/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php deleted file mode 100644 index 837f28f1c0..0000000000 --- a/tests/cron/root2/includes/cron/task/core/simple_not_runnable.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Sun, 21 Aug 2011 03:02:48 -0400 Subject: [feature/extension-manager] Add missing newlines at end of files PHPBB3-10323 --- tests/extension/ext/bar/my/hidden_class.php | 2 +- tests/extension/ext/foo/a_class.php | 2 +- tests/extension/ext/foo/b_class.php | 2 +- tests/extension/ext/foo/foo.php | 2 +- tests/extension/ext/foo/type/alternative.php | 2 +- tests/extension/ext/moo/feature_class.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/extension/ext/bar/my/hidden_class.php b/tests/extension/ext/bar/my/hidden_class.php index b3c910a8c2..0261d7c59a 100644 --- a/tests/extension/ext/bar/my/hidden_class.php +++ b/tests/extension/ext/bar/my/hidden_class.php @@ -2,4 +2,4 @@ class phpbb_ext_bar_my_hidden_class { -} \ No newline at end of file +} diff --git a/tests/extension/ext/foo/a_class.php b/tests/extension/ext/foo/a_class.php index 03253139f9..b7be1ad654 100644 --- a/tests/extension/ext/foo/a_class.php +++ b/tests/extension/ext/foo/a_class.php @@ -2,4 +2,4 @@ class phpbb_ext_foo_a_class { -} \ No newline at end of file +} diff --git a/tests/extension/ext/foo/b_class.php b/tests/extension/ext/foo/b_class.php index 04644a9d9d..4645266122 100644 --- a/tests/extension/ext/foo/b_class.php +++ b/tests/extension/ext/foo/b_class.php @@ -2,4 +2,4 @@ class phpbb_ext_foo_b_class { -} \ No newline at end of file +} diff --git a/tests/extension/ext/foo/foo.php b/tests/extension/ext/foo/foo.php index 78a8c95f65..bbf01606ce 100644 --- a/tests/extension/ext/foo/foo.php +++ b/tests/extension/ext/foo/foo.php @@ -2,4 +2,4 @@ class phpbb_ext_foo extends phpbb_extension_base { -} \ No newline at end of file +} diff --git a/tests/extension/ext/foo/type/alternative.php b/tests/extension/ext/foo/type/alternative.php index b43a293b1d..404b66b965 100644 --- a/tests/extension/ext/foo/type/alternative.php +++ b/tests/extension/ext/foo/type/alternative.php @@ -2,4 +2,4 @@ class phpbb_ext_foo_type_alternative { -} \ No newline at end of file +} diff --git a/tests/extension/ext/moo/feature_class.php b/tests/extension/ext/moo/feature_class.php index 20ea13054f..bf7ba40d84 100644 --- a/tests/extension/ext/moo/feature_class.php +++ b/tests/extension/ext/moo/feature_class.php @@ -2,4 +2,4 @@ class phpbb_ext_moo_feature_class { -} \ No newline at end of file +} -- cgit v1.2.1 From f6632fcfd08650f13560529a6a04c152aefd4e3c Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 22 Aug 2011 02:17:00 -0400 Subject: [feature/extension-manager] Add filename prefix matching in extension finder PHPBB3-10323 --- tests/extension/finder_test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index b0c98da554..4acfe53937 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -55,6 +55,24 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_prefix_get_classes() + { + $classes = $this->finder + ->default_path('includes/default/') + ->prefix('hidden_') + ->default_prefix('') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_default_implementation', + 'phpbb_ext_bar_my_hidden_class', + ), + $classes + ); + } + public function test_directory_get_classes() { $classes = $this->finder @@ -109,8 +127,10 @@ class phpbb_extension_finder_test extends phpbb_test_case $query = array( 'default_path' => 'includes/foo', 'default_suffix' => false, + 'default_prefix' => false, 'default_directory' => 'bar', 'suffix' => false, + 'prefix' => false, 'directory' => false, ); -- cgit v1.2.1 From c7a986eccdac183cc81b3da486092f4ab82109ba Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 17:17:40 -0400 Subject: [feature/extension-manager] Use an incremental process for enable and purge The enable or purge operation of an extension could take a long time if an expensive operation needs to be executed on a large set of data. To allow this to succeed from a web interface with max_execution_time set in the webserver's php configuration, subsequent requests must continue the operation started earlier. So individual enable and purge implementations must be able to spread their work across multiple steps. PHPBB3-10323 --- tests/extension/manager_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 2035264559..70c3543a69 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -8,6 +8,8 @@ */ require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/ext/bar/bar.php'; +require_once dirname(__FILE__) . '/ext/moo/moo.php'; class phpbb_extension_manager_test extends phpbb_database_test_case { @@ -49,10 +51,14 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enable() { + phpbb_ext_bar::$state = 0; + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->extension_manager->enable('bar'); $this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('bar', 'foo', 'moo'), array_keys($this->extension_manager->all_configured())); + + $this->assertEquals(4, phpbb_ext_bar::$state); } public function test_disable() @@ -65,10 +71,14 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_purge() { + phpbb_ext_moo::$purged = false; + $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('foo', 'moo'), array_keys($this->extension_manager->all_configured())); $this->extension_manager->purge('moo'); $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); $this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); + + $this->assertTrue(phpbb_ext_moo::$purged); } } -- cgit v1.2.1 From 64827a6623c9a916d41c2ef5bf2c2092a3008722 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:43:45 -0400 Subject: [feature/extension-manager] Test creation of new extension finder cache PHPBB3-10323 --- tests/extension/finder_test.php | 31 ++++++++++++++++++++++++++++++- tests/mock/cache.php | 12 ++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 4acfe53937..fb2faaf5c0 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -122,6 +122,36 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_get_classes_create_cache() + { + $cache = new phpbb_mock_cache; + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache); + $files = $finder->suffix('_class.php')->get_files(); + + sort($files); + + $expected_files = array( + 'ext/bar/my/hidden_class.php', + 'ext/foo/a_class.php', + 'ext/foo/b_class.php', + ); + + $query = array( + 'default_path' => false, + 'default_suffix' => '_class.php', + 'default_prefix' => false, + 'default_directory' => false, + 'suffix' => '_class.php', + 'prefix' => false, + 'directory' => false, + ); + + $this->assertEquals($expected_files, $files); + $cache->checkAssociativeVar($this, '_extension_finder', array( + md5(serialize($query)) => $expected_files, + )); + } + public function test_cached_get_files() { $query = array( @@ -134,7 +164,6 @@ class phpbb_extension_finder_test extends phpbb_test_case 'directory' => false, ); - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( '_extension_finder' => array( md5(serialize($query)) => array('file_name'), diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 989180c256..b745123801 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -59,6 +59,18 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface $test->assertEquals($data, $this->data[$var_name]); } + public function checkAssociativeVar(PHPUnit_Framework_Assert $test, $var_name, $data) + { + $test->assertTrue(isset($this->data[$var_name])); + + foreach ($this->data[$var_name] as &$content) + { + sort($content); + } + + $test->assertEquals($data, $this->data[$var_name]); + } + public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name) { $test->assertFalse(isset($this->data[$var_name])); -- cgit v1.2.1 From 739e9eb58e7e9b899955b714aa3fc8bbe6a30ebc Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:57:21 -0400 Subject: [feature/extension-manager] Make the cache variable name for extensions dynamic Allows multiple instances to use cache simultaneously. PHPBB3-10323 --- tests/extension/finder_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index fb2faaf5c0..cae11a5bfa 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -125,7 +125,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache); + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache, '.php', '_custom_cache_name'); $files = $finder->suffix('_class.php')->get_files(); sort($files); @@ -147,7 +147,7 @@ class phpbb_extension_finder_test extends phpbb_test_case ); $this->assertEquals($expected_files, $files); - $cache->checkAssociativeVar($this, '_extension_finder', array( + $cache->checkAssociativeVar($this, '_custom_cache_name', array( md5(serialize($query)) => $expected_files, )); } @@ -165,7 +165,7 @@ class phpbb_extension_finder_test extends phpbb_test_case ); $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( - '_extension_finder' => array( + '_ext_finder' => array( md5(serialize($query)) => array('file_name'), ), ))); -- cgit v1.2.1 From c785ef7aa7953c5e533e48b11ef13d6b1f344813 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 20:14:23 -0400 Subject: [feature/extension-manager] Make sure the extension manager works without cache Includes a test for manager without a cache PHPBB3-10323 --- tests/extension/manager_test.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 70c3543a69..52be88330a 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -81,4 +81,17 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->assertTrue(phpbb_ext_moo::$purged); } + + public function test_enabled_no_cache() + { + $extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + 'phpbb_ext', + dirname(__FILE__) . '/', + '.php' + ); + + $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled())); + } + } -- cgit v1.2.1 From 0ea4de41711e1b4be601d01882ff52011cf9bf48 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 22:21:20 -0400 Subject: [feature/extension-manager] Add support for directories to the extension finder PHPBB3-10323 --- tests/extension/finder_test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index cae11a5bfa..b8ce8909ee 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -55,6 +55,18 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_prefix_get_directories() + { + $dirs = $this->finder + ->directory('/type') + ->get_directories(); + + sort($dirs); + $this->assertEquals(array( + 'ext/foo/type/', + ), $dirs); + } + public function test_prefix_get_classes() { $classes = $this->finder @@ -144,6 +156,7 @@ class phpbb_extension_finder_test extends phpbb_test_case 'suffix' => '_class.php', 'prefix' => false, 'directory' => false, + 'is_dir' => false, ); $this->assertEquals($expected_files, $files); @@ -162,6 +175,7 @@ class phpbb_extension_finder_test extends phpbb_test_case 'suffix' => false, 'prefix' => false, 'directory' => false, + 'is_dir' => false, ); $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( -- cgit v1.2.1 From 7d16007d6a1c042389039ab9ab59c073ecd7c933 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 22:51:15 -0400 Subject: [feature/extension-manager] Prepend the phpbb_root_path if necessary. PHPBB3-10323 --- tests/extension/finder_test.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index b8ce8909ee..8d7d38d4d8 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -63,7 +63,7 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($dirs); $this->assertEquals(array( - 'ext/foo/type/', + dirname(__FILE__) . '/ext/foo/type/', ), $dirs); } @@ -137,7 +137,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache, '.php', '_custom_cache_name'); + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/', $cache, '.php', '_custom_cache_name'); $files = $finder->suffix('_class.php')->get_files(); sort($files); @@ -159,7 +159,6 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $this->assertEquals($expected_files, $files); $cache->checkAssociativeVar($this, '_custom_cache_name', array( md5(serialize($query)) => $expected_files, )); @@ -178,7 +177,7 @@ class phpbb_extension_finder_test extends phpbb_test_case 'is_dir' => false, ); - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/', new phpbb_mock_cache(array( '_ext_finder' => array( md5(serialize($query)) => array('file_name'), ), @@ -191,7 +190,7 @@ class phpbb_extension_finder_test extends phpbb_test_case sort($classes); $this->assertEquals( - array('file_name'), + array(dirname(__FILE__) . '/file_name'), $classes ); } -- cgit v1.2.1 From 6c6a7d7992460e301615bcc1e13bee92ecc65724 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 30 Aug 2011 00:06:15 -0400 Subject: [feature/extension-manager] Extract extension provider functionality from cron PHPBB3-10323 --- tests/cron/provider_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cron/provider_test.php b/tests/cron/provider_test.php index 781425e6ab..3a0545ffc6 100644 --- a/tests/cron/provider_test.php +++ b/tests/cron/provider_test.php @@ -27,10 +27,8 @@ class phpbb_cron_provider_test extends PHPUnit_Framework_TestCase public function test_manager_finds_shipped_tasks() { - $task_iterator = $this->provider->find_cron_task_names(); - $tasks = array(); - foreach ($task_iterator as $task) + foreach ($this->provider as $task) { $tasks[] = $task; } -- cgit v1.2.1 From 6ea6d50ccb9607429486a01d3144c7d32322e1b5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 30 Aug 2011 01:15:43 -0400 Subject: [feature/extension-manager] Don't cache the phpbb_root_path in the ext manager Otherwise the paths are incorrect from e.g. adm/ PHPBB3-10323 --- tests/cron/provider_test.php | 2 +- tests/extension/finder_test.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/cron/provider_test.php b/tests/cron/provider_test.php index 3a0545ffc6..662bb34c13 100644 --- a/tests/cron/provider_test.php +++ b/tests/cron/provider_test.php @@ -19,7 +19,7 @@ class phpbb_cron_provider_test extends PHPUnit_Framework_TestCase 'testext' => array( 'ext_name' => 'testext', 'ext_active' => true, - 'ext_path' => dirname(__FILE__) . '/ext/testext/' + 'ext_path' => 'ext/testext/' ), )); $this->provider = new phpbb_cron_provider($this->extension_manager); diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 8d7d38d4d8..9031e1cb47 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -23,12 +23,12 @@ class phpbb_extension_finder_test extends phpbb_test_case 'foo' => array( 'ext_name' => 'foo', 'ext_active' => '1', - 'ext_path' => dirname(__FILE__) . '/ext/foo/', + 'ext_path' => 'ext/foo/', ), 'bar' => array( 'ext_name' => 'bar', 'ext_active' => '1', - 'ext_path' => dirname(__FILE__) . '/ext/bar/', + 'ext_path' => 'ext/bar/', ), )); -- cgit v1.2.1 From ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 30 Aug 2011 01:32:11 -0400 Subject: [feature/extension-manager] Add support for templates in extensions. This commit adds a template path provider to separate the process of locating (cached) paths in extensions from the template engine. The locator is supplied with a list of paths from the path provider. Admin templates can now be created in ext//adm/style/ and regular templates go into ext//styles/