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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?php
namespace OCA\OJSXC\Db;
use OCA\OJSXC\Utility\MapperTestUtility;
use OCP\AppFramework\Db\DoesNotExistException;
/**
* @group DB
*/
class StanzaMapperTest extends MapperTestUtility
{
/**
* @var StanzaMapper
*/
protected $mapper;
protected function setUp()
{
$this->entityName = 'OCA\OJSXC\Db\Stanza';
$this->mapperName = 'StanzaMapper';
parent::setUp();
}
public function insertProvider()
{
return [
[
'john',
'thomas',
'abcd'
]
];
}
/**
* @dataProvider insertProvider
*/
public function testInsert($from, $to, $data)
{
$stanza = new Stanza();
$stanza->setFrom($from);
$stanza->setTo($to);
$stanza->setStanza($data);
$this->assertEquals($stanza->getFrom(), $from);
$this->assertEquals($stanza->getTo(), $to);
$this->assertEquals($stanza->getStanza(), $data);
$this->mapper->insert($stanza);
$result = $this->fetchAll();
$this->assertCount(1, $result);
$this->assertEquals($stanza->getFrom(), $result[0]->getFrom());
$this->assertEquals($stanza->getTo(), $result[0]->getTo());
$this->assertEquals($stanza->getStanza(), $result[0]->getStanza());
}
/**
* @expectedException \OCP\AppFramework\Db\DoesNotExistException
*/
public function testFindByToNotFound()
{
$this->mapper->findByTo('test');
}
/**
* @expectedException \OCP\AppFramework\Db\DoesNotExistException
*/
public function testFindByToNotFound2()
{
$stanza = new Stanza();
$stanza->setFrom('john@localhost');
$stanza->setTo('john@localhost');
$stanza->setStanza('abcd');
$this->mapper->insert($stanza);
$this->mapper->findByTo('test');
}
public function testFindByToFound()
{
$stanza1 = new Stanza();
$stanza1->setFrom('jan');
$stanza1->setTo('john');
$stanza1->setStanza('abcd1');
$this->mapper->insert($stanza1);
$stanza2 = new Stanza();
$stanza2->setFrom('thomas');
$stanza2->setTo('jan');
$stanza2->setStanza('abcd2');
$this->mapper->insert($stanza2);
// check if two elements are inserted
$result = $this->fetchAll();
$this->assertCount(2, $result);
// check findByTo
$result = $this->mapper->findByTo('john');
$this->assertCount(1, $result);
$this->assertEquals($stanza1->getStanza(), $result[0]->getStanza());
// check if element is deleted
$result = $this->fetchAll();
$this->assertCount(1, $result);
$this->assertEquals($stanza2->getFrom(), $result[0]->getFrom());
$this->assertEquals($stanza2->getTo(), $result[0]->getTo());
$this->assertEquals($stanza2->getStanza(), $result[0]->getStanza());
}
public function testDeleteByTo()
{
$stanza1 = new Stanza();
$stanza1->setFrom('jan');
$stanza1->setTo('john');
$stanza1->setStanza('abcd1');
$this->mapper->insert($stanza1);
$stanza2 = new Stanza();
$stanza2->setFrom('thomas');
$stanza2->setTo('jan');
$stanza2->setStanza('abcd2');
$this->mapper->insert($stanza2);
// check if two elements are inserted
$result = $this->fetchAllAsArray();
$this->assertArrayDbResultsEqual([
['from' => 'jan', 'to' => 'john', 'stanza' => 'abcd1'],
['from' => 'thomas', 'to' => 'jan', 'stanza' => 'abcd2']
], $result, ['from', 'to', 'stanza']);
$this->mapper->deleteByTo('jan');
$result = $this->fetchAllAsArray();
$this->assertArrayDbResultsEqual([
['from' => 'jan', 'to' => 'john', 'stanza' => 'abcd1']
], $result, ['from', 'to', 'stanza']);
}
}
|