1<?php
2/**
3 * Copyright 2014-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @category   Horde
9 * @copyright  2014-2016 Horde LLC
10 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @package    Imap_Client
12 * @subpackage UnitTests
13 */
14
15/**
16 * Tests for the Horde_Imap_Client_Base_Mailbox object.
17 *
18 * @author     Michael Slusarz <slusarz@horde.org>
19 * @category   Horde
20 * @copyright  2014-2016 Horde LLC
21 * @ignore
22 * @license    http://www.horde.org/licenses/lgpl21 LGPL 2.1
23 * @package    Imap_Client
24 * @subpackage UnitTests
25 */
26class Horde_Imap_Client_Base_MailboxTest extends PHPUnit_Framework_TestCase
27{
28    private $ob;
29
30    public function setUp()
31    {
32        $this->ob = new Horde_Imap_Client_Base_Mailbox();
33    }
34
35    public function testInitialStatus()
36    {
37        $this->assertInstanceOf(
38            'Horde_Imap_Client_Ids_Map',
39            $this->ob->map
40        );
41    }
42
43    /**
44     * @dataProvider basicIntegerStatusPropertiesProvider
45     */
46    public function testBasicIntegerStatusProperties($property)
47    {
48        $this->assertNull(
49            $this->ob->getStatus($property)
50        );
51
52        $this->ob->setStatus($property, 1);
53
54        $this->assertSame(
55            1,
56            $this->ob->getStatus($property)
57        );
58
59        $this->ob->setStatus($property, "1");
60
61        $this->assertSame(
62            1,
63            $this->ob->getStatus($property)
64        );
65    }
66
67    public function basicIntegerStatusPropertiesProvider()
68    {
69        return array(
70            array(Horde_Imap_Client::STATUS_HIGHESTMODSEQ),
71            array(Horde_Imap_Client::STATUS_MESSAGES),
72            array(Horde_Imap_Client::STATUS_UIDNEXT),
73            array(Horde_Imap_Client::STATUS_UIDVALIDITY)
74        );
75    }
76
77    /**
78     * @dataProvider defaultSyncPropertiesProvider
79     */
80    public function testDefaultSyncProperties($property)
81    {
82        $this->assertInternalType('array', $this->ob->getStatus($property));
83        $this->assertEmpty($this->ob->getStatus($property));
84    }
85
86    public function defaultSyncPropertiesProvider()
87    {
88        return array(
89            array(Horde_Imap_Client::STATUS_SYNCFLAGUIDS),
90            array(Horde_Imap_Client::STATUS_SYNCVANISHED)
91        );
92    }
93
94    public function testFirstUnseen()
95    {
96        $this->assertFalse(
97            $this->ob->getStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN)
98        );
99
100        $this->ob->setStatus(Horde_Imap_Client::STATUS_MESSAGES, 1);
101
102        $this->assertNull(
103            $this->ob->getStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN)
104        );
105
106        $this->ob->setStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN, 1);
107
108        $this->assertSame(
109            1,
110            $this->ob->getStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN)
111        );
112
113        $this->ob->setStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN, "1");
114
115        $this->assertSame(
116            1,
117            $this->ob->getStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN)
118        );
119    }
120
121    public function testDefaultPermFlags()
122    {
123        $this->assertTrue(
124            in_array('\\*', $this->ob->getStatus(Horde_Imap_Client::STATUS_PERMFLAGS))
125        );
126    }
127
128    public function testUnseen()
129    {
130        $this->assertEquals(
131            0,
132            $this->ob->getStatus(Horde_Imap_Client::STATUS_UNSEEN)
133        );
134
135        $this->ob->setStatus(Horde_Imap_Client::STATUS_MESSAGES, 1);
136
137        $this->assertNull(
138            $this->ob->getStatus(Horde_Imap_Client::STATUS_FIRSTUNSEEN)
139        );
140
141        $this->ob->setStatus(Horde_Imap_Client::STATUS_UNSEEN, 1);
142
143        $this->assertSame(
144            1,
145            $this->ob->getStatus(Horde_Imap_Client::STATUS_UNSEEN)
146        );
147
148        $this->ob->setStatus(Horde_Imap_Client::STATUS_UNSEEN, "1");
149
150        $this->assertSame(
151            1,
152            $this->ob->getStatus(Horde_Imap_Client::STATUS_UNSEEN)
153        );
154    }
155
156    public function testStatusRecent()
157    {
158        $this->ob->setStatus(Horde_Imap_Client::STATUS_RECENT, 1);
159        $this->ob->setStatus(Horde_Imap_Client::STATUS_RECENT, 1);
160        $this->ob->setStatus(Horde_Imap_Client::STATUS_RECENT, 1);
161
162        $this->assertEquals(
163            3,
164            $this->ob->getStatus(Horde_Imap_Client::STATUS_RECENT_TOTAL)
165        );
166
167        $this->ob->setStatus(Horde_Imap_Client::STATUS_RECENT, "1");
168
169        $this->assertEquals(
170            4,
171            $this->ob->getStatus(Horde_Imap_Client::STATUS_RECENT_TOTAL)
172        );
173    }
174
175    public function testSyncModseqIsOnlySetOnce()
176    {
177        $this->ob->setStatus(Horde_Imap_Client::STATUS_SYNCMODSEQ, "1");
178        $this->ob->setStatus(Horde_Imap_Client::STATUS_SYNCMODSEQ, 2);
179
180        $this->assertSame(
181            1,
182            $this->ob->getStatus(Horde_Imap_Client::STATUS_SYNCMODSEQ)
183        );
184    }
185
186    /**
187     * @dataProvider statusEntriesAreAdditiveProvider
188     */
189    public function testStatusEntriesAreAdditive($val)
190    {
191        $this->ob->setStatus($val, array(1));
192        $this->ob->setStatus($val, array(2));
193
194        $this->assertEquals(
195            array(1, 2),
196            $this->ob->getStatus($val)
197        );
198    }
199
200    public function statusEntriesAreAdditiveProvider()
201    {
202        return array(
203            array(Horde_Imap_Client::STATUS_SYNCFLAGUIDS),
204            array(Horde_Imap_Client::STATUS_SYNCVANISHED)
205        );
206    }
207
208    public function testReset()
209    {
210        $this->ob->map->update((array(1 => 2)));
211        $this->ob->setStatus(Horde_Imap_Client::STATUS_SYNCMODSEQ, 1);
212        $this->ob->setStatus(Horde_Imap_Client::STATUS_RECENT_TOTAL, 1);
213
214        $this->ob->reset();
215
216        $this->assertEquals(
217            0,
218            count($this->ob->map)
219        );
220        $this->assertEquals(
221            1,
222            $this->ob->getStatus(Horde_Imap_Client::STATUS_SYNCMODSEQ)
223        );
224        $this->assertEquals(
225            0,
226            $this->ob->getStatus(Horde_Imap_Client::STATUS_RECENT_TOTAL)
227        );
228    }
229
230}
231