1+ <?php
2+
3+ declare (strict_types=1 );
4+ /**
5+ * @copyright Copyright (c) 2024 Abdrii Ilkiv <ailkiv@users.noreply.github.com>
6+ *
7+ * @author Abdrii Ilkiv <ailkiv@users.noreply.github.com>
8+ *
9+ * @license AGPL-3.0-or-later
10+ *
11+ * This program is free software: you can redistribute it and/or modify
12+ * it under the terms of the GNU Affero General Public License as
13+ * published by the Free Software Foundation, either version 3 of the
14+ * License, or (at your option) any later version.
15+ *
16+ * This program is distributed in the hope that it will be useful,
17+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+ * GNU Affero General Public License for more details.
20+ *
21+ * You should have received a copy of the GNU Affero General Public License
22+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23+ *
24+ */
25+ namespace OCA \Forms \Tests \Unit \Db ;
26+
27+ use OCA \Forms \Db \SubmissionMapper ;
28+ use OCA \Forms \Db \Form ;
29+
30+ use Test \TestCase ;
31+
32+ class SubmissionMapperTest extends TestCase {
33+
34+ private SubmissionMapper $ mockSubmissionMapper ;
35+
36+
37+ public function setUp (): void {
38+ parent ::setUp ();
39+
40+ $ this ->mockSubmissionMapper = $ this ->getMockBuilder (SubmissionMapper::class)
41+ ->disableOriginalConstructor ()
42+ ->setMethods (['countSubmissionsWithFilters ' ])
43+ ->getMock ();
44+ }
45+
46+ /**
47+ * @dataProvider dataHasMultipleFormSubmissionsByUser
48+ */
49+ public function testHasMultipleFormSubmissionsByUser (int $ numberOfSubmissions , bool $ expected ) {
50+ $ this ->mockSubmissionMapper ->expects ($ this ->once ())
51+ ->method ('countSubmissionsWithFilters ' )
52+ ->will ($ this ->returnValue ($ numberOfSubmissions ));
53+
54+ $ form = new Form ();
55+ $ form ->setId (1 );
56+
57+ $ this ->assertEquals ($ expected , $ this ->mockSubmissionMapper ->hasMultipleFormSubmissionsByUser ($ form , 'user1 ' ));
58+ }
59+
60+ public function dataHasMultipleFormSubmissionsByUser () {
61+ return [
62+ [
63+ 'numberOfSubmissions ' => 0 ,
64+ 'expected ' => false ,
65+ ],
66+ [
67+ 'numberOfSubmissions ' => 1 ,
68+ 'expected ' => false ,
69+ ],
70+ [
71+ 'numberOfSubmissions ' => 2 ,
72+ 'expected ' => true ,
73+ ],
74+ [
75+ 'numberOfSubmissions ' => 3 ,
76+ 'expected ' => true ,
77+ ],
78+ ];
79+ }
80+
81+ /**
82+ * @dataProvider dataHasFormSubmissionsByUser
83+ */
84+ public function testHasFormSubmissionsByUser (int $ numberOfSubmissions , bool $ expected ) {
85+ $ this ->mockSubmissionMapper ->expects ($ this ->once ())
86+ ->method ('countSubmissionsWithFilters ' )
87+ ->will ($ this ->returnValue ($ numberOfSubmissions ));
88+
89+ $ form = new Form ();
90+ $ form ->setId (1 );
91+
92+ $ this ->assertEquals ($ expected , $ this ->mockSubmissionMapper ->hasFormSubmissionsByUser ($ form , 'user1 ' ));
93+ }
94+
95+ public function dataHasFormSubmissionsByUser () {
96+ return [
97+ [
98+ 'numberOfSubmissions ' => 0 ,
99+ 'expected ' => false ,
100+ ],
101+ [
102+ 'numberOfSubmissions ' => 1 ,
103+ 'expected ' => true ,
104+ ],
105+ [
106+ 'numberOfSubmissions ' => 2 ,
107+ 'expected ' => true ,
108+ ],
109+ ];
110+ }
111+
112+ /**
113+ * @dataProvider dataCountSubmissions
114+ */
115+ public function testCountSubmissions (int $ numberOfSubmissions , int $ expected ) {
116+ $ this ->mockSubmissionMapper ->expects ($ this ->once ())
117+ ->method ('countSubmissionsWithFilters ' )
118+ ->will ($ this ->returnValue ($ numberOfSubmissions ));
119+
120+ $ this ->assertEquals ($ expected , $ this ->mockSubmissionMapper ->countSubmissions (1 ));
121+ }
122+
123+ public function dataCountSubmissions () {
124+ return [
125+ [
126+ 'numberOfSubmissions ' => 0 ,
127+ 'expected ' => 0 ,
128+ ],
129+ [
130+ 'numberOfSubmissions ' => 1 ,
131+ 'expected ' => 1 ,
132+ ],
133+ [
134+ 'numberOfSubmissions ' => 20 ,
135+ 'expected ' => 20 ,
136+ ],
137+ ];
138+ }
139+ }
0 commit comments