aboutsummaryrefslogtreecommitdiffstats
path: root/tests/user
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2020-05-08 18:29:30 +0200
committerMaat <maat-pub@mageia.biz>2020-05-08 21:36:04 +0200
commit36bc1870f21fac04736a1049c1d5b8e127d729f4 (patch)
tree9d102331eeaf1ef3cd23e656320d7c08e65757ed /tests/user
parent8875d385d0579b451dac4d9bda465172b4f69ee0 (diff)
parent149375253685b3a38996f63015a74b7a0f53aa14 (diff)
downloadforums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.gz
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.bz2
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.tar.xz
forums-36bc1870f21fac04736a1049c1d5b8e127d729f4.zip
Merge remote-tracking branch 'upstream/prep-release-3.1.11'
Diffstat (limited to 'tests/user')
-rw-r--r--tests/user/fixtures/user_loader.xml31
-rw-r--r--tests/user/lang_test.php73
-rw-r--r--tests/user/user_loader_test.php67
3 files changed, 165 insertions, 6 deletions
diff --git a/tests/user/fixtures/user_loader.xml b/tests/user/fixtures/user_loader.xml
new file mode 100644
index 0000000000..f676f468a6
--- /dev/null
+++ b/tests/user/fixtures/user_loader.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>user_permissions</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value></value>
+ <value>Guest</value>
+ <value>guest</value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value></value>
+ <value>Admin</value>
+ <value>admin</value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value></value>
+ <value>Test</value>
+ <value>test</value>
+ <value></value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php
index d33f430955..bb11bb63cb 100644
--- a/tests/user/lang_test.php
+++ b/tests/user/lang_test.php
@@ -1,19 +1,23 @@
<?php
/**
*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/session.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_user_lang_test extends phpbb_test_case
{
public function test_user_lang_sprintf()
{
- $user = new user;
+ $user = new \phpbb\user('\phpbb\datetime');
$user->lang = array(
'FOO' => 'BAR',
'BARZ' => 'PENG',
@@ -26,6 +30,26 @@ class phpbb_user_lang_test extends phpbb_test_case
1 => '1 post', // 1
2 => '%d posts', // 2+
),
+ 'ARRY_NO_ZERO' => array(
+ 1 => '1 post', // 1
+ 2 => '%d posts', // 0, 2+
+ ),
+ 'ARRY_MISSING' => array(
+ 1 => '%d post', // 1
+ //Missing second plural
+ ),
+ 'ARRY_FLOAT' => array(
+ 1 => '1 post', // 1.x
+ 2 => '%1$.1f posts', // 0.x, 2+.x
+ ),
+ 'ARRY_EMPTY' => array(
+ ),
+ 'dateformat' => array(
+ 'AGO' => array(
+ 1 => '%d second',
+ 2 => '%d seconds',
+ ),
+ ),
);
// No param
@@ -51,8 +75,45 @@ class phpbb_user_lang_test extends phpbb_test_case
$this->assertEquals($user->lang('ARRY', 2), '2 posts');
$this->assertEquals($user->lang('ARRY', 123), '123 posts');
- // Bug PHPBB3-9949
+ // Empty array returns the language key
+ $this->assertEquals($user->lang('ARRY_EMPTY', 123), 'ARRY_EMPTY');
+
+ // No 0 key defined
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 0), '0 posts');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 1), '1 post');
+ $this->assertEquals($user->lang('ARRY_NO_ZERO', 2), '2 posts');
+
+ // Array with missing keys
+ $this->assertEquals($user->lang('ARRY_MISSING', 2), '2 post');
+
+ // Floats as array key
+ $this->assertEquals($user->lang('ARRY_FLOAT', 1.3), '1 post');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.0), '2.0 posts');
+ $this->assertEquals($user->lang('ARRY_FLOAT', 2.51), '2.5 posts');
+
+ // Use sub key, if first paramenter is an array
+ $this->assertEquals($user->lang(array('dateformat', 'AGO'), 2), '2 seconds');
+
+ // ticket PHPBB3-9949 - use first int to determinate the plural-form to use
$this->assertEquals($user->lang('ARRY', 1, 2), '1 post');
$this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post');
+
+ // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+
+ $user = new \phpbb\user('\phpbb\datetime');
+ $user->lang = array(
+ 'PLURAL_RULE' => 13,
+ 'ARRY' => array(
+ 0 => '%d is 0', // 0
+ 1 => '%d is 1', // 1
+ 2 => '%d ends with 01-10', // ending with 01-10
+ 3 => '%d ends with 11-19', // ending with 11-19
+ 4 => '%d is part of the last rule', // everything else
+ ),
+ );
+ $this->assertEquals($user->lang('ARRY', 0), '0 is 0');
+ $this->assertEquals($user->lang('ARRY', 1), '1 is 1');
+ $this->assertEquals($user->lang('ARRY', 103), '103 ends with 01-10');
+ $this->assertEquals($user->lang('ARRY', 15), '15 ends with 11-19');
+ $this->assertEquals($user->lang('ARRY', 300), '300 is part of the last rule');
}
}
diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php
new file mode 100644
index 0000000000..8d1f43707b
--- /dev/null
+++ b/tests/user/user_loader_test.php
@@ -0,0 +1,67 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
+
+class phpbb_user_loader_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $user_loader;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml');
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->db = $this->new_dbal();
+ $this->user_loader = new \phpbb\user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users');
+ }
+
+ public function test_load_get()
+ {
+ $this->user_loader->load_users(array(2));
+
+ $user = $this->user_loader->get_user(1);
+ $this->assertEquals(1, $user['user_id']);
+ $this->assertEquals('Guest', $user['username']);
+
+ $user = $this->user_loader->get_user(2);
+ $this->assertEquals(2, $user['user_id']);
+ $this->assertEquals('Admin', $user['username']);
+ }
+
+ public function test_load_get_unloaded()
+ {
+ $this->user_loader->load_users(array(2));
+
+ $user = $this->user_loader->get_user(3);
+ $this->assertEquals(1, $user['user_id']);
+ $this->assertEquals('Guest', $user['username']);
+
+ $user = $this->user_loader->get_user(3, true);
+ $this->assertEquals(3, $user['user_id']);
+ $this->assertEquals('Test', $user['username']);
+ }
+
+ public function test_load_user_by_username()
+ {
+ $user_id = $this->user_loader->load_user_by_username('Test');
+ $user = $this->user_loader->get_user($user_id);
+ $this->assertEquals(3, $user['user_id']);
+ $this->assertEquals('Test', $user['username']);
+ }
+}