]> git.agnieray.net Git - galette.git/blob - tests/Galette/Repository/tests/units/PaymentTypes.php
Improve coding standards
[galette.git] / tests / Galette / Repository / tests / units / PaymentTypes.php
1 <?php
2
3 /**
4 * Copyright © 2003-2024 The Galette Team
5 *
6 * This file is part of Galette (https://galette.eu).
7 *
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.
12 *
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.
17 *
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/>.
20 */
21
22 namespace Galette\Repository\test\units;
23
24 use Galette\GaletteTestCase;
25
26 /**
27 * Payment types repository tests
28 *
29 * @author Johan Cwiklinski <johan@x-tnd.be>
30 */
31 class PaymentTypes extends GaletteTestCase
32 {
33 private array $remove = [];
34
35 /**
36 * Set up tests
37 *
38 * @return void
39 */
40 public function setUp(): void
41 {
42 parent::setUp();
43
44 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
45 $res = $types->installInit(false);
46 $this->assertTrue($res);
47 }
48
49 /**
50 * Tear down tests
51 *
52 * @return void
53 */
54 public function tearDown(): void
55 {
56 parent::tearDown();
57 $this->deletePaymentType();
58 }
59
60 /**
61 * Delete payment type
62 *
63 * @return void
64 */
65 private function deletePaymentType(): void
66 {
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);
71 }
72
73 //Clean logs
74 $this->zdb->db->query(
75 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
76 \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
77 );
78 }
79
80 /**
81 * Test getList
82 *
83 * @return void
84 */
85 public function testGetList(): void
86 {
87 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
88
89 $list = $types->getList();
90 $this->assertCount(7, $list);
91
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');
98 }
99
100 //reinstall payment types
101 $types->installInit();
102
103 $list = $types->getList();
104 $this->assertCount(7, $list);
105
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(
112 6,
113 $result->last_value,
114 6,
115 'Incorrect payment types sequence ' . $result->last_value
116 );
117 }
118 }
119 }