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
|
<?php
namespace Roundcube\Tests\Framework;
use PHPUnit\Framework\TestCase;
/**
* Test class to test rcube_addressbook class
*/
class Framework_Addressbook extends TestCase
{
/**
* Test for get_col_values() method
*/
function test_get_col_values()
{
$data = ['email' => 'test@test.com', 'other' => 'test'];
$result = \rcube_addressbook::get_col_values('email', $data, true);
$this->assertSame(['test@test.com'], $result);
$data = ['email:home' => 'test@test.com', 'other' => 'test'];
$result = \rcube_addressbook::get_col_values('email', $data, true);
$this->assertSame(['test@test.com'], $result);
$data = ['email:home' => 'test@test.com', 'other' => 'test'];
$result = \rcube_addressbook::get_col_values('email', $data, false);
$this->assertSame(['home' => ['test@test.com']], $result);
}
/**
* Test for compose_list_name() method
*/
function test_compose_list_name()
{
$contact = [];
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('', $result);
$contact = ['email' => 'email@address.tld'];
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('email@address.tld', $result);
$contact = ['email' => 'email@address.tld', 'organization' => 'Org'];
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('Org', $result);
$contact['firstname'] = 'First';
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('First', $result);
$contact['surname'] = 'Last';
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('First Last', $result);
$contact['name'] = 'Name';
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('Name', $result);
unset($contact['name']);
$contact['prefix'] = 'Dr.';
$contact['suffix'] = 'Jr.';
$contact['middlename'] = 'M.';
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('Dr. First M. Last Jr.', $result);
// TODO: Test different modes
/*
\rcube::get_instance()->config->set('addressbook_name_listing', 3);
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('Last, First M.', $result);
\rcube::get_instance()->config->set('addressbook_name_listing', 2);
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('Last First M.', $result);
\rcube::get_instance()->config->set('addressbook_name_listing', 1);
$result = \rcube_addressbook::compose_list_name($contact);
$this->assertSame('First M. Last', $result);
*/
}
}
|