1 | <?php |
||
26 | class MailAccountMapperTest extends \PHPUnit_Framework_TestCase { |
||
27 | |||
28 | /** |
||
29 | * @var MailAccountMapper |
||
30 | */ |
||
31 | private $mapper; |
||
32 | |||
33 | /** |
||
34 | * @var \OC\DB\Connection |
||
35 | */ |
||
36 | private $db; |
||
37 | |||
38 | /** |
||
39 | * @var MailAccount |
||
40 | */ |
||
41 | private $account; |
||
42 | |||
43 | /** |
||
44 | * Initialize Mapper |
||
45 | */ |
||
46 | public function setup(){ |
||
47 | $db = \OC::$server->getDatabaseConnection(); |
||
48 | $this->db = new Db($db); |
||
49 | $this->mapper = new MailAccountMapper($this->db); |
||
50 | |||
51 | $this->account = new MailAccount(); |
||
52 | $this->account->setName('Peter Parker'); |
||
53 | $this->account->setInboundHost('mail.marvel.com'); |
||
54 | $this->account->setInboundPort(159); |
||
55 | $this->account->setInboundUser('spiderman'); |
||
56 | $this->account->setInboundPassword('xxxxxxxx'); |
||
57 | $this->account->setInboundSslMode('tls'); |
||
58 | $this->account->setEmail('[email protected]'); |
||
59 | $this->account->setOutboundHost('smtp.marvel.com'); |
||
60 | $this->account->setOutboundPort(458); |
||
61 | $this->account->setOutboundUser('spiderman'); |
||
62 | $this->account->setOutboundPassword('xxxx'); |
||
63 | $this->account->setOutboundSslMode('ssl'); |
||
64 | $this->account->setUserId('user12345'); |
||
65 | } |
||
66 | |||
67 | public function testFind(){ |
||
68 | |||
69 | /** @var MailAccount $b */ |
||
70 | $b = $this->mapper->insert($this->account); |
||
71 | |||
72 | $result = $this->mapper->find($b->getUserId(), $b->getId()); |
||
73 | $this->assertEquals($b->toJson(), $result->toJson()); |
||
74 | |||
75 | $result = $this->mapper->findByUserId($b->getUserId()); |
||
76 | $c = array_filter($result, function($a) use($b){ |
||
77 | /** @var MailAccount $a */ |
||
78 | return $a->getId() === $b->getId(); |
||
79 | }); |
||
80 | $c = array_pop($c); |
||
81 | $this->assertEquals($b->toJson(), $c->toJson()); |
||
82 | } |
||
83 | |||
84 | public function testSave() { |
||
85 | |||
86 | $a = $this->account; |
||
87 | |||
88 | // test insert |
||
89 | $b = $this->mapper->save($a); |
||
90 | $this->assertNotNull($b); |
||
91 | $this->assertNotNull($a->getId()); |
||
92 | $this->assertNotNull($b->getId()); |
||
93 | $this->assertEquals($a->getId(), $b->getId()); |
||
94 | |||
95 | // update the entity |
||
96 | $b->setEmail('[email protected]'); |
||
97 | $c = $this->mapper->save($b); |
||
98 | $this->assertNotNull($c); |
||
99 | $this->assertNotNull($c->getId()); |
||
100 | $this->assertNotNull($b->getId()); |
||
101 | $this->assertEquals($b->getId(), $c->getId()); |
||
102 | } |
||
103 | } |
||
104 |