commit | author | age
|
5f8ada
|
1 |
<?php |
AM |
2 |
|
|
3 |
/** |
|
4 |
* Test class to test rcube_result_index class |
|
5 |
* |
|
6 |
* @package Tests |
|
7 |
*/ |
|
8 |
class Framework_ResultIndex extends PHPUnit_Framework_TestCase |
|
9 |
{ |
|
10 |
|
|
11 |
/** |
|
12 |
* Class constructor |
|
13 |
*/ |
|
14 |
function test_class() |
|
15 |
{ |
|
16 |
$object = new rcube_result_index; |
|
17 |
|
|
18 |
$this->assertInstanceOf('rcube_result_index', $object, "Class constructor"); |
|
19 |
} |
3b1d41
|
20 |
|
AM |
21 |
/** |
|
22 |
* thread parser test |
|
23 |
*/ |
|
24 |
function test_parse() |
|
25 |
{ |
|
26 |
$text = "* SORT 2001 2002 2035 2036 2037 2038 2044 2046 2043 2045 2226 2225 2224 2223"; |
|
27 |
$object = new rcube_result_index('INBOX', $text); |
|
28 |
|
|
29 |
$this->assertSame(false, $object->is_empty(), "Object is empty"); |
|
30 |
$this->assertSame(false, $object->is_error(), "Object is error"); |
|
31 |
$this->assertSame(2226, $object->max(), "Max message UID"); |
|
32 |
$this->assertSame(2001, $object->min(), "Min message UID"); |
|
33 |
$this->assertSame(14, $object->count_messages(), "Messages count"); |
|
34 |
$this->assertSame(14, $object->count(), "Messages count"); |
|
35 |
$this->assertSame(1, $object->exists(2002, true), "Message exists"); |
|
36 |
$this->assertSame(true, $object->exists(2002), "Message exists (bool)"); |
|
37 |
$this->assertSame(2001, $object->get_element('FIRST'), "Get first element"); |
|
38 |
$this->assertSame(2223, $object->get_element('LAST'), "Get last element"); |
|
39 |
$this->assertSame(2035, (int) $object->get_element(2), "Get specified element"); |
|
40 |
$this->assertSame("2001:2002,2035:2038,2043:2046,2223:2226", $object->get_compressed(), "Get compressed index"); |
|
41 |
$this->assertSame('INBOX', $object->get_parameters('MAILBOX'), "Get parameter"); |
|
42 |
|
|
43 |
$clone = clone $object; |
|
44 |
$clone->filter(array(2035, 2002)); |
|
45 |
|
|
46 |
$this->assertSame(2, $clone->count(), "Messages count (filtered)"); |
|
47 |
$this->assertSame(2002, $clone->get_element('FIRST'), "Get first element (filtered)"); |
|
48 |
|
|
49 |
$clone = clone $object; |
|
50 |
$clone->revert(); |
|
51 |
|
|
52 |
$this->assertSame(14, $clone->count(), "Messages count (reverted)"); |
|
53 |
$this->assertSame(12, $clone->exists(2002, true), "Message exists (reverted)"); |
|
54 |
$this->assertSame(true, $clone->exists(2002), "Message exists (bool) (reverted)"); |
|
55 |
$this->assertSame(2223, $clone->get_element('FIRST'), "Get first element (reverted)"); |
|
56 |
$this->assertSame(2001, $clone->get_element('LAST'), "Get last element (reverted)"); |
|
57 |
$this->assertSame(2225, (int) $clone->get_element(2), "Get specified element (reverted)"); |
|
58 |
|
|
59 |
$clone = clone $object; |
|
60 |
$clone->slice(2, 3); |
|
61 |
|
|
62 |
$this->assertSame(3, $clone->count(), "Messages count (sliced)"); |
|
63 |
$this->assertSame(2035, $clone->get_element('FIRST'), "Get first element (sliced)"); |
|
64 |
$this->assertSame(2037, $clone->get_element('LAST'), "Get last element (sliced)"); |
|
65 |
} |
|
66 |
|
5f8ada
|
67 |
} |