1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Kai Schröer <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Kai Schröer <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Polls\Tests\Unit\Db; |
25
|
|
|
|
26
|
|
|
use OCA\Polls\Db\Log; |
27
|
|
|
use OCA\Polls\Db\LogMapper; |
28
|
|
|
use OCA\Polls\Db\Poll; |
29
|
|
|
use OCA\Polls\Db\PollMapper; |
30
|
|
|
use OCA\Polls\Tests\Unit\UnitTestCase; |
31
|
|
|
use OCP\IDBConnection; |
32
|
|
|
use League\FactoryMuffin\Faker\Facade as Faker; |
33
|
|
|
|
34
|
|
|
class LogMapperTest extends UnitTestCase { |
35
|
|
|
|
36
|
|
|
/** @var IDBConnection */ |
37
|
|
|
private $con; |
38
|
|
|
|
39
|
|
|
/** @var LogMapper */ |
40
|
|
|
private $logMapper; |
41
|
|
|
|
42
|
|
|
/** @var PollMapper */ |
43
|
|
|
private $pollMapper; |
44
|
|
|
|
45
|
|
|
/** @var array */ |
46
|
|
|
private $polls = []; |
47
|
|
|
|
48
|
|
|
/** @var array */ |
49
|
|
|
private $logs = []; |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
protected function setUp(): void { |
56
|
|
|
parent::setUp(); |
57
|
|
|
$this->con = \OC::$server->getDatabaseConnection(); |
58
|
|
|
$this->logMapper = new LogMapper($this->con); |
59
|
|
|
$this->pollMapper = new PollMapper($this->con); |
60
|
|
|
|
61
|
|
|
$this->polls = [ |
62
|
|
|
$this->fm->instance('OCA\Polls\Db\Poll') |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
foreach ($this->polls as &$poll) { |
66
|
|
|
$poll = $this->pollMapper->insert($poll); |
67
|
|
|
|
68
|
|
|
for ($count=0; $count < 2; $count++) { |
69
|
|
|
$log = $this->fm->instance('OCA\Polls\Db\Log'); |
70
|
|
|
$log->setPollId($poll->getId()); |
71
|
|
|
array_push($this->logs, $this->logMapper->insert($log)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
unset($poll); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* testFindByPollId |
79
|
|
|
*/ |
80
|
|
|
public function testFindByPollId() { |
81
|
|
|
foreach ($this->polls as $poll) { |
82
|
|
|
$this->assertTrue(count($this->logMapper->findByPollId($poll->getId())) > 0); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* testFindUnprocessed |
88
|
|
|
*/ |
89
|
|
|
public function testFindUnprocessed() { |
90
|
|
|
$this->assertTrue(count($this->logMapper->findUnprocessed()) > 0); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* testFindUnprocessedPolls |
95
|
|
|
*/ |
96
|
|
|
public function testFindUnprocessedPolls() { |
97
|
|
|
$this->assertTrue(count($this->logMapper->findUnprocessedPolls()) > 0); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* testGetLastRecord |
102
|
|
|
*/ |
103
|
|
|
public function testGetLastRecord() { |
104
|
|
|
foreach ($this->polls as $poll) { |
105
|
|
|
$this->assertInstanceOf(Log::class, $this->logMapper->getLastRecord($poll->getId())); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* testUpdate |
111
|
|
|
* includes testFind |
112
|
|
|
*/ |
113
|
|
|
public function testUpdate() { |
114
|
|
|
foreach ($this->logs as &$log) { |
115
|
|
|
$log->setMessageId(Log::MSG_ID_UPDATEPOLL); |
116
|
|
|
$this->assertInstanceOf(Log::class, $this->logMapper->update($log)); |
117
|
|
|
} |
118
|
|
|
unset($log); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* testDelete |
124
|
|
|
*/ |
125
|
|
|
public function testDelete() { |
126
|
|
|
foreach ($this->logs as $log) { |
127
|
|
|
$before = $this->logMapper->find($log->getId()); |
128
|
|
|
$this->assertInstanceOf(Log::class, $this->logMapper->delete($before)); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* tearDown |
134
|
|
|
*/ |
135
|
|
|
public function tearDown(): void { |
136
|
|
|
parent::tearDown(); |
137
|
|
|
foreach ($this->polls as $poll) { |
138
|
|
|
$this->pollMapper->delete($poll); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|