File: ResultThread.php

package info (click to toggle)
roundcube 1.6.11%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,868 kB
  • sloc: javascript: 195,588; php: 76,818; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (115 lines) | stat: -rw-r--r-- 4,380 bytes parent folder | download
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
<?php

namespace Roundcube\Tests\Framework;

use PHPUnit\Framework\TestCase;

/**
 * Test class to test rcube_result_thread class
 */
class Framework_ResultThread extends TestCase
{

    /**
     * Class constructor
     */
    function test_class()
    {
        $object = new \rcube_result_thread();

        $this->assertInstanceOf(\rcube_result_thread::class, $object, "Class constructor");
    }

    /**
     * thread parser test
     */
    function test_parse_thread()
    {
        $text   = file_get_contents(__DIR__ . '/../src/imap_thread.txt');
        $object = new \rcube_result_thread('INBOX', $text);

        $this->assertSame(false, $object->is_empty(), "Object is empty");
        $this->assertSame(false, $object->is_error(), "Object is error");
        $this->assertSame(1721, $object->max(), "Max message UID");
        $this->assertSame(1, $object->min(), "Min message UID");
        $this->assertSame(731, $object->count(), "Threads count");
        $this->assertSame(1721, $object->count_messages(), "Messages count");
        $this->assertSame(1691, $object->exists(1720, true), "Message exists");
        $this->assertSame(true, $object->exists(1720), "Message exists (bool)");
        $this->assertSame(1, $object->get_element('FIRST'), "Get first element");
        $this->assertSame(1719, $object->get_element('LAST'), "Get last element");
        $this->assertSame(14, (int) $object->get_element(2), "Get specified element");

        $tree = $object->get_tree();
        $expected = [
            4 => [
                18 => [
                    39 => [
                        100 => []
                    ]
                ]
            ],
            5 => [
                6 => [],
                8 => [
                    11 => [],
                    13 => [
                        15 => []
                    ],
                    465 => []
                ],
                209 => []
            ],
            19 => [
                314 => []
            ]
        ];

        $this->assertSame([], $tree[1]);
        $this->assertSame([], $tree[2]);
        $this->assertSame([], $tree[14]);
        $this->assertSame([], $tree[3]);
        $this->assertSame($expected[4], $tree[4]);
        $this->assertSame($expected[5], $tree[5]);
        $this->assertSame($expected[19], $tree[19]);

        $clone = clone $object;
        $clone->filter([7]);
        $clone = $clone->get_tree();

        $this->assertSame(1, count($clone), "Structure check");
        $this->assertSame(3, count($clone[7]), "Structure check");
        $this->assertSame(0, count($clone[7][12]), "Structure check");
        $this->assertSame(1, count($clone[7][167]), "Structure check");
        $this->assertSame(0, count($clone[7][167][197]), "Structure check");
        $this->assertSame(2, count($clone[7][458]), "Structure check");
        $this->assertSame(1, count($clone[7][458][460]), "Structure check");
        $this->assertSame(0, count($clone[7][458][460][463]), "Structure check");
        $this->assertSame(1, count($clone[7][458][464]), "Structure check");
        $this->assertSame(0, count($clone[7][458][464][471]), "Structure check");

        $object->filter([784]);
        $this->assertSame(118, $object->count_messages(), "Messages filter");
        $this->assertSame(1, $object->count(), "Messages filter (count)");
    }

    /**
     * thread parser test (empty result)
     */
    function test_parse_empty()
    {
        $object = new \rcube_result_thread('INBOX', "* THREAD");

        $this->assertSame(true, $object->is_empty(), "Object is empty");
        $this->assertSame(false, $object->is_error(), "Object is error");
        $this->assertSame(null, $object->max(), "Max message UID");
        $this->assertSame(null, $object->min(), "Min message UID");
        $this->assertSame(0, $object->count(), "Threads count");
        $this->assertSame(0, $object->count_messages(), "Messages count");
        $this->assertSame(false, $object->exists(1720, true), "Message exists");
        $this->assertSame(false, $object->exists(1720), "Message exists (bool)");
        $this->assertSame(null, $object->get_element('FIRST'), "Get first element");
        $this->assertSame(null, $object->get_element('LAST'), "Get last element");
        $this->assertSame(null, $object->get_element(2), "Get specified element");
    }
}