mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 06:20:46 +02:00
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into feature/softdelete-1-permission
* 'develop' of https://github.com/phpbb/phpbb3: (480 commits) [ticket/6723] Show info that message has been deleted before delivery [ticket/11385] Fix issue with migration module tool not getting extension module info [ticket/11386] Fix failing tests from constructor changes [ticket/11386] Fix circular reference error & serialize error [ticket/11386] Remove tests that check if finder cache is working [ticket/11386] Forgot to get the migration classes [ticket/11386] Update tests with new constructors for ext.manager/migrator [ticket/11386] Use finder to find migration files [ticket/11363] Fix to make get_module_infos get from all extensions [ticket/11381] Make finder able to search in all available extensions [ticket/11103] Revert whitespace changes [ticket/11103] Few more minor language things [ticket/11103] Don't call generate_board_url many times [ticket/11103] Case time in queries as an int [ticket/11103] Fix effectively installed check [ticket/11103] Remove padding from notifications for now. [ticket/11363] Fix a couple bugs and throw errors if the file not found [ticket/11372] Migrator should only check if effectively installed if not [ticket/11363] Load module info files for extensions too [ticket/11103] Notifications Migration file ... Conflicts: phpBB/includes/functions_posting.php phpBB/includes/mcp/mcp_queue.php phpBB/includes/search/fulltext_mysql.php phpBB/includes/search/fulltext_native.php phpBB/includes/search/fulltext_postgres.php phpBB/includes/search/fulltext_sphinx.php phpBB/install/database_update.php phpBB/styles/prosilver/template/ajax.js
This commit is contained in:
@@ -17,7 +17,27 @@ PHP extensions
|
||||
Unit tests use several PHP extensions that board code does not use. Currently
|
||||
the following PHP extensions must be installed and enabled to run unit tests:
|
||||
|
||||
- ctype
|
||||
- ctype (also a PHPUnit dependency)
|
||||
- dom (PHPUnit dependency)
|
||||
- json (also a phpBB dependency)
|
||||
|
||||
Some of the functionality in phpBB and/or the test suite uses additional
|
||||
PHP extensions. If these extensions are not loaded, respective tests
|
||||
will be skipped:
|
||||
|
||||
- apc (APC cache driver)
|
||||
- bz2 (compress tests)
|
||||
- interbase, pdo_firebird (Firebird database driver)
|
||||
- mysql, pdo_mysql (MySQL database driver)
|
||||
- mysqli, pdo_mysql (MySQLi database driver)
|
||||
- pcntl (flock class)
|
||||
- pdo (any database tests)
|
||||
- pgsql, pdo_pgsql (PostgreSQL database driver)
|
||||
- redis (https://github.com/nicolasff/phpredis, Redis cache driver)
|
||||
- simplexml (any database tests)
|
||||
- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support
|
||||
in pdo_sqlite)
|
||||
- zlib (compress tests)
|
||||
|
||||
Database Tests
|
||||
--------------
|
||||
@@ -44,7 +64,7 @@ to use in the environment as follows:
|
||||
$ PHPBB_TEST_CONFIG=tests/test_config.php phpunit
|
||||
|
||||
Alternatively you can specify parameters in the environment, so e.g. the
|
||||
following will run phpunit with the same parameters as in the shown
|
||||
following will run PHPUnit with the same parameters as in the shown
|
||||
test_config.php file:
|
||||
|
||||
$ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \
|
||||
|
5
tests/cache/common_test_case.php
vendored
5
tests/cache/common_test_case.php
vendored
@@ -64,9 +64,10 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
global $db, $cache, $phpbb_root_path, $phpEx;
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
$cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx);
|
||||
|
||||
$sql = "SELECT * FROM phpbb_config
|
||||
WHERE config_name = 'foo'";
|
||||
|
5
tests/cache/null_driver_test.php
vendored
5
tests/cache/null_driver_test.php
vendored
@@ -47,9 +47,10 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case
|
||||
|
||||
public function test_cache_sql()
|
||||
{
|
||||
global $db, $cache;
|
||||
global $db, $cache, $phpbb_root_path, $phpEx;
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->new_dbal();
|
||||
$cache = new phpbb_cache_service($this->driver);
|
||||
$cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx);
|
||||
|
||||
$sql = "SELECT * FROM phpbb_config
|
||||
WHERE config_name = 'foo'";
|
||||
|
29
tests/dbal/fixtures/migrator.xml
Normal file
29
tests/dbal/fixtures/migrator.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_migrations">
|
||||
<column>migration_name</column>
|
||||
<column>migration_depends_on</column>
|
||||
<column>migration_schema_done</column>
|
||||
<column>migration_data_done</column>
|
||||
<column>migration_data_state</column>
|
||||
<column>migration_start_time</column>
|
||||
<column>migration_end_time</column>
|
||||
<row>
|
||||
<value>installed_migration</value>
|
||||
<value></value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>1234</value>
|
||||
<value>5678</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_config">
|
||||
<column>config_name</column>
|
||||
<column>config_value</column>
|
||||
<row>
|
||||
<value>foo</value>
|
||||
<value>bar</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
42
tests/dbal/fixtures/migrator_module.xml
Normal file
42
tests/dbal/fixtures/migrator_module.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_modules">
|
||||
<column>module_id</column>
|
||||
<column>module_enabled</column>
|
||||
<column>module_display</column>
|
||||
<column>module_basename</column>
|
||||
<column>module_class</column>
|
||||
<column>parent_id</column>
|
||||
<column>left_id</column>
|
||||
<column>right_id</column>
|
||||
<column>module_langname</column>
|
||||
<column>module_mode</column>
|
||||
<column>module_auth</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>acp</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>4</value>
|
||||
<value>ACP_CAT</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>acp_test</value>
|
||||
<value>acp</value>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
<value>ACP_MODULE</value>
|
||||
<value>test</value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
31
tests/dbal/fixtures/migrator_permission.xml
Normal file
31
tests/dbal/fixtures/migrator_permission.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_acl_options">
|
||||
<column>auth_option_id</column>
|
||||
<column>auth_option</column>
|
||||
<column>is_global</column>
|
||||
<column>is_local</column>
|
||||
<column>founder_only</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>global</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>local</value>
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>both</value>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
27
tests/dbal/migration/dummy.php
Normal file
27
tests/dbal/migration/dummy.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_dummy extends phpbb_db_migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('installed_migration');
|
||||
}
|
||||
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
'phpbb_config' => array(
|
||||
'extra_column' => array('UINT', 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
41
tests/dbal/migration/fail.php
Normal file
41
tests/dbal/migration/fail.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package migration
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_fail extends phpbb_db_migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'config' => array(
|
||||
'test_column' => array('BOOL', 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_columns' => array(
|
||||
$this->table_prefix . 'config' => array(
|
||||
'test_column',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.add', array('foobar3', true)),
|
||||
array('config.update', array('does_not_exist', true)),
|
||||
);
|
||||
}
|
||||
}
|
44
tests/dbal/migration/if.php
Normal file
44
tests/dbal/migration/if.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_if extends phpbb_db_migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
return array(
|
||||
array('if', array(
|
||||
true,
|
||||
array('custom', array(array(&$this, 'test_true'))),
|
||||
)),
|
||||
array('if', array(
|
||||
false,
|
||||
array('custom', array(array(&$this, 'test_false'))),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
function test_true()
|
||||
{
|
||||
global $migrator_test_if_true_failed;
|
||||
|
||||
$migrator_test_if_true_failed = false;
|
||||
}
|
||||
|
||||
function test_false()
|
||||
{
|
||||
global $migrator_test_if_false_failed;
|
||||
|
||||
$migrator_test_if_false_failed = true;
|
||||
}
|
||||
}
|
30
tests/dbal/migration/installed.php
Normal file
30
tests/dbal/migration/installed.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_installed extends phpbb_db_migration
|
||||
{
|
||||
function effectively_installed()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array(&$this, 'test'))),
|
||||
);
|
||||
}
|
||||
|
||||
function test()
|
||||
{
|
||||
global $migrator_test_installed_failed;
|
||||
|
||||
$migrator_test_installed_failed = true;
|
||||
}
|
||||
}
|
38
tests/dbal/migration/recall.php
Normal file
38
tests/dbal/migration/recall.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_recall extends phpbb_db_migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array(&$this, 'test_call'))),
|
||||
);
|
||||
}
|
||||
|
||||
// This function should be called 10 times
|
||||
function test_call($input)
|
||||
{
|
||||
global $migrator_test_call_input;
|
||||
|
||||
$migrator_test_call_input = (int) $input;
|
||||
|
||||
if ($migrator_test_call_input < 10)
|
||||
{
|
||||
return ($migrator_test_call_input + 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
40
tests/dbal/migration/revert.php
Normal file
40
tests/dbal/migration/revert.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_revert extends phpbb_db_migration
|
||||
{
|
||||
function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_columns' => array(
|
||||
'phpbb_config' => array(
|
||||
'bar_column' => array('UINT', 1),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_columns' => array(
|
||||
'phpbb_config' => array(
|
||||
'bar_column',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
return array(
|
||||
array('config.add', array('foobartest', 0)),
|
||||
);
|
||||
}
|
||||
}
|
16
tests/dbal/migration/revert_with_dependency.php
Normal file
16
tests/dbal/migration/revert_with_dependency.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('phpbb_dbal_migration_revert');
|
||||
}
|
||||
}
|
26
tests/dbal/migration/unfulfillable.php
Normal file
26
tests/dbal/migration/unfulfillable.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration
|
||||
{
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration');
|
||||
}
|
||||
|
||||
function update_schema()
|
||||
{
|
||||
trigger_error('Schema update of migration with unfulfillable dependency was run!');
|
||||
}
|
||||
|
||||
function update_data()
|
||||
{
|
||||
trigger_error('Data update of migration with unfulfillable dependency was run!');
|
||||
}
|
||||
}
|
277
tests/dbal/migrator_test.php
Normal file
277
tests/dbal/migrator_test.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/migration/dummy.php';
|
||||
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
|
||||
require_once dirname(__FILE__) . '/migration/if.php';
|
||||
require_once dirname(__FILE__) . '/migration/recall.php';
|
||||
require_once dirname(__FILE__) . '/migration/revert.php';
|
||||
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
|
||||
require_once dirname(__FILE__) . '/migration/fail.php';
|
||||
require_once dirname(__FILE__) . '/migration/installed.php';
|
||||
|
||||
class phpbb_dbal_migrator_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $db;
|
||||
protected $db_tools;
|
||||
protected $migrator;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = new phpbb_db_tools($this->db);
|
||||
|
||||
$this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config');
|
||||
|
||||
$tools = array(
|
||||
new phpbb_db_migration_tool_config($this->config),
|
||||
);
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$this->db,
|
||||
$this->config,
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/../../phpBB/',
|
||||
'.php',
|
||||
null
|
||||
);
|
||||
$this->migrator = new phpbb_db_migrator(
|
||||
$this->config,
|
||||
$this->db,
|
||||
$this->db_tools,
|
||||
'phpbb_migrations',
|
||||
dirname(__FILE__) . '/../../phpBB/',
|
||||
'php',
|
||||
'phpbb_',
|
||||
$tools
|
||||
);
|
||||
$this->migrator->set_extension_manager($this->extension_manager);
|
||||
}
|
||||
|
||||
public function test_update()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_dummy'));
|
||||
|
||||
// schema
|
||||
$this->migrator->update();
|
||||
$this->assertFalse($this->migrator->finished());
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('success' => '1')),
|
||||
"SELECT 1 as success
|
||||
FROM phpbb_migrations
|
||||
WHERE migration_name = 'phpbb_dbal_migration_dummy'
|
||||
AND migration_start_time >= " . (time() - 1) . "
|
||||
AND migration_start_time <= " . (time() + 1),
|
||||
'Start time set correctly'
|
||||
);
|
||||
|
||||
// data
|
||||
$this->migrator->update();
|
||||
$this->assertTrue($this->migrator->finished());
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('extra_column' => '1')),
|
||||
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
|
||||
'Dummy migration created extra_column with value 1 in all rows.'
|
||||
);
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('success' => '1')),
|
||||
"SELECT 1 as success
|
||||
FROM phpbb_migrations
|
||||
WHERE migration_name = 'phpbb_dbal_migration_dummy'
|
||||
AND migration_start_time <= migration_end_time
|
||||
AND migration_end_time >= " . (time() - 1) . "
|
||||
AND migration_end_time <= " . (time() + 1),
|
||||
'End time set correctly'
|
||||
);
|
||||
|
||||
// cleanup
|
||||
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
|
||||
}
|
||||
|
||||
public function test_unfulfillable()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'));
|
||||
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
}
|
||||
|
||||
$this->assertTrue($this->migrator->finished());
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('extra_column' => '1')),
|
||||
"SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'",
|
||||
'Dummy migration was run, even though an unfulfillable migration was found.'
|
||||
);
|
||||
|
||||
$this->db_tools->sql_column_remove('phpbb_config', 'extra_column');
|
||||
}
|
||||
|
||||
public function test_if()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_if'));
|
||||
|
||||
// Don't like this, but I'm not sure there is any other way to do this
|
||||
global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
|
||||
$migrator_test_if_true_failed = true;
|
||||
$migrator_test_if_false_failed = false;
|
||||
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
}
|
||||
|
||||
if ($migrator_test_if_true_failed)
|
||||
{
|
||||
$this->fail('True test failed');
|
||||
}
|
||||
|
||||
if ($migrator_test_if_false_failed)
|
||||
{
|
||||
$this->fail('False test failed');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_recall()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_recall'));
|
||||
|
||||
global $migrator_test_call_input;
|
||||
|
||||
// Run the schema first
|
||||
$this->migrator->update();
|
||||
|
||||
$i = 0;
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
|
||||
$this->assertSame($i, $migrator_test_call_input);
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$this->assertSame(10, $migrator_test_call_input);
|
||||
}
|
||||
|
||||
public function test_revert()
|
||||
{
|
||||
// Make sure there are no other migrations in the db, this could cause issues
|
||||
$this->db->sql_query("DELETE FROM phpbb_migrations");
|
||||
$this->migrator->load_migration_state();
|
||||
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency'));
|
||||
|
||||
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
|
||||
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
|
||||
|
||||
// Install the migration first
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
}
|
||||
|
||||
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false);
|
||||
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false);
|
||||
|
||||
$this->assertSqlResultEquals(
|
||||
array(array('bar_column' => '1')),
|
||||
"SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'",
|
||||
'Installing revert migration failed to create bar_column.'
|
||||
);
|
||||
|
||||
$this->assertTrue(isset($this->config['foobartest']));
|
||||
|
||||
while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false)
|
||||
{
|
||||
$this->migrator->revert('phpbb_dbal_migration_revert');
|
||||
}
|
||||
|
||||
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert'));
|
||||
$this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency'));
|
||||
|
||||
$this->assertFalse(isset($this->config['foobartest']));
|
||||
|
||||
$sql = 'SELECT * FROM phpbb_config';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (isset($row['bar_column']))
|
||||
{
|
||||
$this->fail('Revert did not remove test_column.');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_fail()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
|
||||
|
||||
$this->assertFalse(isset($this->config['foobar3']));
|
||||
|
||||
try
|
||||
{
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
}
|
||||
}
|
||||
catch (phpbb_db_migration_exception $e) {}
|
||||
|
||||
// Failure should have caused an automatic roll-back, so this should not exist.
|
||||
$this->assertFalse(isset($this->config['foobar3']));
|
||||
|
||||
$sql = 'SELECT * FROM phpbb_config';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (isset($row['test_column']))
|
||||
{
|
||||
$this->fail('Revert did not remove test_column.');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_installed()
|
||||
{
|
||||
$this->migrator->set_migrations(array('phpbb_dbal_migration_installed'));
|
||||
|
||||
global $migrator_test_installed_failed;
|
||||
$migrator_test_installed_failed = false;
|
||||
|
||||
while (!$this->migrator->finished())
|
||||
{
|
||||
$this->migrator->update();
|
||||
}
|
||||
|
||||
$this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false);
|
||||
|
||||
if ($migrator_test_installed_failed)
|
||||
{
|
||||
$this->fail('Installed test failed');
|
||||
}
|
||||
}
|
||||
}
|
124
tests/dbal/migrator_tool_config_test.php
Normal file
124
tests/dbal/migrator_tool_config_test.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
|
||||
{
|
||||
public function setup()
|
||||
{
|
||||
$this->config = new phpbb_config(array());
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_config($this->config);
|
||||
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('foo', 'bar');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar', $this->config['foo']);
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('foo', 'bar');
|
||||
$this->fail('Exception not thrown');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
public function test_update()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
try
|
||||
{
|
||||
$this->tool->update('foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar2', $this->config['foo']);
|
||||
}
|
||||
|
||||
public function test_update_if_equals()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->update_if_equals('', 'foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar', $this->config['foo']);
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->update_if_equals('bar', 'foo', 'bar2');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('bar2', $this->config['foo']);
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->remove('foo');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertFalse(isset($this->config['foo']));
|
||||
}
|
||||
|
||||
public function test_reverse()
|
||||
{
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->reverse('add', 'foo');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertFalse(isset($this->config['foo']));
|
||||
|
||||
$this->config->set('foo', 'bar');
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->reverse('update_if_equals', 'test', 'foo', 'bar');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals('test', $this->config['foo']);
|
||||
}
|
||||
}
|
150
tests/dbal/migrator_tool_module.php
Normal file
150
tests/dbal/migrator_tool_module.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
// Need global $db, $user for delete_module function in acp_modules
|
||||
global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user;
|
||||
|
||||
parent::setup();
|
||||
|
||||
// Force add_log function to not be used
|
||||
$skip_add_log = true;
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
|
||||
$user = $this->user = new phpbb_user();
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
|
||||
}
|
||||
|
||||
public function exists_data()
|
||||
{
|
||||
return array(
|
||||
// Test the category
|
||||
array(
|
||||
'',
|
||||
'ACP_CAT',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
0,
|
||||
'ACP_CAT',
|
||||
true,
|
||||
),
|
||||
|
||||
// Test the module
|
||||
array(
|
||||
'',
|
||||
'ACP_MODULE',
|
||||
false,
|
||||
),
|
||||
array(
|
||||
false,
|
||||
'ACP_MODULE',
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'ACP_CAT',
|
||||
'ACP_MODULE',
|
||||
true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider exists_data
|
||||
*/
|
||||
public function test_exists($parent, $module, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
|
||||
|
||||
// Should throw an exception when trying to add a module that already exists
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
|
||||
$this->fail('Exception not thrown');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 'ACP_NEW_CAT', array(
|
||||
'module_basename' => 'acp_new_module',
|
||||
'module_langname' => 'ACP_NEW_MODULE',
|
||||
'module_mode' => 'test',
|
||||
'module_auth' => '',
|
||||
));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE'));
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE'));
|
||||
}
|
||||
|
||||
public function test_reverse()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('acp', 0, 'ACP_NEW_CAT');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT'));
|
||||
}
|
||||
}
|
159
tests/dbal/migrator_tool_permission.php
Normal file
159
tests/dbal/migrator_tool_permission.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';
|
||||
|
||||
class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
|
||||
}
|
||||
|
||||
public function setup()
|
||||
{
|
||||
// Global $db and $cache are needed in acp/auth.php constructor
|
||||
global $phpbb_root_path, $phpEx, $db, $cache;
|
||||
|
||||
parent::setup();
|
||||
|
||||
$db = $this->db = $this->new_dbal();
|
||||
$cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx);
|
||||
$this->auth = new phpbb_auth();
|
||||
|
||||
$this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
|
||||
}
|
||||
|
||||
public function exists_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'global',
|
||||
true,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'local',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'both',
|
||||
true,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'both',
|
||||
false,
|
||||
true,
|
||||
),
|
||||
array(
|
||||
'does_not_exist',
|
||||
true,
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider exists_data
|
||||
*/
|
||||
public function test_exists($auth_option, $global, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->tool->exists($auth_option, $global));
|
||||
}
|
||||
|
||||
public function test_add()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('new', true));
|
||||
$this->assertEquals(false, $this->tool->exists('new', false));
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(true, $this->tool->exists('new', false));
|
||||
|
||||
// Should fail (duplicate)
|
||||
try
|
||||
{
|
||||
$this->tool->add('new', true);
|
||||
$this->fail('Did not throw exception on duplicate');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
public function test_remove()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->remove('global', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('global', true));
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->remove('both', false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertEquals(false, $this->tool->exists('both', false));
|
||||
|
||||
// Should fail (does not exist)
|
||||
try
|
||||
{
|
||||
$this->tool->remove('new', true);
|
||||
$this->fail('Did not throw exception on duplicate');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
public function test_reverse()
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->tool->reverse('remove', 'global_test', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertTrue($this->tool->exists('global_test', true));
|
||||
|
||||
try
|
||||
{
|
||||
$this->tool->reverse('add', 'global_test', true);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail($e);
|
||||
}
|
||||
$this->assertFalse($this->tool->exists('global_test', true));
|
||||
}
|
||||
}
|
@@ -142,6 +142,9 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* These do not work because of changes with PHPBB3-11386
|
||||
* They do not seem neccessary to me, so I am commenting them out for now
|
||||
public function test_get_classes_create_cache()
|
||||
{
|
||||
$cache = new phpbb_mock_cache;
|
||||
@@ -183,11 +186,15 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||
'is_dir' => false,
|
||||
);
|
||||
|
||||
$finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/', new phpbb_mock_cache(array(
|
||||
'_ext_finder' => array(
|
||||
md5(serialize($query)) => array('file_name' => 'extension'),
|
||||
),
|
||||
)));
|
||||
$finder = new phpbb_extension_finder(
|
||||
$this->extension_manager,
|
||||
dirname(__FILE__) . '/',
|
||||
new phpbb_mock_cache(array(
|
||||
'_ext_finder' => array(
|
||||
md5(serialize($query)) => array('file_name' => 'extension'),
|
||||
),
|
||||
))
|
||||
);
|
||||
|
||||
$classes = $finder
|
||||
->core_path($query['core_path'])
|
||||
@@ -200,4 +207,5 @@ class phpbb_extension_finder_test extends phpbb_test_case
|
||||
$classes
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -25,14 +25,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
$this->new_dbal(),
|
||||
new phpbb_config(array()),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.php',
|
||||
new phpbb_mock_cache
|
||||
);
|
||||
$this->extension_manager = $this->create_extension_manager();
|
||||
}
|
||||
|
||||
public function test_available()
|
||||
@@ -89,15 +82,43 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
|
||||
|
||||
public function test_enabled_no_cache()
|
||||
{
|
||||
$extension_manager = new phpbb_extension_manager(
|
||||
$this->new_dbal(),
|
||||
new phpbb_config(array()),
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.php'
|
||||
);
|
||||
$extension_manager = $this->create_extension_manager(false);
|
||||
|
||||
$this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled()));
|
||||
}
|
||||
|
||||
protected function create_extension_manager($with_cache = true)
|
||||
{
|
||||
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->new_dbal();
|
||||
$db_tools = new phpbb_db_tools($db);
|
||||
$phpbb_root_path = __DIR__ . './../../phpBB/';
|
||||
$php_ext = 'php';
|
||||
$table_prefix = 'phpbb_';
|
||||
|
||||
$manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
'phpbb_ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
($with_cache) ? new phpbb_mock_cache() : null
|
||||
);
|
||||
$migrator = new phpbb_db_migrator(
|
||||
$config,
|
||||
$db,
|
||||
$db_tools,
|
||||
'phpbb_migrations',
|
||||
$phpbb_root_path,
|
||||
$php_ext,
|
||||
$table_prefix,
|
||||
array()
|
||||
);
|
||||
$manager->set_migrator($migrator);
|
||||
$migrator->set_extension_manager($manager);
|
||||
|
||||
return $manager;
|
||||
}
|
||||
}
|
||||
|
@@ -34,9 +34,11 @@ class metadata_manager_test extends phpbb_database_test_case
|
||||
'version' => '3.1.0',
|
||||
));
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = new phpbb_db_tools($this->db);
|
||||
$this->phpbb_root_path = dirname(__FILE__) . '/';
|
||||
$this->phpEx = '.php';
|
||||
$this->user = new phpbb_user();
|
||||
$this->table_prefix = 'phpbb_';
|
||||
|
||||
$this->template = new phpbb_template(
|
||||
$this->phpbb_root_path,
|
||||
@@ -48,6 +50,7 @@ class metadata_manager_test extends phpbb_database_test_case
|
||||
);
|
||||
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$this->db,
|
||||
$this->config,
|
||||
'phpbb_ext',
|
||||
|
128
tests/functional/acp_permissions_test.php
Normal file
128
tests/functional/acp_permissions_test.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?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_acp_permissions_test extends phpbb_functional_test_case
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
$this->add_lang('acp/permissions');
|
||||
}
|
||||
|
||||
public function test_permissions_tab()
|
||||
{
|
||||
// Permissions tab
|
||||
// XXX hardcoded id
|
||||
$crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
// these language strings are html
|
||||
$this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function test_select_user()
|
||||
{
|
||||
// User permissions
|
||||
$crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
|
||||
|
||||
// Select admin
|
||||
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
|
||||
$data = array('username[0]' => 'admin');
|
||||
$form->setValues($data);
|
||||
$crawler = $this->client->submit($form);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
|
||||
}
|
||||
|
||||
public function permissions_data()
|
||||
{
|
||||
return array(
|
||||
// description
|
||||
// permission type
|
||||
// permission name
|
||||
// mode
|
||||
// object name
|
||||
// object id
|
||||
array(
|
||||
'user permission',
|
||||
'u_',
|
||||
'u_hideonline',
|
||||
'setting_user_global',
|
||||
'user_id',
|
||||
2,
|
||||
),
|
||||
array(
|
||||
'moderator permission',
|
||||
'm_',
|
||||
'm_ban',
|
||||
'setting_mod_global',
|
||||
'group_id',
|
||||
4,
|
||||
),
|
||||
/* Admin does not work yet, probably because founder can do everything
|
||||
array(
|
||||
'admin permission',
|
||||
'a_',
|
||||
'a_forum',
|
||||
'setting_admin_global',
|
||||
'group_id',
|
||||
5,
|
||||
),
|
||||
*/
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider permissions_data
|
||||
*/
|
||||
public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id)
|
||||
{
|
||||
// Get the form
|
||||
$crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
|
||||
|
||||
// XXX globals for phpbb_auth, refactor it later
|
||||
global $db, $cache;
|
||||
$db = $this->get_db();
|
||||
$cache = new phpbb_mock_null_cache;
|
||||
|
||||
$auth = new phpbb_auth;
|
||||
// XXX hardcoded id
|
||||
$user_data = $auth->obtain_user_data(2);
|
||||
$auth->acl($user_data);
|
||||
$this->assertEquals(1, $auth->acl_get($permission));
|
||||
|
||||
// Set u_hideonline to never
|
||||
$form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
|
||||
// initially it should be a yes
|
||||
$values = $form->getValues();
|
||||
$this->assertEquals(1, $values["setting[$object_id][0][$permission]"]);
|
||||
// set to never
|
||||
$data = array("setting[$object_id][0][$permission]" => '0');
|
||||
$form->setValues($data);
|
||||
$crawler = $this->client->submit($form);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text());
|
||||
|
||||
// check acl again
|
||||
$auth = new phpbb_auth;
|
||||
// XXX hardcoded id
|
||||
$user_data = $auth->obtain_user_data(2);
|
||||
$auth->acl($user_data);
|
||||
$this->assertEquals(0, $auth->acl_get($permission));
|
||||
}
|
||||
}
|
@@ -49,4 +49,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
|
||||
}
|
||||
|
||||
public function test_acp_login()
|
||||
{
|
||||
$this->login();
|
||||
$this->admin_login();
|
||||
|
||||
// check that we are logged in
|
||||
$crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid);
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
|
||||
}
|
||||
}
|
||||
|
@@ -44,8 +44,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
|
||||
|
||||
public function test_empty_file()
|
||||
{
|
||||
$this->markTestIncomplete('Test fails intermittently.');
|
||||
$crawler = $this->upload_file('empty.png', 'image/png');
|
||||
$this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text());
|
||||
$this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text());
|
||||
}
|
||||
|
||||
public function test_invalid_extension()
|
||||
@@ -63,6 +64,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case
|
||||
|
||||
public function test_valid_file()
|
||||
{
|
||||
$this->markTestIncomplete('Test fails intermittently.');
|
||||
$crawler = $this->upload_file('valid.jpg', 'image/jpeg');
|
||||
$this->assert_response_success();
|
||||
// ensure there was no error message rendered
|
||||
|
121
tests/functions_user/fixtures/group_user_attributes.xml
Normal file
121
tests/functions_user/fixtures/group_user_attributes.xml
Normal file
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_groups">
|
||||
<column>group_id</column>
|
||||
<column>group_avatar</column>
|
||||
<column>group_rank</column>
|
||||
<column>group_desc</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>default</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value></value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>default2</value>
|
||||
<value>3</value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>group_id</column>
|
||||
<column>user_avatar</column>
|
||||
<column>user_rank</column>
|
||||
<column>username_clean</column>
|
||||
<column>user_permissions</column>
|
||||
<column>user_sig</column>
|
||||
<column>user_occ</column>
|
||||
<column>user_interests</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value>0</value>
|
||||
<value>barfoo</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>default</value>
|
||||
<value>1</value>
|
||||
<value>foobar</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>custom</value>
|
||||
<value>2</value>
|
||||
<value>bertie</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_user_group">
|
||||
<column>user_id</column>
|
||||
<column>group_id</column>
|
||||
<column>user_pending</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>2</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>3</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
156
tests/functions_user/group_user_attributes_test.php
Normal file
156
tests/functions_user/group_user_attributes_test.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2008 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
|
||||
|
||||
class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml');
|
||||
}
|
||||
|
||||
public function group_user_attributes_data()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Setting new default group without settings for user with no settings - no change',
|
||||
1,
|
||||
2,
|
||||
array(
|
||||
'group_avatar' => '',
|
||||
'group_avatar_type' => 0,
|
||||
'group_avatar_height' => 0,
|
||||
'group_avatar_width' => 0,
|
||||
'group_rank' => 0,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => '',
|
||||
'user_rank' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Setting new default group without settings for user with default settings - user settings overwritten',
|
||||
2,
|
||||
2,
|
||||
array(
|
||||
'group_avatar' => '',
|
||||
'group_avatar_type' => 0,
|
||||
'group_avatar_height' => 0,
|
||||
'group_avatar_width' => 0,
|
||||
'group_rank' => 0,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => '',
|
||||
'user_rank' => 0,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Setting new default group without settings for user with custom settings - no change',
|
||||
3,
|
||||
2,
|
||||
array(
|
||||
'group_avatar' => '',
|
||||
'group_avatar_type' => 0,
|
||||
'group_avatar_height' => 0,
|
||||
'group_avatar_width' => 0,
|
||||
'group_rank' => 0,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => 'custom',
|
||||
'user_rank' => 2,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Setting new default group with settings for user with no settings - user settings overwritten',
|
||||
1,
|
||||
3,
|
||||
array(
|
||||
'group_avatar' => 'default2',
|
||||
'group_avatar_type' => 1,
|
||||
'group_avatar_height' => 1,
|
||||
'group_avatar_width' => 1,
|
||||
'group_rank' => 3,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => 'default2',
|
||||
'user_rank' => 3,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Setting new default group with settings for user with default settings - user settings overwritten',
|
||||
2,
|
||||
3,
|
||||
array(
|
||||
'group_avatar' => 'default2',
|
||||
'group_avatar_type' => 1,
|
||||
'group_avatar_height' => 1,
|
||||
'group_avatar_width' => 1,
|
||||
'group_rank' => 3,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => 'default2',
|
||||
'user_rank' => 3,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Setting new default group with settings for user with custom settings - no change',
|
||||
3,
|
||||
3,
|
||||
array(
|
||||
'group_avatar' => 'default2',
|
||||
'group_avatar_type' => 1,
|
||||
'group_avatar_height' => 1,
|
||||
'group_avatar_width' => 1,
|
||||
'group_rank' => 3,
|
||||
),
|
||||
array(
|
||||
'user_avatar' => 'custom',
|
||||
'user_rank' => 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider group_user_attributes_data
|
||||
*/
|
||||
public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected)
|
||||
{
|
||||
global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container;
|
||||
|
||||
$user->ip = '';
|
||||
$cache = new phpbb_mock_cache;
|
||||
$db = $this->new_dbal();
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
|
||||
$auth = $this->getMock('phpbb_auth');
|
||||
$auth->expects($this->any())
|
||||
->method('acl_clear_prefetch');
|
||||
$cache_driver = new phpbb_cache_driver_null();
|
||||
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$phpbb_container
|
||||
->expects($this->any())
|
||||
->method('get')
|
||||
->with('cache.driver')
|
||||
->will($this->returnValue($cache_driver));
|
||||
|
||||
group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row);
|
||||
|
||||
$sql = 'SELECT user_avatar, user_rank
|
||||
FROM ' . USERS_TABLE . '
|
||||
WHERE user_id = ' . $user_id;
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$this->assertEquals(array($expected), $db->sql_fetchrowset($result));
|
||||
|
||||
$db->sql_freeresult($result);
|
||||
}
|
||||
}
|
@@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface
|
||||
public function sql_load($query)
|
||||
{
|
||||
}
|
||||
public function sql_save($query, $query_result, $ttl)
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl)
|
||||
{
|
||||
return $query_result;
|
||||
}
|
||||
|
@@ -11,6 +11,9 @@ use Symfony\Component\DependencyInjection\ScopeInterface;
|
||||
|
||||
class phpbb_mock_container_builder implements ContainerInterface
|
||||
{
|
||||
protected $services = array();
|
||||
protected $parameters = array();
|
||||
|
||||
/**
|
||||
* Sets a service.
|
||||
*
|
||||
@@ -22,6 +25,7 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
|
||||
{
|
||||
$this->services[$id] = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +46,12 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
||||
{
|
||||
if ($this->has($id))
|
||||
{
|
||||
return $this->services[$id];
|
||||
}
|
||||
|
||||
throw new Exception('Could not find service: ' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +65,7 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function has($id)
|
||||
{
|
||||
return isset($this->services[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +81,12 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
if ($this->hasParameter($name))
|
||||
{
|
||||
return $this->parameters[$name];
|
||||
}
|
||||
|
||||
throw new Exception('Could not find parameter: ' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +100,7 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function hasParameter($name)
|
||||
{
|
||||
return isset($this->parameters[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +113,7 @@ class phpbb_mock_container_builder implements ContainerInterface
|
||||
*/
|
||||
public function setParameter($name, $value)
|
||||
{
|
||||
$this->parameters[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
94
tests/mock/notification_manager.php
Normal file
94
tests/mock/notification_manager.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package notifications
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications service class
|
||||
* @package notifications
|
||||
*/
|
||||
class phpbb_mock_notification_manager
|
||||
{
|
||||
public function load_notifications()
|
||||
{
|
||||
return array(
|
||||
'notifications' => array(),
|
||||
'unread_count' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
public function mark_notifications_read()
|
||||
{
|
||||
}
|
||||
|
||||
public function mark_notifications_read_by_parent()
|
||||
{
|
||||
}
|
||||
|
||||
public function mark_notifications_read_by_id()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function add_notifications()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function add_notifications_for_users()
|
||||
{
|
||||
}
|
||||
|
||||
public function update_notifications()
|
||||
{
|
||||
}
|
||||
|
||||
public function delete_notifications()
|
||||
{
|
||||
}
|
||||
|
||||
public function get_subscription_types()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_subscription_methods()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function get_global_subscriptions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function add_subscription()
|
||||
{
|
||||
}
|
||||
|
||||
public function delete_subscription()
|
||||
{
|
||||
}
|
||||
|
||||
public function load_users()
|
||||
{
|
||||
}
|
||||
|
||||
public function get_user()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
40
tests/mock/notifications_auth.php
Normal file
40
tests/mock/notifications_auth.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
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_mock_notifications_auth extends phpbb_auth
|
||||
{
|
||||
function acl_get_list($user_id = false, $opts = false, $forum_id = false)
|
||||
{
|
||||
$user_id = (!is_array($user_id)) ? array($user_id) : $user_id;
|
||||
$opts = (!is_array($opts)) ? array($opts) : $opts;
|
||||
$forum_id = (!is_array($forum_id)) ? array($forum_id) : $forum_id;
|
||||
|
||||
$auth_list = array();
|
||||
|
||||
foreach ($forum_id as $fid)
|
||||
{
|
||||
foreach ($opts as $opt)
|
||||
{
|
||||
$auth_list[$fid][$opt] = array();
|
||||
|
||||
foreach ($user_id as $uid)
|
||||
{
|
||||
$auth_list[$fid][$opt][] = $uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $auth_list;
|
||||
}
|
||||
|
||||
function acl_get($opt, $f = 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
69
tests/mock/notifications_notification_manager.php
Normal file
69
tests/mock/notifications_notification_manager.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package notifications
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications service class
|
||||
* @package notifications
|
||||
*/
|
||||
class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager
|
||||
{
|
||||
public function set_var($name, $value)
|
||||
{
|
||||
$this->$name = $value;
|
||||
}
|
||||
|
||||
// Extra dependencies for get_*_class functions
|
||||
protected $auth = null;
|
||||
protected $cache = null;
|
||||
protected $config = null;
|
||||
public function setDependencies($auth, $cache, $config)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the notifications item type class and set it up
|
||||
*/
|
||||
public function get_item_type_class($item_type, $data = array())
|
||||
{
|
||||
$item_type = 'phpbb_notification_type_' . $item_type;
|
||||
|
||||
$item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
||||
|
||||
$item->set_notification_manager($this);
|
||||
|
||||
$item->set_initial_data($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the notifications method class and set it up
|
||||
*/
|
||||
public function get_method_class($method_name)
|
||||
{
|
||||
$method_name = 'phpbb_notification_method_' . $method_name;
|
||||
|
||||
$method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table);
|
||||
|
||||
$method->set_notification_manager($this);
|
||||
|
||||
return $method;
|
||||
}
|
||||
}
|
85
tests/notification/ext/test/notification/type/test.php
Normal file
85
tests/notification/ext/test/notification/type/test.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package notifications
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
class phpbb_notification_type_test extends phpbb_notification_type_base
|
||||
{
|
||||
public function get_type()
|
||||
{
|
||||
return 'test';
|
||||
}
|
||||
|
||||
public static function get_item_id($post)
|
||||
{
|
||||
return (int) $post['post_id'];
|
||||
}
|
||||
|
||||
public static function get_item_parent_id($post)
|
||||
{
|
||||
return (int) $post['topic_id'];
|
||||
}
|
||||
|
||||
public function find_users_for_notification($post, $options = array())
|
||||
{
|
||||
return $this->check_user_notification_options(array(0), $options);
|
||||
}
|
||||
|
||||
public function create_insert_array($post, $pre_create_data = array())
|
||||
{
|
||||
$this->notification_time = $post['post_time'];
|
||||
|
||||
return parent::create_insert_array($post, $pre_create_data);
|
||||
}
|
||||
|
||||
public function create_update_array($type_data)
|
||||
{
|
||||
$data = $this->create_insert_array($type_data);
|
||||
|
||||
// Unset data unique to each row
|
||||
unset(
|
||||
$data['notification_id'],
|
||||
$data['notification_read'],
|
||||
$data['user_id']
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
return 'test title';
|
||||
}
|
||||
|
||||
public function users_to_query()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function get_url()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_email_template()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_email_template_variables()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
5
tests/notification/fixtures/notification.xml
Normal file
5
tests/notification/fixtures/notification.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_notifications">
|
||||
</table>
|
||||
</dataset>
|
385
tests/notification/notification.php
Normal file
385
tests/notification/notification.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_notification_test extends phpbb_database_test_case
|
||||
{
|
||||
protected $notifications, $db, $container, $user, $config, $auth, $cache;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml');
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!function_exists('set_var'))
|
||||
{
|
||||
include($phpbb_root_path . 'includes/functions.' . $phpEx);
|
||||
}
|
||||
|
||||
include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx);
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->config = new phpbb_config(array(
|
||||
'allow_privmsg' => true,
|
||||
'allow_bookmarks' => true,
|
||||
'allow_topic_notify' => true,
|
||||
'allow_forum_notify' => true,
|
||||
));
|
||||
$this->user = new phpbb_mock_user();
|
||||
$this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users');
|
||||
$this->auth = new phpbb_mock_notifications_auth();
|
||||
$this->cache = new phpbb_mock_cache();
|
||||
|
||||
$this->container = new phpbb_mock_container_builder();
|
||||
|
||||
$this->notifications = new phpbb_mock_notifications_notification_manager(
|
||||
array(),
|
||||
array(),
|
||||
$this->container,
|
||||
$this->user_loader,
|
||||
$this->db,
|
||||
$this->user,
|
||||
$phpbb_root_path,
|
||||
$phpEx,
|
||||
'phpbb_notification_types',
|
||||
'phpbb_notifications',
|
||||
'phpbb_user_notifications'
|
||||
);
|
||||
|
||||
$this->notifications->setDependencies($this->auth, $this->cache, $this->config);
|
||||
|
||||
$types = array();
|
||||
foreach (array(
|
||||
'test',
|
||||
'approve_post',
|
||||
'approve_topic',
|
||||
'bookmark',
|
||||
'disapprove_post',
|
||||
'disapprove_topic',
|
||||
'pm',
|
||||
'post',
|
||||
'post_in_queue',
|
||||
'quote',
|
||||
'report_pm',
|
||||
'report_pm_closed',
|
||||
'report_post',
|
||||
'report_post_closed',
|
||||
'topic',
|
||||
'topic_in_queue',
|
||||
) as $type)
|
||||
{
|
||||
$class = $this->build_type('phpbb_notification_type_' . $type);
|
||||
|
||||
$types[$type] = $class;
|
||||
$this->container->set('notification.type.' . $type, $class);
|
||||
}
|
||||
|
||||
$this->notifications->set_var('notification_types', $types);
|
||||
}
|
||||
|
||||
protected function build_type($type)
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications');
|
||||
}
|
||||
|
||||
public function test_get_subscription_types()
|
||||
{
|
||||
$subscription_types = $this->notifications->get_subscription_types();
|
||||
|
||||
$this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
|
||||
$this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
|
||||
|
||||
$this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
||||
$this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
||||
$this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
||||
$this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
|
||||
|
||||
$this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
|
||||
|
||||
//get_subscription_types
|
||||
//get_subscription_methods
|
||||
}
|
||||
|
||||
public function test_subscriptions()
|
||||
{
|
||||
$this->notifications->delete_subscription('post', 0, '', 2);
|
||||
|
||||
$this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2));
|
||||
|
||||
$this->notifications->add_subscription('post', 0, '', 2);
|
||||
|
||||
$this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2));
|
||||
}
|
||||
|
||||
public function test_notifications()
|
||||
{
|
||||
// Used to test post notifications later
|
||||
$this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||
'topic_id' => 2,
|
||||
'notify_status' => NOTIFY_YES,
|
||||
'user_id' => 0,
|
||||
)));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'notifications' => array(),
|
||||
'unread_count' => 0,
|
||||
'total_count' => 0,
|
||||
), $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
)));
|
||||
|
||||
$this->notifications->add_notifications('test', array(
|
||||
'post_id' => '1',
|
||||
'topic_id' => '1',
|
||||
'post_time' => 1349413321,
|
||||
));
|
||||
|
||||
$this->notifications->add_notifications('test', array(
|
||||
'post_id' => '2',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1349413322,
|
||||
));
|
||||
|
||||
$this->notifications->add_notifications('test', array(
|
||||
'post_id' => '3',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1349413323,
|
||||
));
|
||||
|
||||
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
||||
'post_id' => '4',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1349413324,
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title',
|
||||
'post_subject' => 'Re: test-title',
|
||||
'forum_id' => 2,
|
||||
'forum_name' => 'Your first forum',
|
||||
));
|
||||
|
||||
$this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||
'topic_id' => 2,
|
||||
'user_id' => 0,
|
||||
)));
|
||||
|
||||
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
||||
'post_id' => '5',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1349413325,
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title',
|
||||
'post_subject' => 'Re: test-title',
|
||||
'forum_id' => 2,
|
||||
'forum_name' => 'Your first forum',
|
||||
));
|
||||
|
||||
$this->notifications->delete_subscription('test');
|
||||
|
||||
$this->notifications->add_notifications('test', array(
|
||||
'post_id' => '6',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1349413326,
|
||||
));
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
1 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 1,
|
||||
'item_parent_id' => 1,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413321,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
2 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 2,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413322,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
3 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 3,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413323,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
4 => array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 4,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413324,
|
||||
'notification_data' => array(
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title',
|
||||
'post_subject' => 'Re: test-title',
|
||||
'post_username' => '',
|
||||
'forum_id' => 2,
|
||||
'forum_name' => 'Your first forum',
|
||||
),
|
||||
),
|
||||
5 => array(
|
||||
'item_type' => 'bookmark',
|
||||
'item_id' => 5,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413325,
|
||||
'notification_data' => array(
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title',
|
||||
'post_subject' => 'Re: test-title',
|
||||
'post_username' => '',
|
||||
'forum_id' => 2,
|
||||
'forum_name' => 'Your first forum',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
|
||||
|
||||
$notifications = $notifications['notifications'];
|
||||
|
||||
foreach ($expected as $notification_id => $notification_data)
|
||||
{
|
||||
//echo $notifications[$notification_id];
|
||||
|
||||
$this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
|
||||
|
||||
foreach ($notification_data as $key => $value)
|
||||
{
|
||||
$this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Now test updating -------------------------------
|
||||
|
||||
$this->notifications->update_notifications('test', array(
|
||||
'post_id' => '1',
|
||||
'topic_id' => '2', // change parent_id
|
||||
'post_time' => 1349413321,
|
||||
));
|
||||
|
||||
$this->notifications->update_notifications('test', array(
|
||||
'post_id' => '3',
|
||||
'topic_id' => '2',
|
||||
'post_time' => 1234, // change time
|
||||
));
|
||||
|
||||
$this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array(
|
||||
'post_id' => '5',
|
||||
'topic_id' => '2',
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title2', // change topic_title
|
||||
'post_subject' => 'Re: test-title2', // change post_subject
|
||||
'forum_id' => 3, // change forum_id
|
||||
'forum_name' => 'Your second forum', // change forum_name
|
||||
));
|
||||
|
||||
$notifications = $this->notifications->load_notifications(array(
|
||||
'count_unread' => true,
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
1 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 1,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413321,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
2 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 2,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413322,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
3 => array(
|
||||
'item_type' => 'test',
|
||||
'item_id' => 3,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1234,
|
||||
'notification_data' => array(),
|
||||
),
|
||||
4 => array(
|
||||
'item_type' => 'post',
|
||||
'item_id' => 4,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413324,
|
||||
'notification_data' => array(
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title',
|
||||
'post_subject' => 'Re: test-title',
|
||||
'post_username' => '',
|
||||
'forum_id' => 2,
|
||||
'forum_name' => 'Your first forum',
|
||||
),
|
||||
),
|
||||
5 => array(
|
||||
'item_type' => 'bookmark',
|
||||
'item_id' => 5,
|
||||
'item_parent_id' => 2,
|
||||
'user_id' => 0,
|
||||
'notification_read' => 0,
|
||||
'notification_time' => 1349413325,
|
||||
'notification_data' => array(
|
||||
'poster_id' => 2,
|
||||
'topic_title' => 'test-title2',
|
||||
'post_subject' => 'Re: test-title2',
|
||||
'post_username' => '',
|
||||
'forum_id' => 3,
|
||||
'forum_name' => 'Your second forum',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEquals(sizeof($expected), $notifications['unread_count']);
|
||||
|
||||
$notifications = $notifications['notifications'];
|
||||
|
||||
foreach ($expected as $notification_id => $notification_data)
|
||||
{
|
||||
//echo $notifications[$notification_id];
|
||||
|
||||
$this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
|
||||
|
||||
foreach ($notification_data as $key => $value)
|
||||
{
|
||||
$this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -81,10 +81,13 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
|
||||
*/
|
||||
public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to)
|
||||
{
|
||||
global $db;
|
||||
global $db, $phpbb_container;
|
||||
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
|
||||
|
||||
phpbb_delete_user_pms($delete_user);
|
||||
|
||||
$sql = 'SELECT msg_id
|
||||
|
@@ -1,54 +1,54 @@
|
||||
<?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__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
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', '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', 'using session_id'),
|
||||
|
||||
// Testing anchors
|
||||
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', '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', '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, $description)
|
||||
{
|
||||
global $phpbb_dispatcher;
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
|
||||
}
|
||||
}
|
||||
|
||||
<?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__) . '/../../phpBB/includes/functions.php';
|
||||
|
||||
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', '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', 'using session_id'),
|
||||
|
||||
// Testing anchors
|
||||
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', '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', '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, $description)
|
||||
{
|
||||
global $phpbb_dispatcher;
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -196,7 +196,25 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('loop'),
|
||||
'',
|
||||
),/* no top level nested loops
|
||||
),
|
||||
/* Currently fail on develop:
|
||||
http://tracker.phpbb.com/browse/PHPBB3-11323
|
||||
array(
|
||||
'include_define_variable.html',
|
||||
array('VARIABLE' => 'variable.html'),
|
||||
array(),
|
||||
array(),
|
||||
'variable.html',
|
||||
),
|
||||
array(
|
||||
'include_loop_define.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array('loop' => array(array('NESTED_FILE' => 'variable.html'))),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
*/
|
||||
/* no top level nested loops
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
|
2
tests/template/templates/include_define_variable.html
Normal file
2
tests/template/templates/include_define_variable.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<!-- DEFINE $DEF = '{VARIABLE}' -->
|
||||
<!-- INCLUDE {$DEF} -->
|
4
tests/template/templates/include_loop_define.html
Normal file
4
tests/template/templates/include_loop_define.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<!-- BEGIN loop -->
|
||||
<!-- DEFINE $DEF = '{loop.NESTED_FILE}' -->
|
||||
<!-- INCLUDE {$DEF} -->
|
||||
<!-- END loop -->
|
@@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager
|
||||
$this->purge_extras();
|
||||
break;
|
||||
|
||||
case 'phpbb_db_driver_postgres':
|
||||
$this->connect();
|
||||
// Drop all of the tables
|
||||
foreach ($this->get_tables() as $table)
|
||||
{
|
||||
$this->pdo->exec('DROP TABLE ' . $table . ' CASCADE');
|
||||
}
|
||||
$this->purge_extras();
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->connect(false);
|
||||
|
||||
@@ -418,6 +428,19 @@ class phpbb_database_test_connection_manager
|
||||
$queries[] = 'DROP SEQUENCE ' . current($row);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'phpbb_db_driver_postgres':
|
||||
$sql = 'SELECT sequence_name
|
||||
FROM information_schema.sequences';
|
||||
$result = $this->pdo->query($sql);
|
||||
|
||||
while ($row = $result->fetch(PDO::FETCH_NUM))
|
||||
{
|
||||
$queries[] = 'DROP SEQUENCE ' . current($row);
|
||||
}
|
||||
|
||||
$queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE';
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($queries as $query)
|
||||
|
@@ -134,19 +134,33 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!$this->extension_manager)
|
||||
{
|
||||
$this->extension_manager = new phpbb_extension_manager(
|
||||
$this->get_db(),
|
||||
new phpbb_config(array()),
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
$phpbb_root_path,
|
||||
".$phpEx",
|
||||
$this->get_cache_driver()
|
||||
);
|
||||
}
|
||||
$config = new phpbb_config(array());
|
||||
$db = $this->get_db();
|
||||
$db_tools = new phpbb_db_tools($db);
|
||||
|
||||
return $this->extension_manager;
|
||||
$extension_manager = new phpbb_extension_manager(
|
||||
new phpbb_mock_container_builder(),
|
||||
$db,
|
||||
$config,
|
||||
self::$config['table_prefix'] . 'ext',
|
||||
dirname(__FILE__) . '/',
|
||||
'.' . $php_ext,
|
||||
$this->get_cache_driver()
|
||||
);
|
||||
$migrator = new phpbb_db_migrator(
|
||||
$config,
|
||||
$db,
|
||||
$db_tools,
|
||||
self::$config['table_prefix'] . 'migrations',
|
||||
$phpbb_root_path,
|
||||
$php_ext,
|
||||
self::$config['table_prefix'],
|
||||
array()
|
||||
);
|
||||
$extension_manager->set_migrator($migrator);
|
||||
$migrator->set_extension_manager($extension_manager);
|
||||
|
||||
return $extension_manager;
|
||||
}
|
||||
|
||||
static protected function install_board()
|
||||
@@ -262,7 +276,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$config['rand_seed_last_update'] = time() + 600;
|
||||
|
||||
// Required by user_add
|
||||
global $db, $cache, $phpbb_dispatcher;
|
||||
global $db, $cache, $phpbb_dispatcher, $phpbb_container;
|
||||
$db = $this->get_db();
|
||||
if (!function_exists('phpbb_mock_null_cache'))
|
||||
{
|
||||
@@ -270,6 +284,14 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
}
|
||||
$cache = new phpbb_mock_null_cache;
|
||||
|
||||
$cache_driver = new phpbb_cache_driver_null();
|
||||
$phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$phpbb_container
|
||||
->expects($this->any())
|
||||
->method('get')
|
||||
->with('cache.driver')
|
||||
->will($this->returnValue($cache_driver));
|
||||
|
||||
if (!function_exists('utf_clean_string'))
|
||||
{
|
||||
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
|
||||
@@ -323,7 +345,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
* Login to the ACP
|
||||
* You must run login() before calling this.
|
||||
*/
|
||||
protected function admin_login()
|
||||
protected function admin_login($username = 'admin')
|
||||
{
|
||||
$this->add_lang('acp/common');
|
||||
|
||||
@@ -343,7 +365,9 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
{
|
||||
if (strpos($field, 'password_') === 0)
|
||||
{
|
||||
$login = $this->client->submit($form, array('username' => 'admin', $field => 'admin'));
|
||||
$crawler = $this->client->submit($form, array('username' => $username, $field => $username));
|
||||
$this->assert_response_success();
|
||||
$this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text());
|
||||
|
||||
$cookies = $this->cookieJar->all();
|
||||
|
||||
@@ -424,4 +448,20 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$content = $this->client->getResponse()->getContent();
|
||||
$this->assertNotContains('Fatal error:', $content);
|
||||
}
|
||||
|
||||
public function assert_filter($crawler, $expr, $msg = null)
|
||||
{
|
||||
$nodes = $crawler->filter($expr);
|
||||
if ($msg)
|
||||
{
|
||||
$msg .= "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$msg = '';
|
||||
}
|
||||
$msg .= "`$expr` not found in DOM.";
|
||||
$this->assertGreaterThan(0, count($nodes), $msg);
|
||||
return $nodes;
|
||||
}
|
||||
}
|
||||
|
@@ -77,6 +77,11 @@ class phpbb_test_case_helpers
|
||||
{
|
||||
include($test_config);
|
||||
|
||||
if (!function_exists('phpbb_convert_30_dbms_to_31'))
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
}
|
||||
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => phpbb_convert_30_dbms_to_31($dbms),
|
||||
'dbhost' => $dbhost,
|
||||
|
23
tests/user/fixtures/user_loader.xml
Normal file
23
tests/user/fixtures/user_loader.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_users">
|
||||
<column>user_id</column>
|
||||
<column>username</column>
|
||||
<column>username_clean</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>Guest</value>
|
||||
<value>guest</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>Admin</value>
|
||||
<value>admin</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>Test</value>
|
||||
<value>test</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
49
tests/user/user_loader.php
Normal file
49
tests/user/user_loader.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
|
||||
|
||||
class phpbb_user_lang_test extends phpbb_database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml');
|
||||
}
|
||||
|
||||
public function test_user_loader()
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
||||
$user_loader = new phpbb_user_loader($db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users');
|
||||
|
||||
$user_loader->load_users(array(2));
|
||||
|
||||
$user = $user_loader->get_user(1);
|
||||
$this->assertEquals(1, $user['user_id']);
|
||||
$this->assertEquals('Guest', $user['username']);
|
||||
|
||||
$user = $user_loader->get_user(2);
|
||||
$this->assertEquals(2, $user['user_id']);
|
||||
$this->assertEquals('Admin', $user['username']);
|
||||
|
||||
// Not loaded
|
||||
$user = $user_loader->get_user(3);
|
||||
$this->assertEquals(1, $user['user_id']);
|
||||
$this->assertEquals('Guest', $user['username']);
|
||||
|
||||
$user = $user_loader->get_user(3, true);
|
||||
$this->assertEquals(3, $user['user_id']);
|
||||
$this->assertEquals('Test', $user['username']);
|
||||
|
||||
$user_id = $user_loader->load_user_by_username('Test');
|
||||
$user = $user_loader->get_user($user_id);
|
||||
$this->assertEquals(3, $user['user_id']);
|
||||
$this->assertEquals('Test', $user['username']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user