3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * PDF models repository tests
10 * Copyright © 2019-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
27 * @category Repository
28 * @package GaletteTests
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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Repository\test\units
;
40 use Galette\GaletteTestCase
;
43 * PDF models repository tests
45 * @category Repository
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
54 class PdfModels
extends GaletteTestCase
56 private array $remove = [];
63 public function setUp(): void
67 $models = new \Galette\Repository\
PdfModels($this->zdb
, $this->preferences
, $this->login
);
68 $res = $models->installInit(false);
69 $this->assertTrue($res);
77 public function tearDown(): void
80 $this->deletePdfModels();
88 private function deletePdfModels()
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);
97 $this->zdb
->db
->query(
98 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
99 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
108 public function testGetList()
110 global $container, $zdb;
111 $zdb = $this->zdb
; //globals '(
112 $container = new class {
116 * @param string $name Param name
120 public function get($name)
122 $router = new class {
126 * @param sttring $name Route name
130 public function urlFor($name)
138 $_SERVER['HTTP_HOST'] = '';
140 $models = new \Galette\Repository\
PdfModels($this->zdb
, $this->preferences
, $this->login
);
143 $list = $models->getList();
144 $this->assertCount(4, $list);
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(
154 'Incorrect PDF models sequence: ' . $result->last_value
158 //reinstall pdf models
159 $models->installInit();
161 $list = $models->getList();
162 $this->assertCount(4, $list);
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(
172 'Incorrect PDF models sequence ' . $result->last_value