4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
22 namespace Galette\Repository\test\units
;
24 use Galette\GaletteTestCase
;
27 * Payment types repository tests
29 * @author Johan Cwiklinski <johan@x-tnd.be>
31 class PaymentTypes
extends GaletteTestCase
33 private array $remove = [];
40 public function setUp(): void
44 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
45 $res = $types->installInit(false);
46 $this->assertTrue($res);
54 public function tearDown(): void
57 $this->deletePaymentType();
65 private function deletePaymentType(): void
67 if (is_array($this->remove
) && count($this->remove
) > 0) {
68 $delete = $this->zdb
->delete(\Galette\Entity\PaymentType
::TABLE
);
69 $delete->where
->in(\Galette\Entity\PaymentTypes
::PK
, $this->remove
);
70 $this->zdb
->execute($delete);
74 $this->zdb
->db
->query(
75 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
76 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
85 public function testGetList(): void
87 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
89 $list = $types->getList();
90 $this->assertCount(7, $list);
92 if ($this->zdb
->isPostgres()) {
93 $select = $this->zdb
->select(\Galette\Entity\PaymentType
::TABLE
. '_id_seq');
94 $select->columns(['last_value']);
95 $results = $this->zdb
->execute($select);
96 $result = $results->current();
97 $this->assertGreaterThanOrEqual(6, $result->last_value
, 'Incorrect payments types sequence');
100 //reinstall payment types
101 $types->installInit();
103 $list = $types->getList();
104 $this->assertCount(7, $list);
106 if ($this->zdb
->isPostgres()) {
107 $select = $this->zdb
->select(\Galette\Entity\PaymentType
::TABLE
. '_id_seq');
108 $select->columns(['last_value']);
109 $results = $this->zdb
->execute($select);
110 $result = $results->current();
111 $this->assertGreaterThanOrEqual(
115 'Incorrect payment types sequence ' . $result->last_value