3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
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\Entity\test\units
;
39 use PHPUnit\Framework\TestCase
;
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 PaymentType
extends TestCase
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;
66 public function setUp(): void
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
73 $this->login
= new \Galette\Core\
Login($this->zdb
, $this->i18n
);
75 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
76 $res = $types->installInit(false);
77 $this->assertTrue($res);
85 public function tearDown(): void
87 if (TYPE_DB
=== 'mysql') {
88 $this->assertSame([], $this->zdb
->getWarnings());
90 $this->deletePaymentType();
98 private function deletePaymentType()
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);
107 $this->zdb
->db
->query(
108 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
109 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
118 public function testPaymentType()
120 global $i18n; // globals :(
123 $type = new \Galette\Entity\
PaymentType($this->zdb
);
125 $type->name
= 'Test payment type';
126 $this->assertTrue($type->store());
128 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
131 'text_orig' => 'Test payment type'
134 $results = $this->zdb
->execute($select);
135 $result = (array)$results->current();
137 $this->assertSame('Test payment type', $result['text_orig']);
140 $this->remove
[] = $id;
142 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
143 $type->name
= 'Changed test payment type';
144 $this->assertTrue($type->store());
146 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
147 $this->assertSame('Changed test payment type', $type->getName());
149 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
152 'text_orig' => 'Changed test payment type'
155 $results = $this->zdb
->execute($select);
156 $this->assertSame(count($this->i18n
->getArrayList()), count($results));
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!');
163 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
164 $this->assertTrue($type->remove());
166 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
169 'text_orig' => 'Test payment type'
172 $results = $this->zdb
->execute($select);
173 $this->assertSame(0, $results->count());