aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/functions_messenger.php38
-rw-r--r--phpBB/phpbb/log/log.php2
-rw-r--r--phpBB/phpbb/session.php18
-rw-r--r--phpBB/posting.php3
-rw-r--r--tests/composer.json2
-rw-r--r--tests/composer.lock55
-rw-r--r--tests/test_framework/phpbb_ui_test_case.php377
7 files changed, 447 insertions, 48 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 0525cfc29e..9b3ca14101 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -231,6 +231,13 @@ class messenger
$template_lang = basename($config['default_lang']);
}
+ $ext_template_paths = array(
+ array(
+ 'name' => $template_lang . '_email',
+ 'ext_path' => 'language/' . $template_lang . '/email' . $template_dir_prefix,
+ ),
+ );
+
if ($template_path)
{
$template_paths = array(
@@ -246,23 +253,38 @@ class messenger
$template_path . $template_dir_prefix,
);
+ $board_language = basename($config['default_lang']);
+
// we can only specify default language fallback when the path is not a custom one for which we
// do not know the default language alternative
- if ($template_lang !== basename($config['default_lang']))
+ if ($template_lang !== $board_language)
{
$fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
- $fallback_template_path .= basename($config['default_lang']) . '/email';
+ $fallback_template_path .= $board_language . '/email';
$template_paths[] = $fallback_template_path . $template_dir_prefix;
+
+ $ext_template_paths[] = array(
+ 'name' => $board_language . '_email',
+ 'ext_path' => 'language/' . $board_language . '/email' . $template_dir_prefix,
+ );
+ }
+ // If everything fails just fall back to en template
+ if ($template_lang !== 'en' && $board_language !== 'en')
+ {
+ $fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
+ $fallback_template_path .= 'en/email';
+
+ $template_paths[] = $fallback_template_path . $template_dir_prefix;
+
+ $ext_template_paths[] = array(
+ 'name' => 'en_email',
+ 'ext_path' => 'language/en/email' . $template_dir_prefix,
+ );
}
}
- $this->set_template_paths(array(
- array(
- 'name' => $template_lang . '_email',
- 'ext_path' => 'language/' . $template_lang . '/email' . $template_dir_prefix,
- ),
- ), $template_paths);
+ $this->set_template_paths($ext_template_paths, $template_paths);
$this->template->set_filenames(array(
'body' => $template_file . '.txt',
diff --git a/phpBB/phpbb/log/log.php b/phpBB/phpbb/log/log.php
index d46e3d1f3f..094ff78abe 100644
--- a/phpBB/phpbb/log/log.php
+++ b/phpBB/phpbb/log/log.php
@@ -402,7 +402,7 @@ class log implements \phpbb\log\log_interface
}
}
- $sql = 'DELETE FROM ' . LOG_TABLE . "
+ $sql = 'DELETE FROM ' . $this->log_table . "
$sql_where";
$this->db->sql_query($sql);
diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php
index 33d8df9cb8..eb5543b50b 100644
--- a/phpBB/phpbb/session.php
+++ b/phpBB/phpbb/session.php
@@ -219,7 +219,7 @@ class session
function session_begin($update_session_page = true)
{
global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path;
- global $request, $phpbb_container;
+ global $request, $phpbb_container, $phpbb_dispatcher;
// Give us some basic information
$this->time_now = time();
@@ -281,11 +281,21 @@ class session
// Why no forwarded_for et al? Well, too easily spoofed. With the results of my recent requests
// it's pretty clear that in the majority of cases you'll at least be left with a proxy/cache ip.
- $this->ip = htmlspecialchars_decode($request->server('REMOTE_ADDR'));
- $this->ip = preg_replace('# {2,}#', ' ', str_replace(',', ' ', $this->ip));
+ $ip = htmlspecialchars_decode($request->server('REMOTE_ADDR'));
+ $ip = preg_replace('# {2,}#', ' ', str_replace(',', ' ', $ip));
+
+ /**
+ * Event to alter user IP address
+ *
+ * @event core.session_ip_after
+ * @var string ip REMOTE_ADDR
+ * @since 3.1.10-RC1
+ */
+ $vars = array('ip');
+ extract($phpbb_dispatcher->trigger_event('core.session_ip_after', compact($vars)));
// split the list of IPs
- $ips = explode(' ', trim($this->ip));
+ $ips = explode(' ', trim($ip));
// Default IP if REMOTE_ADDR is invalid
$this->ip = '127.0.0.1';
diff --git a/phpBB/posting.php b/phpBB/posting.php
index f1e8452305..db580d926b 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -371,7 +371,9 @@ switch ($mode)
* NOTE: Should be actual language strings, NOT
* language keys.
* @var bool is_authed Does the user have the required permissions?
+* @var array post_data All post data from database
* @since 3.1.3-RC1
+* @changed 3.1.10-RC1 Added post_data
*/
$vars = array(
'post_id',
@@ -387,6 +389,7 @@ $vars = array(
'mode',
'error',
'is_authed',
+ 'post_data',
);
extract($phpbb_dispatcher->trigger_event('core.modify_posting_auth', compact($vars)));
diff --git a/tests/composer.json b/tests/composer.json
index 69512f30a6..057e0115a5 100644
--- a/tests/composer.json
+++ b/tests/composer.json
@@ -1,5 +1,5 @@
{
"require-dev": {
- "facebook/webdriver": "dev-master"
+ "facebook/webdriver": "~1.1"
}
}
diff --git a/tests/composer.lock b/tests/composer.lock
index f714495d84..f172de4669 100644
--- a/tests/composer.lock
+++ b/tests/composer.lock
@@ -1,45 +1,48 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
- "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
- ],
- "hash": "cf1d8a4841e5e669b148e0df6645a788",
- "packages": [
-
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "This file is @generated automatically"
],
+ "hash": "25ad22c35c19f2b0a2331640fb6b5577",
+ "content-hash": "617c33144bd2877c3c9a78f167a871b6",
+ "packages": [],
"packages-dev": [
{
"name": "facebook/webdriver",
- "version": "dev-master",
+ "version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-webdriver.git",
- "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796"
+ "reference": "0b889d7de7461439f8a3bbcca46e0f696cb27986"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/b6e002e5bf811a8edba393ce6872322c1b7cf796",
- "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796",
+ "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/0b889d7de7461439f8a3bbcca46e0f696cb27986",
+ "reference": "0b889d7de7461439f8a3bbcca46e0f696cb27986",
"shasum": ""
},
"require": {
+ "ext-curl": "*",
"php": ">=5.3.19"
},
"require-dev": {
- "phpdocumentor/phpdocumentor": "2.*",
- "phpunit/phpunit": "3.7.*"
+ "phpunit/phpunit": "4.6.*"
+ },
+ "suggest": {
+ "phpdocumentor/phpdocumentor": "2.*"
},
"type": "library",
"autoload": {
- "classmap": [
- "lib/"
- ]
+ "psr-4": {
+ "Facebook\\WebDriver\\": "lib/"
+ }
},
- "notification-url": "http://packagist.org/downloads/",
+ "notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
- "description": "A php client for WebDriver",
+ "description": "A PHP client for WebDriver",
"homepage": "https://github.com/facebook/php-webdriver",
"keywords": [
"facebook",
@@ -47,20 +50,14 @@
"selenium",
"webdriver"
],
- "time": "2014-08-05 02:55:46"
+ "time": "2016-06-04 00:02:34"
}
],
- "aliases": [
-
- ],
+ "aliases": [],
"minimum-stability": "stable",
- "stability-flags": {
- "facebook/webdriver": 20
- },
- "platform": [
-
- ],
- "platform-dev": [
-
- ]
+ "stability-flags": [],
+ "prefer-stable": false,
+ "prefer-lowest": false,
+ "platform": [],
+ "platform-dev": []
}
diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php
index c8ac492e25..e8b230ecbe 100644
--- a/tests/test_framework/phpbb_ui_test_case.php
+++ b/tests/test_framework/phpbb_ui_test_case.php
@@ -11,6 +11,11 @@
*
*/
+use Facebook\WebDriver\WebDriverBy;
+use Facebook\WebDriver\Exception\WebDriverCurlException;
+use Facebook\WebDriver\Remote\RemoteWebDriver;
+use Facebook\WebDriver\Remote\DesiredCapabilities;
+
require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
class phpbb_ui_test_case extends phpbb_test_case
@@ -19,13 +24,30 @@ class phpbb_ui_test_case extends phpbb_test_case
static protected $port = 8910;
/**
- * @var \RemoteWebDriver
+ * @var RemoteWebDriver
*/
static protected $webDriver;
static protected $config;
static protected $root_url;
static protected $already_installed = false;
+ static protected $install_success = false;
+
+ protected $cache = null;
+ protected $db = null;
+ protected $extension_manager = null;
+
+ /**
+ * Session ID for current test's session (each test makes its own)
+ * @var string
+ */
+ protected $sid;
+
+ /**
+ * Language array used by phpBB
+ * @var array
+ */
+ protected $lang = array();
static public function setUpBeforeClass()
{
@@ -35,7 +57,7 @@ class phpbb_ui_test_case extends phpbb_test_case
{
self::markTestSkipped('UI test case requires at least PHP 5.3.19.');
}
- else if (!class_exists('\RemoteWebDriver'))
+ else if (!class_exists('\Facebook\WebDriver\Remote\RemoteWebDriver'))
{
self::markTestSkipped(
'Could not find RemoteWebDriver class. ' .
@@ -60,7 +82,7 @@ class phpbb_ui_test_case extends phpbb_test_case
if (!self::$webDriver)
{
try {
- $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox');
+ $capabilities = DesiredCapabilities::firefox();
self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities);
} catch (WebDriverCurlException $e) {
self::markTestSkipped('PhantomJS webserver is not running.');
@@ -74,6 +96,57 @@ class phpbb_ui_test_case extends phpbb_test_case
}
}
+ /**
+ * @return array List of extensions that should be set up
+ */
+ static protected function setup_extensions()
+ {
+ return array();
+ }
+
+ public function setUp()
+ {
+ if (!self::$install_success)
+ {
+ $this->fail('Installing phpBB has failed.');
+ }
+
+ // Clear the language array so that things
+ // that were added in other tests are gone
+ $this->lang = array();
+ $this->add_lang('common');
+
+ $db = $this->get_db();
+
+ foreach (static::setup_extensions() as $extension)
+ {
+ $this->purge_cache();
+
+ $sql = 'SELECT ext_active
+ FROM ' . EXT_TABLE . "
+ WHERE ext_name = '" . $db->sql_escape($extension). "'";
+ $result = $db->sql_query($sql);
+ $status = (bool) $db->sql_fetchfield('ext_active');
+ $db->sql_freeresult($result);
+
+ if (!$status)
+ {
+ $this->install_ext($extension);
+ }
+ }
+ }
+
+ protected function tearDown()
+ {
+ parent::tearDown();
+
+ if ($this->db instanceof \phpbb\db\driver\driver_interface)
+ {
+ // Close the database connections again this test
+ $this->db->sql_close();
+ }
+ }
+
static public function visit($path)
{
self::$webDriver->get(self::$root_url . $path);
@@ -96,9 +169,9 @@ class phpbb_ui_test_case extends phpbb_test_case
$element->click();
}
- static public function install_board()
+ static protected function install_board()
{
- global $phpbb_root_path, $phpEx;
+ global $phpbb_root_path, $phpEx, $db;
self::recreate_database(self::$config);
@@ -200,5 +273,299 @@ class phpbb_ui_test_case extends phpbb_test_case
self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText());
copy($config_file, $config_file_test);
+
+ self::$install_success = true;
+ }
+
+ public function install_ext($extension)
+ {
+ $this->login();
+ $this->admin_login();
+
+ $ext_path = str_replace('/', '%2F', $extension);
+
+ $this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid);
+ $this->assertNotEmpty(count(self::find_element('cssSelector', '.submit-buttons')));
+
+ self::find_element('cssSelector', "input[value='Enable']")->submit();
+ $this->add_lang('acp/extensions');
+
+ try
+ {
+ $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]');
+
+ // Wait for extension to be fully enabled
+ while (sizeof($meta_refresh))
+ {
+ preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match);
+ self::$webDriver->execute(array('method' => 'post', 'url' => $match[1]));
+ $meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]');
+ }
+ }
+ catch (\Facebook\WebDriver\Exception\NoSuchElementException $e)
+ {
+ // Probably no refresh triggered
+ }
+
+ $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText());
+
+ $this->logout();
+ }
+
+ protected function get_cache_driver()
+ {
+ if (!$this->cache)
+ {
+ $this->cache = new \phpbb\cache\driver\file;
+ }
+
+ return $this->cache;
+ }
+
+ protected function purge_cache()
+ {
+ $cache = $this->get_cache_driver();
+
+ $cache->purge();
+ $cache->unload();
+ $cache->load();
+ }
+
+ protected function get_extension_manager()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $config = new \phpbb\config\config(array());
+ $db = $this->get_db();
+ $db_tools = new \phpbb\db\tools($db);
+
+ $container = new phpbb_mock_container_builder();
+ $migrator = new \phpbb\db\migrator(
+ $container,
+ $config,
+ $db,
+ $db_tools,
+ self::$config['table_prefix'] . 'migrations',
+ $phpbb_root_path,
+ $phpEx,
+ self::$config['table_prefix'],
+ array(),
+ new \phpbb\db\migration\helper()
+ );
+ $container->set('migrator', $migrator);
+ $container->set('dispatcher', new phpbb_mock_event_dispatcher());
+ $user = new \phpbb\user('\phpbb\datetime');
+
+ $extension_manager = new \phpbb\extension\manager(
+ $container,
+ $db,
+ $config,
+ new phpbb\filesystem(),
+ $user,
+ self::$config['table_prefix'] . 'ext',
+ dirname(__FILE__) . '/',
+ $phpEx,
+ $this->get_cache_driver()
+ );
+
+ return $extension_manager;
+ }
+
+ protected function get_db()
+ {
+ // so we don't reopen an open connection
+ if (!($this->db instanceof \phpbb\db\driver\driver_interface))
+ {
+ $dbms = self::$config['dbms'];
+ /** @var \phpbb\db\driver\driver_interface $db */
+ $db = new $dbms();
+ $db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
+ $this->db = $db;
+ }
+ return $this->db;
+ }
+
+ protected function logout()
+ {
+ $this->add_lang('ucp');
+
+ if (empty($this->sid))
+ {
+ return;
+ }
+
+ $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout');
+ $this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource());
+ unset($this->sid);
+
+ }
+
+ /**
+ * Login to the ACP
+ * You must run login() before calling this.
+ */
+ protected function admin_login($username = 'admin')
+ {
+ $this->add_lang('acp/common');
+
+ // Requires login first!
+ if (empty($this->sid))
+ {
+ $this->fail('$this->sid is empty. Make sure you call login() before admin_login()');
+ return;
+ }
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ $this->visit('adm/index.php?sid=' . $this->sid);
+ $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource());
+
+ self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username);
+ self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username);
+ self::find_element('cssSelector', 'input[name=login]')->click();
+ $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText());
+
+ $cookies = self::$webDriver->manage()->getCookies();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie)
+ {
+ if (substr($cookie['name'], -4) == '_sid')
+ {
+ $this->sid = $cookie['value'];
+
+ break;
+ }
+ }
+
+ $this->assertNotEmpty($this->sid);
+ }
+
+ protected function add_lang($lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang($file);
+ }
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
+ protected function add_lang_ext($ext_name, $lang_file)
+ {
+ if (is_array($lang_file))
+ {
+ foreach ($lang_file as $file)
+ {
+ $this->add_lang_ext($ext_name, $file);
+ }
+
+ return;
+ }
+
+ $lang_path = __DIR__ . "/../../phpBB/ext/{$ext_name}/language/en/$lang_file.php";
+
+ $lang = array();
+
+ if (file_exists($lang_path))
+ {
+ include($lang_path);
+ }
+
+ $this->lang = array_merge($this->lang, $lang);
+ }
+
+ protected function lang()
+ {
+ $args = func_get_args();
+ $key = $args[0];
+
+ if (empty($this->lang[$key]))
+ {
+ throw new RuntimeException('Language key "' . $key . '" could not be found.');
+ }
+
+ $args[0] = $this->lang[$key];
+
+ return call_user_func_array('sprintf', $args);
+ }
+
+ /**
+ * assertContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ /**
+ * assertNotContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertNotContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertNotContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
+
+ protected function login($username = 'admin')
+ {
+ $this->add_lang('ucp');
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ $this->visit('ucp.php');
+ $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource());
+
+ self::$webDriver->manage()->deleteAllCookies();
+
+ self::find_element('cssSelector', 'input[name=username]')->sendKeys($username);
+ self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username);
+ self::find_element('cssSelector', 'input[name=login]')->click();
+ $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText());
+
+ $cookies = self::$webDriver->manage()->getCookies();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie)
+ {
+ if (substr($cookie['name'], -4) == '_sid')
+ {
+ $this->sid = $cookie['value'];
+ }
+ }
+
+ $this->assertNotEmpty($this->sid);
+ }
+
+ /**
+ * Take screenshot. Can be used for debug purposes.
+ *
+ * @throws Exception When screenshot can't be created
+ */
+ public function take_screenshot()
+ {
+ // Change the Path to your own settings
+ $screenshot = time() . ".png";
+
+ self::$webDriver->takeScreenshot($screenshot);
}
}