]> git.agnieray.net Git - galette.git/blob - tests/Galette/Repository/tests/units/PdfModels.php
Migrate to phpunit; closes #1674
[galette.git] / tests / Galette / Repository / tests / units / PdfModels.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * PDF models repository tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2019-2023 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Repository
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2019-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2019-12-17
36 */
37
38 namespace Galette\Repository\test\units;
39
40 use Galette\GaletteTestCase;
41
42 /**
43 * PDF models repository tests
44 *
45 * @category Repository
46 * @name PdfModels
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2019-2023 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2019-12-17
53 */
54 class PdfModels extends GaletteTestCase
55 {
56 private array $remove = [];
57
58 /**
59 * Set up tests
60 *
61 * @return void
62 */
63 public function setUp(): void
64 {
65 parent::setUp();
66
67 $models = new \Galette\Repository\PdfModels($this->zdb, $this->preferences, $this->login);
68 $res = $models->installInit(false);
69 $this->assertTrue($res);
70 }
71
72 /**
73 * Tear down tests
74 *
75 * @return void
76 */
77 public function tearDown(): void
78 {
79 parent::tearDown();
80 $this->deletePdfModels();
81 }
82
83 /**
84 * Delete pdf models
85 *
86 * @return void
87 */
88 private function deletePdfModels()
89 {
90 if (is_array($this->remove) && count($this->remove) > 0) {
91 $delete = $this->zdb->delete(\Galette\Entity\PdfModel::TABLE);
92 $delete->where->in(\Galette\Repository\PdfModel::PK, $this->remove);
93 $this->zdb->execute($delete);
94 }
95
96 //Clean logs
97 $this->zdb->db->query(
98 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
99 \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
100 );
101 }
102
103 /**
104 * Test getList
105 *
106 * @return void
107 */
108 public function testGetList()
109 {
110 global $container, $zdb;
111 $zdb = $this->zdb; //globals '(
112 $container = new class {
113 /**
114 * Get (only router)
115 *
116 * @param string $name Param name
117 *
118 * @return mixed
119 */
120 public function get($name)
121 {
122 $router = new class {
123 /**
124 * Get path ('')
125 *
126 * @param sttring $name Route name
127 *
128 * @return string
129 */
130 public function urlFor($name)
131 {
132 return '';
133 }
134 };
135 return $router;
136 }
137 };
138 $_SERVER['HTTP_HOST'] = '';
139
140 $models = new \Galette\Repository\PdfModels($this->zdb, $this->preferences, $this->login);
141
142 //install pdf models
143 $list = $models->getList();
144 $this->assertCount(4, $list);
145
146 if ($this->zdb->isPostgres()) {
147 $select = $this->zdb->select(\Galette\Entity\PdfModel::TABLE . '_id_seq');
148 $select->columns(['last_value']);
149 $results = $this->zdb->execute($select);
150 $result = $results->current();
151 $this->assertGreaterThanOrEqual(
152 4,
153 $result->last_value,
154 'Incorrect PDF models sequence: ' . $result->last_value
155 );
156 }
157
158 //reinstall pdf models
159 $models->installInit();
160
161 $list = $models->getList();
162 $this->assertCount(4, $list);
163
164 if ($this->zdb->isPostgres()) {
165 $select = $this->zdb->select(\Galette\Entity\PdfModel::TABLE . '_id_seq');
166 $select->columns(['last_value']);
167 $results = $this->zdb->execute($select);
168 $result = $results->current();
169 $this->assertGreaterThanOrEqual(
170 4,
171 $result->last_value,
172 'Incorrect PDF models sequence ' . $result->last_value
173 );
174 }
175 }
176 }