]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/PaymentType.php
Remove 'svn' lines
[galette.git] / tests / Galette / Entity / tests / units / PaymentType.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Payment type 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-15
35 */
36
37 namespace Galette\Entity\test\units;
38
39 use PHPUnit\Framework\TestCase;
40
41 /**
42 * Payment type tests
43 *
44 * @category Entity
45 * @name PaymentType
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-15
52 */
53 class PaymentType extends TestCase
54 {
55 private \Galette\Core\Db $zdb;
56 private \Galette\Core\Preferences $preferences;
57 private \Galette\Core\Login $login;
58 private array $remove = [];
59 private \Galette\Core\I18n $i18n;
60
61 /**
62 * Set up tests
63 *
64 * @return void
65 */
66 public function setUp(): void
67 {
68 $this->zdb = new \Galette\Core\Db();
69 $this->preferences = new \Galette\Core\Preferences($this->zdb);
70 $this->i18n = new \Galette\Core\I18n(
71 \Galette\Core\I18n::DEFAULT_LANG
72 );
73 $this->login = new \Galette\Core\Login($this->zdb, $this->i18n);
74
75 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
76 $res = $types->installInit(false);
77 $this->assertTrue($res);
78 }
79
80 /**
81 * Tear down tests
82 *
83 * @return void
84 */
85 public function tearDown(): void
86 {
87 if (TYPE_DB === 'mysql') {
88 $this->assertSame([], $this->zdb->getWarnings());
89 }
90 $this->deletePaymentType();
91 }
92
93 /**
94 * Delete payment type
95 *
96 * @return void
97 */
98 private function deletePaymentType()
99 {
100 if (is_array($this->remove) && count($this->remove) > 0) {
101 $delete = $this->zdb->delete(\Galette\Entity\PaymentType::TABLE);
102 $delete->where->in(\Galette\Entity\PaymentType::PK, $this->remove);
103 $this->zdb->execute($delete);
104 }
105
106 //Clean logs
107 $this->zdb->db->query(
108 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
109 \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
110 );
111 }
112
113 /**
114 * Test payment type
115 *
116 * @return void
117 */
118 public function testPaymentType()
119 {
120 global $i18n; // globals :(
121 $i18n = $this->i18n;
122
123 $type = new \Galette\Entity\PaymentType($this->zdb);
124
125 $type->name = 'Test payment type';
126 $this->assertTrue($type->store());
127
128 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
129 $select->where(
130 array(
131 'text_orig' => 'Test payment type'
132 )
133 );
134 $results = $this->zdb->execute($select);
135 $result = (array)$results->current();
136
137 $this->assertSame('Test payment type', $result['text_orig']);
138
139 $id = $type->id;
140 $this->remove[] = $id;
141
142 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
143 $type->name = 'Changed test payment type';
144 $this->assertTrue($type->store());
145
146 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
147 $this->assertSame('Changed test payment type', $type->getName());
148
149 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
150 $select->where(
151 array(
152 'text_orig' => 'Changed test payment type'
153 )
154 );
155 $results = $this->zdb->execute($select);
156 $this->assertSame(count($this->i18n->getArrayList()), count($results));
157
158 $type = new \Galette\Entity\PaymentType($this->zdb, \Galette\Entity\PaymentType::CASH);
159 $this->expectException(\RuntimeException::class);
160 $this->expectExceptionMessage('You cannot delete system payment types!');
161 $type->remove();
162
163 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
164 $this->assertTrue($type->remove());
165
166 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
167 $select->where(
168 array(
169 'text_orig' => 'Test payment type'
170 )
171 );
172 $results = $this->zdb->execute($select);
173 $this->assertSame(0, $results->count());
174 }
175 }