mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 16:56:44 +02:00
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/10714
* 'develop' of https://github.com/phpbb/phpbb3: (158 commits) [ticket/11015] Move comment in the right place. [ticket/11015] Correctly transform 'mysqli' etc. in phpbb_convert_30_dbms_to_31 [ticket/11015] Fix 3.0 to 3.1 dbms conversion for mysqli. [ticket/11015] Change permission adding in database updater to new style. [ticket/11015] Change more docblocks to phpbb_db_driver. [ticket/11015] Installer still needs 3.0-style dbms name. [ticket/11262] Add .lock in cache directory to .gitignore [ticket/11015] Include functions.php because it is not always included. [ticket/11265] Add assertions for board installation success. [ticket/11263] Fix PHP Notice: Undefined variable: extension_manager [ticket/11015] Convert database drivers to new spelling in post setup sync. [ticket/11015] Convert connect test to the new syntax. [ticket/11015] Restore whitespace to avoid conflict when merging develop. [ticket/10975] Add a test for viewing a profile. [ticket/10975] Test restricting by first character. [ticket/10975] Avoid rewriting global config twice. [ticket/10975] Test memberlist, not user creation. [ticket/10975] Some quick tests to check the memberlist behaviour [ticket/11162] Reformat. [ticket/10491] Make recreate_database static. ...
This commit is contained in:
@@ -30,7 +30,7 @@ example for mysqli can be found below. More information on configuration
|
||||
options can be found on the wiki (see below).
|
||||
|
||||
<?php
|
||||
$dbms = 'mysqli';
|
||||
$dbms = 'phpbb_db_driver_mysqli';
|
||||
$dbhost = 'localhost';
|
||||
$dbport = '';
|
||||
$dbname = 'database';
|
||||
|
41
tests/dbal/connect_test.php
Normal file
41
tests/dbal/connect_test.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_dbal_connect_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
|
||||
}
|
||||
|
||||
public function test_failing_connect()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$config = $this->get_database_config();
|
||||
|
||||
$db = new $config['dbms']();
|
||||
|
||||
// Failure to connect results in a trigger_error call in dbal.
|
||||
// phpunit converts triggered errors to exceptions.
|
||||
// In particular there should be no fatals here.
|
||||
try
|
||||
{
|
||||
$db->sql_connect($config['dbhost'], 'phpbbogus', 'phpbbogus', 'phpbbogus', $config['dbport']);
|
||||
$this->assertFalse(true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// should have a legitimate message
|
||||
$this->assertNotEmpty($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -33,6 +33,10 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
// dbal uses cache
|
||||
global $cache;
|
||||
$cache = new phpbb_mock_cache();
|
||||
|
||||
$sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array(
|
||||
'username' => $username,
|
||||
'username_clean' => $username,
|
||||
|
@@ -9,7 +9,6 @@
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
|
||||
|
||||
class phpbb_di_container_test extends phpbb_test_case
|
||||
{
|
||||
@@ -52,7 +51,7 @@ class phpbb_di_container_test extends phpbb_test_case
|
||||
}
|
||||
}
|
||||
|
||||
class dbal_container_mock extends dbal
|
||||
class phpbb_db_driver_container_mock extends phpbb_db_driver
|
||||
{
|
||||
public function sql_connect()
|
||||
{
|
||||
|
6
tests/fixtures/empty.xml
vendored
6
tests/fixtures/empty.xml
vendored
@@ -1,5 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_posts">
|
||||
<table name="phpbb_sessions">
|
||||
<column>session_id</column>
|
||||
<column>session_user_id</column>
|
||||
<column>session_ip</column>
|
||||
<column>session_browser</column>
|
||||
</table>
|
||||
</dataset>
|
||||
|
@@ -18,9 +18,19 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
|
||||
|
||||
// check for logout link
|
||||
$crawler = $this->request('GET', 'index.php');
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
|
||||
}
|
||||
|
||||
public function test_login_other()
|
||||
{
|
||||
$this->create_user('anothertestuser');
|
||||
$this->login('anothertestuser');
|
||||
$crawler = $this->request('GET', 'index.php');
|
||||
$this->assert_response_success();
|
||||
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_login
|
||||
*/
|
||||
@@ -31,10 +41,12 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
|
||||
|
||||
// logout
|
||||
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
|
||||
|
||||
// look for a register link, which should be visible only when logged out
|
||||
$crawler = $this->request('GET', 'index.php');
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
|
||||
}
|
||||
}
|
||||
|
43
tests/functional/memberlist_test.php
Normal file
43
tests/functional/memberlist_test.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class phpbb_functional_memberlist_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function test_memberlist()
|
||||
{
|
||||
$this->create_user('memberlist-test-user');
|
||||
// logs in as admin
|
||||
$this->login();
|
||||
$crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains('memberlist-test-user', $crawler->text());
|
||||
|
||||
// restrict by first character
|
||||
$crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains('memberlist-test-user', $crawler->text());
|
||||
|
||||
// make sure results for wrong character are not returned
|
||||
$crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertNotContains('memberlist-test-user', $crawler->text());
|
||||
}
|
||||
|
||||
public function test_viewprofile()
|
||||
{
|
||||
$this->login();
|
||||
// XXX hardcoded user id
|
||||
$crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains('admin', $crawler->filter('h2')->text());
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case
|
||||
{
|
||||
public function build_hidden_fields_for_query_params_test_data()
|
||||
{
|
||||
return array(
|
||||
// get
|
||||
// post
|
||||
// exclude
|
||||
// expected
|
||||
array(
|
||||
array('foo' => 'bar'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => 'b'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />",
|
||||
),
|
||||
array(
|
||||
array('a' => 'quote"', 'b' => '<less>'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />",
|
||||
),
|
||||
array(
|
||||
array('a' => "quotes'\""),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"a\" value=\"quotes'"\" />",
|
||||
),
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => 'b'),
|
||||
array('a' => 'c'),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
// strict equality check
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => '0'),
|
||||
array('a' => ''),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_hidden_fields_for_query_params_test_data
|
||||
*/
|
||||
public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected)
|
||||
{
|
||||
$request = new phpbb_mock_request($get, $post);
|
||||
$result = phpbb_build_hidden_fields_for_query_params($request, $exclude);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
40
tests/functions/convert_30_dbms_to_31_test.php
Normal file
40
tests/functions/convert_30_dbms_to_31_test.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
|
||||
{
|
||||
public function convert_30_dbms_to_31_data()
|
||||
{
|
||||
return array(
|
||||
array('firebird'),
|
||||
array('mssql'),
|
||||
array('mssql_odbc'),
|
||||
array('mssqlnative'),
|
||||
array('mysql'),
|
||||
array('mysqli'),
|
||||
array('oracle'),
|
||||
array('postgres'),
|
||||
array('sqlite'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider convert_30_dbms_to_31_data
|
||||
*/
|
||||
public function test_convert_30_dbms_to_31($input)
|
||||
{
|
||||
$expected = "phpbb_db_driver_$input";
|
||||
|
||||
$output = phpbb_convert_30_dbms_to_31($input);
|
||||
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
}
|
44
tests/functions/quoteattr_test.php
Normal file
44
tests/functions/quoteattr_test.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
class phpbb_quoteattr_test extends phpbb_test_case
|
||||
{
|
||||
public function quoteattr_test_data()
|
||||
{
|
||||
return array(
|
||||
array('foo', null, '"foo"'),
|
||||
array('', null, '""'),
|
||||
array(' ', null, '" "'),
|
||||
array('<a>', null, '"<a>"'),
|
||||
array('&', null, '"&amp;"'),
|
||||
array('"hello"', null, "'\"hello\"'"),
|
||||
array("'hello'", null, "\"'hello'\""),
|
||||
array("\"'", null, "\""'\""),
|
||||
array("a\nb", null, '"a b"'),
|
||||
array("a\r\nb", null, '"a b"'),
|
||||
array("a\tb", null, '"a	b"'),
|
||||
array('a b', null, '"a b"'),
|
||||
array('"a<b"', null, "'\"a<b\"'"),
|
||||
array('foo', array('f' => 'z'), '"zoo"'),
|
||||
array('<a>', array('a' => '&'), '"<&>"'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider quoteattr_test_data
|
||||
*/
|
||||
public function test_quoteattr($input, $entities, $expected)
|
||||
{
|
||||
$output = phpbb_quoteattr($input, $entities);
|
||||
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_bookmarks">
|
||||
<column>user_id</column>
|
||||
<column>topic_id</column>
|
||||
|
||||
<!-- one entry for this topic -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
|
||||
<!-- non-conflicting entries -->
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>3</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting entries -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>4</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>5</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting and non-conflicting entries -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>6</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>7</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>6</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_topics_watch">
|
||||
<column>user_id</column>
|
||||
<column>topic_id</column>
|
||||
<column>notify_status</column>
|
||||
|
||||
<!-- one entry for this topic -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
|
||||
<!-- non-conflicting entries -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting entries, same notify status -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>4</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>5</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting entries, notify status 0 into 1 -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>6</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>7</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting entries, notify status 1 into 0 -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>8</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>9</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
|
||||
<!-- conflicting and non-conflicting entries -->
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>10</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>11</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>10</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php';
|
||||
|
||||
class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/topics_watch_duplicates.xml');
|
||||
}
|
||||
|
||||
public static function fixture_data()
|
||||
{
|
||||
return array(
|
||||
// description
|
||||
// from array
|
||||
// to value
|
||||
// expected count with to value post update
|
||||
// expected notify_status values
|
||||
array(
|
||||
'trivial',
|
||||
array(1),
|
||||
1000,
|
||||
1,
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'no conflict',
|
||||
array(2),
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'conflict, same notify status',
|
||||
array(4),
|
||||
5,
|
||||
1,
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'conflict, notify status 0 into 1',
|
||||
array(6),
|
||||
7,
|
||||
1,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
'conflict, notify status 1 into 0',
|
||||
array(8),
|
||||
9,
|
||||
1,
|
||||
0,
|
||||
),
|
||||
array(
|
||||
'conflict and no conflict',
|
||||
array(10),
|
||||
11,
|
||||
2,
|
||||
0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider fixture_data
|
||||
*/
|
||||
public function test_update($description, $from, $to, $expected_result_count, $expected_notify_status)
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to);
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS remaining_rows
|
||||
FROM ' . TOPICS_WATCH_TABLE . '
|
||||
WHERE topic_id = ' . (int) $to;
|
||||
$result = $db->sql_query($sql);
|
||||
$result_count = $db->sql_fetchfield('remaining_rows');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$this->assertEquals($expected_result_count, $result_count);
|
||||
|
||||
// user id of 1 is the user being updated
|
||||
$sql = 'SELECT notify_status
|
||||
FROM ' . TOPICS_WATCH_TABLE . '
|
||||
WHERE topic_id = ' . (int) $to . '
|
||||
AND user_id = 1';
|
||||
$result = $db->sql_query($sql);
|
||||
$notify_status = $db->sql_fetchfield('notify_status');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$this->assertEquals($expected_notify_status, $notify_status);
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php';
|
||||
|
||||
class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/bookmarks_duplicates.xml');
|
||||
}
|
||||
|
||||
public static function fixture_data()
|
||||
{
|
||||
return array(
|
||||
// description
|
||||
// from array
|
||||
// to value
|
||||
// expected count with to value post update
|
||||
array(
|
||||
'trivial',
|
||||
array(1),
|
||||
10,
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'no conflict',
|
||||
array(2),
|
||||
3,
|
||||
2,
|
||||
),
|
||||
array(
|
||||
'conflict',
|
||||
array(4),
|
||||
5,
|
||||
1,
|
||||
),
|
||||
array(
|
||||
'conflict and no conflict',
|
||||
array(6),
|
||||
7,
|
||||
2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider fixture_data
|
||||
*/
|
||||
public function test_update($description, $from, $to, $expected_result_count)
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $from, $to);
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS remaining_rows
|
||||
FROM ' . BOOKMARKS_TABLE . '
|
||||
WHERE topic_id = ' . (int) $to;
|
||||
$result = $db->sql_query($sql);
|
||||
$result_count = $db->sql_fetchfield('remaining_rows');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$this->assertEquals($expected_result_count, $result_count);
|
||||
}
|
||||
}
|
32
tests/mock/filesystem_extension_manager.php
Normal file
32
tests/mock/filesystem_extension_manager.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_mock_filesystem_extension_manager extends phpbb_mock_extension_manager
|
||||
{
|
||||
public function __construct($phpbb_root_path)
|
||||
{
|
||||
$extensions = array();
|
||||
$iterator = new DirectoryIterator($phpbb_root_path . 'ext/');
|
||||
foreach ($iterator as $fileinfo)
|
||||
{
|
||||
if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 1) != '.')
|
||||
{
|
||||
$name = $fileinfo->getFilename();
|
||||
$extension = array(
|
||||
'ext_name' => $name,
|
||||
'ext_active' => true,
|
||||
'ext_path' => 'ext/' . $name . '/',
|
||||
);
|
||||
$extensions[$name] = $extension;
|
||||
}
|
||||
}
|
||||
ksort($extensions);
|
||||
parent::__construct($phpbb_root_path, $extensions);
|
||||
}
|
||||
}
|
47
tests/mock/null_cache.php
Normal file
47
tests/mock/null_cache.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_mock_null_cache
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function get($var_name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function put($var_name, $var, $ttl = 0)
|
||||
{
|
||||
}
|
||||
|
||||
public function destroy($var_name, $table = '')
|
||||
{
|
||||
}
|
||||
|
||||
public function obtain_bots()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function obtain_word_list()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function set_bots($bots)
|
||||
{
|
||||
}
|
||||
|
||||
public function sql_exists($query_id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case
|
||||
parent::setUp();
|
||||
|
||||
// dbal uses cache
|
||||
$cache = new phpbb_cache_service(new phpbb_cache_driver_null);
|
||||
$cache = new phpbb_mock_cache();
|
||||
|
||||
// set config values
|
||||
$config['fulltext_mysql_min_word_len'] = 4;
|
||||
|
@@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case
|
||||
parent::setUp();
|
||||
|
||||
// dbal uses cache
|
||||
$cache = new phpbb_cache_service(new phpbb_cache_driver_null);
|
||||
$cache = new phpbb_mock_cache();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$error = null;
|
||||
|
@@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case
|
||||
parent::setUp();
|
||||
|
||||
// dbal uses cache
|
||||
$cache = new phpbb_cache_service(new phpbb_cache_driver_null);
|
||||
$cache = new phpbb_mock_cache();
|
||||
|
||||
// set config values
|
||||
$config['fulltext_postgres_min_word_len'] = 4;
|
||||
|
@@ -59,10 +59,10 @@ class phpbb_session_testable_factory
|
||||
/**
|
||||
* Retrieve the configured session class instance
|
||||
*
|
||||
* @param dbal $dbal The database connection to use for session data
|
||||
* @param phpbb_db_driver $dbal The database connection to use for session data
|
||||
* @return phpbb_mock_session_testable A session instance
|
||||
*/
|
||||
public function get_session(dbal $dbal)
|
||||
public function get_session(phpbb_db_driver $dbal)
|
||||
{
|
||||
// set up all the global variables used by session
|
||||
global $SID, $_SID, $db, $config, $cache, $request;
|
||||
|
@@ -0,0 +1 @@
|
||||
Kappa test event in all
|
@@ -0,0 +1 @@
|
||||
Kappa test event in silver
|
@@ -0,0 +1 @@
|
||||
Kappa test event in silver_inherit
|
@@ -0,0 +1 @@
|
||||
Omega test event in all
|
@@ -0,0 +1 @@
|
||||
Omega test event in silver
|
@@ -0,0 +1 @@
|
||||
two in silver in omega
|
@@ -0,0 +1 @@
|
||||
Zeta test event in all
|
@@ -0,0 +1 @@
|
||||
<!-- EVENT test -->
|
@@ -0,0 +1 @@
|
||||
<!-- EVENT two -->
|
@@ -0,0 +1 @@
|
||||
<!-- EVENT test -->
|
@@ -0,0 +1 @@
|
||||
Universal in trivial extension.
|
@@ -0,0 +1 @@
|
||||
Simple in trivial extension.
|
@@ -0,0 +1 @@
|
||||
<!-- EVENT simple -->
|
@@ -0,0 +1 @@
|
||||
<!-- EVENT universal -->
|
@@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
|
||||
|
||||
$this->setup_engine(array('tpl_allow_php' => true));
|
||||
|
||||
$this->style->set_custom_style('tests', $cache_dir, '');
|
||||
$this->style->set_custom_style('tests', $cache_dir, array(), '');
|
||||
$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);
|
||||
|
@@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->template_compile = new phpbb_template_compile(false, null, '');
|
||||
$this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, '');
|
||||
$this->template_path = dirname(__FILE__) . '/templates';
|
||||
}
|
||||
|
||||
|
118
tests/template/template_events_test.php
Normal file
118
tests/template/template_events_test.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/template_test_case.php';
|
||||
|
||||
class phpbb_template_template_events_test extends phpbb_template_template_test_case
|
||||
{
|
||||
public function template_data()
|
||||
{
|
||||
return array(
|
||||
/*
|
||||
array(
|
||||
'', // file
|
||||
'', // dataset
|
||||
array(), // style names
|
||||
array(), // vars
|
||||
array(), // block vars
|
||||
array(), // destroy
|
||||
'', // expected result
|
||||
),
|
||||
*/
|
||||
array(
|
||||
'Simple template event',
|
||||
'ext_trivial',
|
||||
array(),
|
||||
'event_simple.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"Simple in trivial extension.",
|
||||
),
|
||||
array(
|
||||
'Universal template event ("all" style)',
|
||||
'ext_trivial',
|
||||
array(),
|
||||
'event_universal.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"Universal in trivial extension.",
|
||||
),
|
||||
array(
|
||||
'Template event with inheritance - parent',
|
||||
'event_inheritance',
|
||||
array('silver'),
|
||||
'event_test.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'Kappa test event in all
|
||||
Omega test event in all
|
||||
Zeta test event in all
|
||||
Kappa test event in silver
|
||||
Omega test event in silver',
|
||||
),
|
||||
array(
|
||||
'Template event with inheritance - child',
|
||||
'event_inheritance',
|
||||
array('silver_inherit', 'silver'),
|
||||
'event_test.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'Kappa test event in all
|
||||
Omega test event in all
|
||||
Zeta test event in all
|
||||
Kappa test event in silver_inherit',
|
||||
),
|
||||
array(
|
||||
'Definition in parent style',
|
||||
'event_inheritance',
|
||||
array('silver_inherit', 'silver'),
|
||||
'event_two.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'two in silver in omega',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
{
|
||||
// Reset the engine state
|
||||
$this->setup_engine_for_events($dataset, $style_names);
|
||||
|
||||
// Run test
|
||||
$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
|
||||
$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
|
||||
}
|
||||
|
||||
protected function setup_engine_for_events($dataset, $style_names, array $new_config = array())
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $user;
|
||||
|
||||
$defaults = $this->config_defaults();
|
||||
$config = new phpbb_config(array_merge($defaults, $new_config));
|
||||
|
||||
$this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template";
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
|
||||
dirname(__FILE__) . "/datasets/$dataset/"
|
||||
);
|
||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('silver', array($this->template_path), $style_names, '');
|
||||
}
|
||||
}
|
@@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('tests', $this->template_path, '');
|
||||
$this->style->set_custom_style('tests', $this->template_path, array(), '');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
@@ -24,6 +24,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
|
||||
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');
|
||||
}
|
||||
}
|
||||
|
4
tests/template/templates/events.html
Normal file
4
tests/template/templates/events.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<!-- EVENT child_only -->
|
||||
<!-- EVENT parent_only -->
|
||||
<!-- EVENT parent_and_child -->
|
||||
<!-- EVENT random_event -->
|
@@ -49,7 +49,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
$db_config = $this->get_database_config();
|
||||
|
||||
// Firebird requires table and column names to be uppercase
|
||||
if ($db_config['dbms'] == 'firebird')
|
||||
if ($db_config['dbms'] == 'phpbb_db_driver_firebird')
|
||||
{
|
||||
$xml_data = file_get_contents($path);
|
||||
$xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
|
||||
@@ -118,9 +118,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
|
||||
$config = $this->get_database_config();
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
|
||||
$dbal = 'dbal_' . $config['dbms'];
|
||||
$db = new $dbal();
|
||||
$db = new $config['dbms']();
|
||||
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
|
||||
|
||||
return $db;
|
||||
|
@@ -108,7 +108,7 @@ class phpbb_database_test_connection_manager
|
||||
|
||||
// These require different connection strings on the phpBB side than they do in PDO
|
||||
// so you must provide a DSN string for ODBC separately
|
||||
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird'))
|
||||
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird'))
|
||||
{
|
||||
$dsn = 'odbc:' . $this->config['custom_dsn'];
|
||||
}
|
||||
@@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager
|
||||
{
|
||||
switch ($this->config['dbms'])
|
||||
{
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'phpbb_db_driver_mssql':
|
||||
case 'phpbb_db_driver_mssql_odbc':
|
||||
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
|
||||
break;
|
||||
|
||||
case 'firebird':
|
||||
case 'phpbb_db_driver_firebird':
|
||||
if (!empty($this->config['custom_dsn']))
|
||||
{
|
||||
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
|
||||
@@ -165,8 +165,8 @@ class phpbb_database_test_connection_manager
|
||||
{
|
||||
switch ($this->config['dbms'])
|
||||
{
|
||||
case 'sqlite':
|
||||
case 'firebird':
|
||||
case 'phpbb_db_driver_sqlite':
|
||||
case 'phpbb_db_driver_firebird':
|
||||
$this->connect();
|
||||
// Drop all of the tables
|
||||
foreach ($this->get_tables() as $table)
|
||||
@@ -176,7 +176,7 @@ class phpbb_database_test_connection_manager
|
||||
$this->purge_extras();
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
case 'phpbb_db_driver_oracle':
|
||||
$this->connect();
|
||||
// Drop all of the tables
|
||||
foreach ($this->get_tables() as $table)
|
||||
@@ -226,39 +226,39 @@ class phpbb_database_test_connection_manager
|
||||
|
||||
switch ($this->config['dbms'])
|
||||
{
|
||||
case 'mysql':
|
||||
case 'mysql4':
|
||||
case 'mysqli':
|
||||
case 'phpbb_db_driver_mysql':
|
||||
case 'phpbb_db_driver_mysql4':
|
||||
case 'phpbb_db_driver_mysqli':
|
||||
$sql = 'SHOW TABLES';
|
||||
break;
|
||||
|
||||
case 'sqlite':
|
||||
case 'phpbb_db_driver_sqlite':
|
||||
$sql = 'SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE type = "table"';
|
||||
break;
|
||||
|
||||
case 'mssql':
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
case 'phpbb_db_driver_mssql':
|
||||
case 'phpbb_db_driver_mssql_odbc':
|
||||
case 'phpbb_db_driver_mssqlnative':
|
||||
$sql = "SELECT name
|
||||
FROM sysobjects
|
||||
WHERE type='U'";
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
case 'phpbb_db_driver_postgres':
|
||||
$sql = 'SELECT relname
|
||||
FROM pg_stat_user_tables';
|
||||
break;
|
||||
|
||||
case 'firebird':
|
||||
case 'phpbb_db_driver_firebird':
|
||||
$sql = 'SELECT rdb$relation_name
|
||||
FROM rdb$relations
|
||||
WHERE rdb$view_source is null
|
||||
AND rdb$system_flag = 0';
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
case 'phpbb_db_driver_oracle':
|
||||
$sql = 'SELECT table_name
|
||||
FROM USER_TABLES';
|
||||
break;
|
||||
@@ -293,8 +293,8 @@ class phpbb_database_test_connection_manager
|
||||
protected function load_schema_from_file($directory)
|
||||
{
|
||||
$schema = $this->dbms['SCHEMA'];
|
||||
|
||||
if ($this->config['dbms'] == 'mysql')
|
||||
|
||||
if ($this->config['dbms'] == 'phpbb_db_driver_mysql')
|
||||
{
|
||||
$sth = $this->pdo->query('SELECT VERSION() AS version');
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
@@ -313,7 +313,7 @@ class phpbb_database_test_connection_manager
|
||||
|
||||
$queries = file_get_contents($filename);
|
||||
$sql = phpbb_remove_comments($queries);
|
||||
|
||||
|
||||
$sql = split_sql_file($sql, $this->dbms['DELIM']);
|
||||
|
||||
foreach ($sql as $query)
|
||||
@@ -328,47 +328,47 @@ class phpbb_database_test_connection_manager
|
||||
protected function get_dbms_data($dbms)
|
||||
{
|
||||
$available_dbms = array(
|
||||
'firebird' => array(
|
||||
'phpbb_db_driver_firebird' => array(
|
||||
'SCHEMA' => 'firebird',
|
||||
'DELIM' => ';;',
|
||||
'PDO' => 'firebird',
|
||||
),
|
||||
'mysqli' => array(
|
||||
'phpbb_db_driver_mysqli' => array(
|
||||
'SCHEMA' => 'mysql_41',
|
||||
'DELIM' => ';',
|
||||
'PDO' => 'mysql',
|
||||
),
|
||||
'mysql' => array(
|
||||
'phpbb_db_driver_mysql' => array(
|
||||
'SCHEMA' => 'mysql',
|
||||
'DELIM' => ';',
|
||||
'PDO' => 'mysql',
|
||||
),
|
||||
'mssql' => array(
|
||||
'phpbb_db_driver_mssql' => array(
|
||||
'SCHEMA' => 'mssql',
|
||||
'DELIM' => 'GO',
|
||||
'PDO' => 'odbc',
|
||||
),
|
||||
'mssql_odbc'=> array(
|
||||
'phpbb_db_driver_mssql_odbc'=> array(
|
||||
'SCHEMA' => 'mssql',
|
||||
'DELIM' => 'GO',
|
||||
'PDO' => 'odbc',
|
||||
),
|
||||
'mssqlnative' => array(
|
||||
'phpbb_db_driver_mssqlnative' => array(
|
||||
'SCHEMA' => 'mssql',
|
||||
'DELIM' => 'GO',
|
||||
'PDO' => 'sqlsrv',
|
||||
),
|
||||
'oracle' => array(
|
||||
'phpbb_db_driver_oracle' => array(
|
||||
'SCHEMA' => 'oracle',
|
||||
'DELIM' => '/',
|
||||
'PDO' => 'oci',
|
||||
),
|
||||
'postgres' => array(
|
||||
'phpbb_db_driver_postgres' => array(
|
||||
'SCHEMA' => 'postgres',
|
||||
'DELIM' => ';',
|
||||
'PDO' => 'pgsql',
|
||||
),
|
||||
'sqlite' => array(
|
||||
'phpbb_db_driver_sqlite' => array(
|
||||
'SCHEMA' => 'sqlite',
|
||||
'DELIM' => ';',
|
||||
'PDO' => 'sqlite2',
|
||||
@@ -397,7 +397,7 @@ class phpbb_database_test_connection_manager
|
||||
|
||||
switch ($this->config['dbms'])
|
||||
{
|
||||
case 'firebird':
|
||||
case 'phpbb_db_driver_firebird':
|
||||
$sql = 'SELECT RDB$GENERATOR_NAME
|
||||
FROM RDB$GENERATORS
|
||||
WHERE RDB$SYSTEM_FLAG = 0';
|
||||
@@ -409,7 +409,7 @@ class phpbb_database_test_connection_manager
|
||||
}
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
case 'phpbb_db_driver_oracle':
|
||||
$sql = 'SELECT sequence_name
|
||||
FROM USER_SEQUENCES';
|
||||
$result = $this->pdo->query($sql);
|
||||
@@ -444,7 +444,7 @@ class phpbb_database_test_connection_manager
|
||||
|
||||
switch ($this->config['dbms'])
|
||||
{
|
||||
case 'oracle':
|
||||
case 'phpbb_db_driver_oracle':
|
||||
// Get all of the information about the sequences
|
||||
$sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value
|
||||
FROM USER_TRIGGERS t
|
||||
@@ -486,7 +486,7 @@ class phpbb_database_test_connection_manager
|
||||
}
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
case 'phpbb_db_driver_postgres':
|
||||
// Get the sequences attached to the tables
|
||||
$sql = 'SELECT column_name, table_name FROM information_schema.columns
|
||||
WHERE table_name IN (' . implode(', ', $table_names) . ")
|
||||
|
@@ -34,13 +34,36 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
static protected $config = array();
|
||||
static protected $already_installed = false;
|
||||
|
||||
public function setUp()
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::$config = phpbb_test_case_helpers::get_test_config();
|
||||
|
||||
// Important: this is used both for installation and by
|
||||
// test cases for querying the tables.
|
||||
// Therefore table prefix must be set before a board is
|
||||
// installed, and also before each test case is run.
|
||||
self::$config['table_prefix'] = 'phpbb_';
|
||||
|
||||
if (!isset(self::$config['phpbb_functional_url']))
|
||||
{
|
||||
$this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
|
||||
self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
|
||||
}
|
||||
|
||||
if (!self::$already_installed)
|
||||
{
|
||||
self::install_board();
|
||||
self::$already_installed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->bootstrap();
|
||||
|
||||
$this->cookieJar = new CookieJar;
|
||||
$this->client = new Goutte\Client(array(), null, $this->cookieJar);
|
||||
// Reset the curl handle because it is 0 at this point and not a valid
|
||||
@@ -73,27 +96,16 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$this->backupStaticAttributesBlacklist += array(
|
||||
'phpbb_functional_test_case' => array('config', 'already_installed'),
|
||||
);
|
||||
|
||||
if (!static::$already_installed)
|
||||
{
|
||||
$this->install_board();
|
||||
$this->bootstrap();
|
||||
static::$already_installed = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_db()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
// so we don't reopen an open connection
|
||||
if (!($this->db instanceof dbal))
|
||||
if (!($this->db instanceof phpbb_db_driver))
|
||||
{
|
||||
if (!class_exists('dbal_' . self::$config['dbms']))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
|
||||
}
|
||||
$sql_db = 'dbal_' . self::$config['dbms'];
|
||||
$this->db = new $sql_db();
|
||||
$dbms = self::$config['dbms'];
|
||||
$this->db = new $dbms();
|
||||
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
|
||||
}
|
||||
return $this->db;
|
||||
@@ -137,19 +149,11 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
return $this->extension_manager;
|
||||
}
|
||||
|
||||
protected function install_board()
|
||||
static protected function install_board()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
self::$config = phpbb_test_case_helpers::get_test_config();
|
||||
|
||||
if (!isset(self::$config['phpbb_functional_url']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
self::$config['table_prefix'] = 'phpbb_';
|
||||
$this->recreate_database(self::$config);
|
||||
self::recreate_database(self::$config);
|
||||
|
||||
if (file_exists($phpbb_root_path . "config.$phpEx"))
|
||||
{
|
||||
@@ -194,19 +198,30 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
));
|
||||
// end data
|
||||
|
||||
$content = $this->do_request('install');
|
||||
$this->assertContains('Welcome to Installation', $content);
|
||||
$content = self::do_request('install');
|
||||
self::assertNotSame(false, $content);
|
||||
self::assertContains('Welcome to Installation', $content);
|
||||
|
||||
$this->do_request('create_table', $data);
|
||||
// Installer uses 3.0-style dbms name
|
||||
$data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']);
|
||||
$content = self::do_request('create_table', $data);
|
||||
self::assertNotSame(false, $content);
|
||||
self::assertContains('The database tables used by phpBB', $content);
|
||||
// 3.0 or 3.1
|
||||
self::assertContains('have been created and populated with some initial data.', $content);
|
||||
|
||||
$this->do_request('config_file', $data);
|
||||
$content = self::do_request('config_file', $data);
|
||||
self::assertNotSame(false, $content);
|
||||
self::assertContains('Configuration file', $content);
|
||||
file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true));
|
||||
|
||||
$this->do_request('final', $data);
|
||||
$content = self::do_request('final', $data);
|
||||
self::assertNotSame(false, $content);
|
||||
self::assertContains('You have successfully installed', $content);
|
||||
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
|
||||
}
|
||||
|
||||
private function do_request($sub, $post_data = null)
|
||||
static private function do_request($sub, $post_data = null)
|
||||
{
|
||||
$context = null;
|
||||
|
||||
@@ -225,13 +240,62 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context);
|
||||
}
|
||||
|
||||
private function recreate_database($config)
|
||||
static private function recreate_database($config)
|
||||
{
|
||||
$db_conn_mgr = new phpbb_database_test_connection_manager($config);
|
||||
$db_conn_mgr->recreate_db();
|
||||
}
|
||||
|
||||
protected function login()
|
||||
/**
|
||||
* Creates a new user with limited permissions
|
||||
*
|
||||
* @param string $username Also doubles up as the user's password
|
||||
* @return int ID of created user
|
||||
*/
|
||||
protected function create_user($username)
|
||||
{
|
||||
// Required by unique_id
|
||||
global $config;
|
||||
|
||||
$config = new phpbb_config(array());
|
||||
$config['rand_seed'] = '';
|
||||
$config['rand_seed_last_update'] = time() + 600;
|
||||
|
||||
// Required by user_add
|
||||
global $db, $cache, $phpbb_dispatcher;
|
||||
$db = $this->get_db();
|
||||
if (!function_exists('phpbb_mock_null_cache'))
|
||||
{
|
||||
require_once(__DIR__ . '/../mock/null_cache.php');
|
||||
}
|
||||
$cache = new phpbb_mock_null_cache;
|
||||
|
||||
if (!function_exists('utf_clean_string'))
|
||||
{
|
||||
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
|
||||
}
|
||||
if (!function_exists('user_add'))
|
||||
{
|
||||
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
|
||||
}
|
||||
set_config(null, null, null, $config);
|
||||
set_config_count(null, null, null, $config);
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
|
||||
$user_row = array(
|
||||
'username' => $username,
|
||||
'group_id' => 2,
|
||||
'user_email' => 'nobody@example.com',
|
||||
'user_type' => 0,
|
||||
'user_lang' => 'en',
|
||||
'user_timezone' => 0,
|
||||
'user_dateformat' => '',
|
||||
'user_password' => phpbb_hash($username),
|
||||
);
|
||||
return user_add($user_row);
|
||||
}
|
||||
|
||||
protected function login($username = 'admin')
|
||||
{
|
||||
$this->add_lang('ucp');
|
||||
|
||||
@@ -239,7 +303,9 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
|
||||
|
||||
$form = $crawler->selectButton($this->lang('LOGIN'))->form();
|
||||
$login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin'));
|
||||
$crawler = $this->client->submit($form, array('username' => $username, 'password' => $username));
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
|
||||
|
||||
$cookies = $this->cookieJar->all();
|
||||
|
||||
|
@@ -54,7 +54,7 @@ class phpbb_test_case_helpers
|
||||
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => 'sqlite',
|
||||
'dbms' => 'phpbb_db_driver_sqlite',
|
||||
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
||||
'dbport' => '',
|
||||
'dbname' => '',
|
||||
@@ -78,7 +78,7 @@ class phpbb_test_case_helpers
|
||||
include($test_config);
|
||||
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => $dbms,
|
||||
'dbms' => phpbb_convert_30_dbms_to_31($dbms),
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
@@ -104,8 +104,13 @@ class phpbb_test_case_helpers
|
||||
|
||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||
{
|
||||
if (!function_exists('phpbb_convert_30_dbms_to_31'))
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
}
|
||||
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
|
||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||
|
Reference in New Issue
Block a user