1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
<?php
namespace Roundcube\Tests\Framework;
use Roundcube\Tests\ActionTestCase;
/**
* Test class to test rcube_user class
*/
class Framework_User extends ActionTestCase
{
/**
* Test class constructor
*/
function test_constructor()
{
self::initDB('init');
$user = new \rcube_user(1);
$this->assertSame(1, $user->ID);
$this->assertSame(null, $user->language);
}
/**
* Test get_username()
*/
function test_get_username()
{
self::initDB('init');
$user = new \rcube_user(1);
$this->assertSame('test@example.com', $user->get_username());
$this->assertSame('test', $user->get_username('local'));
$this->assertSame('example.com', $user->get_username('domain'));
}
/**
* Test save_prefs() and get_prefs() and get_hash()
*/
function test_save_prefs()
{
self::initDB('init');
$user = new \rcube_user(1);
$this->assertSame([], $user->get_prefs());
$user->save_prefs(['test' => 'test'], true);
$user = new \rcube_user(1);
$this->assertSame(['test' => 'test'], $user->get_prefs());
$hash = $user->get_hash();
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9]{16}$/', $hash);
$user = new \rcube_user(1);
$prefs = $user->get_prefs();
$this->assertSame('test', $prefs['test']);
$this->assertSame($hash, $prefs['client_hash']);
$this->assertSame($hash, $user->get_hash());
}
/**
* Test identities related methods
*/
function test_list_emails_and_identities()
{
self::initDB('init');
self::initDB('identities');
$user = new \rcube_user(1);
$all = $user->list_emails();
$this->assertCount(2, $all);
$this->assertSame('test@example.com', $all[0]['email']);
$this->assertSame('test@example.org', $all[1]['email']);
$ident = $user->list_emails(true);
$this->assertSame('test@example.com', $ident['email']);
$ident = $user->get_identity();
$this->assertSame('test@example.com', $ident['email']);
$idents = $user->list_identities('', true);
$this->assertCount(2, $idents);
$this->assertSame('test@example.com', $idents[0]['email_ascii']);
$this->assertSame('test <test@example.com>', $idents[0]['ident']);
$this->assertSame('test@example.org', $idents[1]['email_ascii']);
$this->assertSame('test <test@example.org>', $idents[1]['ident']);
$default = $idents[0]['identity_id'];
$res = $user->update_identity($idents[1]['identity_id'], ['name' => 'test-new']);
$this->assertTrue($res);
$ident = $user->get_identity($idents[1]['identity_id']);
$this->assertSame('test-new', $ident['name']);
$id = $user->insert_identity([
'name' => 'name',
'email' => 'add@ident.com',
]);
$this->assertTrue(is_numeric($id));
$ident = $user->get_identity($id);
$this->assertSame('name', $ident['name']);
$this->assertSame('add@ident.com', $ident['email']);
$idents = $user->list_identities();
$this->assertCount(3, $idents);
$ident = $user->set_default($id);
$idents = $user->list_identities();
$this->assertCount(3, $idents);
$this->assertSame('add@ident.com', $idents[0]['email']);
$this->assertEquals(1, $idents[0]['standard']);
$this->assertSame('test@example.com', $idents[1]['email']);
$this->assertEquals(0, $idents[1]['standard']);
$this->assertSame('test@example.org', $idents[2]['email']);
$this->assertEquals(0, $idents[2]['standard']);
$ident = $user->delete_identity($default);
$idents = $user->list_identities();
$this->assertCount(2, $idents);
}
/**
* Test failed_login() and is_locked()
*/
function test_failed_login()
{
self::initDB('init');
$user = new \rcube_user(1);
$user->failed_login();
$user = new \rcube_user(1);
$this->assertEquals(1, $user->data['failed_login_counter']);
$this->assertFalse($user->is_locked());
}
/**
* Test query()
*/
function test_query()
{
self::initDB('init');
$this->assertNull(\rcube_user::query('test', 'localhost'));
$user = \rcube_user::query('test@example.com', 'localhost');
$this->assertEquals(1, $user->ID);
}
/**
* Test create()
*/
function test_create()
{
self::initDB('init');
$user = \rcube_user::create('new@example.com', 'localhost');
$this->assertSame('new@example.com', $user->get_username());
$user = new \rcube_user($user->ID);
$idents = $user->list_identities();
$this->assertCount(1, $idents);
$this->assertSame('new@example.com', $idents[0]['email']);
$this->assertEquals(1, $idents[0]['standard']);
}
/**
* Test saved searches
*/
function test_saved_searches()
{
$this->markTestIncomplete();
}
}
|