]> git.agnieray.net Git - galette.git/blob - tests/Galette/Repository/tests/units/PaymentTypes.php
Remove 'svn' lines
[galette.git] / tests / Galette / Repository / tests / units / PaymentTypes.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Payment types 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 * @link http://galette.tuxfamily.org
34 * @since 2019-12-17
35 */
36
37 namespace Galette\Repository\test\units;
38
39 use Galette\GaletteTestCase;
40
41 /**
42 * Payment types repository tests
43 *
44 * @category Repository
45 * @name PaymentTypes
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
51 * @since 2019-12-17
52 */
53 class PaymentTypes extends GaletteTestCase
54 {
55 private array $remove = [];
56
57 /**
58 * Set up tests
59 *
60 * @return void
61 */
62 public function setUp(): void
63 {
64 parent::setUp();
65
66 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
67 $res = $types->installInit(false);
68 $this->assertTrue($res);
69 }
70
71 /**
72 * Tear down tests
73 *
74 * @return void
75 */
76 public function tearDown(): void
77 {
78 parent::tearDown();
79 $this->deletePaymentType();
80 }
81
82 /**
83 * Delete payment type
84 *
85 * @return void
86 */
87 private function deletePaymentType()
88 {
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);
93 }
94
95 //Clean logs
96 $this->zdb->db->query(
97 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
98 \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
99 );
100 }
101
102 /**
103 * Test getList
104 *
105 * @return void
106 */
107 public function testGetList()
108 {
109 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
110
111 $list = $types->getList();
112 $this->assertCount(6, $list);
113
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');
120 }
121
122 //reinstall payment types
123 $types->installInit();
124
125 $list = $types->getList();
126 $this->assertCount(6, $list);
127
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(
134 6,
135 $result->last_value,
136 6,
137 'Incorrect payment types sequence ' . $result->last_value
138 );
139 }
140 }
141 }