3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Payment types 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
33 * @link http://galette.tuxfamily.org
37 namespace Galette\Repository\test\units
;
39 use Galette\GaletteTestCase
;
42 * Payment types repository tests
44 * @category Repository
46 * @package GaletteTests
47 * @author Johan Cwiklinski <johan@x-tnd.be>
48 * @copyright 2019-2023 The Galette Team
49 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
50 * @link http://galette.tuxfamily.org
53 class PaymentTypes
extends GaletteTestCase
55 private array $remove = [];
62 public function setUp(): void
66 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
67 $res = $types->installInit(false);
68 $this->assertTrue($res);
76 public function tearDown(): void
79 $this->deletePaymentType();
87 private function deletePaymentType()
89 if (is_array($this->remove
) && count($this->remove
) > 0) {
90 $delete = $this->zdb
->delete(\Galette\Entity\PaymentType
::TABLE
);
91 $delete->where
->in(\Galette\Entity\PaymentTypes
::PK
, $this->remove
);
92 $this->zdb
->execute($delete);
96 $this->zdb
->db
->query(
97 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
98 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
107 public function testGetList()
109 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
111 $list = $types->getList();
112 $this->assertCount(6, $list);
114 if ($this->zdb
->isPostgres()) {
115 $select = $this->zdb
->select(\Galette\Entity\PaymentType
::TABLE
. '_id_seq');
116 $select->columns(['last_value']);
117 $results = $this->zdb
->execute($select);
118 $result = $results->current();
119 $this->assertGreaterThanOrEqual(6, $result->last_value
, 'Incorrect payments types sequence');
122 //reinstall payment types
123 $types->installInit();
125 $list = $types->getList();
126 $this->assertCount(6, $list);
128 if ($this->zdb
->isPostgres()) {
129 $select = $this->zdb
->select(\Galette\Entity\PaymentType
::TABLE
. '_id_seq');
130 $select->columns(['last_value']);
131 $results = $this->zdb
->execute($select);
132 $result = $results->current();
133 $this->assertGreaterThanOrEqual(
137 'Incorrect payment types sequence ' . $result->last_value