1 | <?php |
||
26 | class AccountTest extends AbstractTest { |
||
27 | |||
28 | /** |
||
29 | * @dataProvider providesMailBoxNames |
||
30 | * @param $name |
||
31 | */ |
||
32 | public function testCreateAndDelete($name) { |
||
33 | $name = uniqid($name); |
||
34 | $this->createMailBox($name); |
||
35 | $this->assertMailBoxExists($name); |
||
36 | |||
37 | $this->getTestAccount()->deleteMailbox($name); |
||
38 | $this->assertMailBoxNotExists($name); |
||
39 | } |
||
40 | |||
41 | public function providesMailBoxNames() { |
||
42 | return [ |
||
43 | ['boxbox'], |
||
44 | ['box box'], |
||
45 | ['äöü'] |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @dataProvider providesMailBoxNames |
||
51 | * @param $name |
||
52 | */ |
||
53 | public function testListMailBoxes($name) { |
||
54 | $name = uniqid($name); |
||
55 | $this->createMailBox($name); |
||
56 | $mailBoxes = $this->getTestAccount()->getListArray(); |
||
57 | $this->assertInternalType('array', $mailBoxes); |
||
58 | |||
59 | $m = array_filter($mailBoxes['folders'], function($item) use ($name) { |
||
60 | return $item['name'] === $name; |
||
61 | }); |
||
62 | $this->assertTrue(count($m) === 1); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @dataProvider providesMailBoxNames |
||
67 | * @param $name |
||
68 | */ |
||
69 | public function testListMessages($name) { |
||
70 | $name = uniqid($name); |
||
71 | $newMailBox = parent::createMailBox($name); |
||
72 | $count = $newMailBox->getTotalMessages(); |
||
73 | $this->assertEquals(0, $count); |
||
74 | $messages = $newMailBox->getMessages(); |
||
75 | $this->assertInternalType('array', $messages); |
||
76 | $this->assertEquals(0, count($messages)); |
||
77 | $this->createTestMessage($newMailBox); |
||
78 | $count = $newMailBox->getTotalMessages(); |
||
79 | $this->assertEquals(1, $count); |
||
80 | $messages = $newMailBox->getMessages(); |
||
81 | $this->assertInternalType('array', $messages); |
||
82 | $this->assertEquals(1, count($messages)); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @dataProvider providesMailBoxNames |
||
87 | * @param $name |
||
88 | */ |
||
89 | public function testGetChangedMailboxes($name) { |
||
90 | $name = uniqid($name); |
||
91 | $newMailBox = parent::createMailBox($name); |
||
92 | $status = $newMailBox->getStatus(); |
||
93 | $changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([ |
||
94 | $newMailBox->getFolderId() => [ 'uidvalidity' => $status['uidvalidity'], 'uidnext' => $status['uidnext'] ] |
||
95 | ]); |
||
96 | |||
97 | $this->assertEquals(0, count($changedMailBoxes)); |
||
98 | |||
99 | $this->createTestMessage($newMailBox); |
||
100 | |||
101 | $changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([ |
||
102 | $newMailBox->getFolderId() => [ 'uidvalidity' => $status['uidvalidity'], 'uidnext' => $status['uidnext'] ] |
||
103 | ]); |
||
104 | |||
105 | $this->assertEquals(1, count($changedMailBoxes)); |
||
106 | $this->assertEquals(1, count($changedMailBoxes[$newMailBox->getFolderId()]['messages'])); |
||
107 | } |
||
108 | |||
109 | public function testGetChangedMailboxesForNotExisting() { |
||
110 | $changedMailBoxes = $this->getTestAccount()->getChangedMailboxes([ |
||
111 | 'you-dont-know-me' => ['uidvalidity' => 0, 'uidnext' => 0] |
||
112 | ]); |
||
113 | |||
114 | $this->assertEquals(0, count($changedMailBoxes)); |
||
115 | } |
||
116 | } |
||
117 |