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\Entity\test\units
;
24 use PHPUnit\Framework\TestCase
;
29 * @author Johan Cwiklinski <johan@x-tnd.be>
31 class PaymentType
extends TestCase
33 private \Galette\Core\Db
$zdb;
34 private \Galette\Core\Preferences
$preferences;
35 private \Galette\Core\Login
$login;
36 private array $remove = [];
37 private \Galette\Core\I18n
$i18n;
44 public function setUp(): void
46 $this->zdb
= new \Galette\Core\
Db();
47 $this->preferences
= new \Galette\Core\
Preferences($this->zdb
);
48 $this->i18n
= new \Galette\Core\
I18n(
49 \Galette\Core\I18n
::DEFAULT_LANG
51 $this->login
= new \Galette\Core\
Login($this->zdb
, $this->i18n
);
53 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
54 $res = $types->installInit(false);
55 $this->assertTrue($res);
63 public function tearDown(): void
65 if (TYPE_DB
=== 'mysql') {
66 $this->assertSame([], $this->zdb
->getWarnings());
68 $this->deletePaymentType();
76 private function deletePaymentType(): void
78 if (is_array($this->remove
) && count($this->remove
) > 0) {
79 $delete = $this->zdb
->delete(\Galette\Entity\PaymentType
::TABLE
);
80 $delete->where
->in(\Galette\Entity\PaymentType
::PK
, $this->remove
);
81 $this->zdb
->execute($delete);
85 $this->zdb
->db
->query(
86 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
87 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
96 public function testPaymentType(): void
98 global $i18n; // globals :(
101 $type = new \Galette\Entity\
PaymentType($this->zdb
);
103 $type->name
= 'Test payment type';
104 $this->assertTrue($type->store());
106 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
109 'text_orig' => 'Test payment type'
112 $results = $this->zdb
->execute($select);
113 $result = (array)$results->current();
115 $this->assertSame('Test payment type', $result['text_orig']);
118 $this->remove
[] = $id;
120 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
121 $type->name
= 'Changed test payment type';
122 $this->assertTrue($type->store());
124 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
125 $this->assertSame('Changed test payment type', $type->getName());
127 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
130 'text_orig' => 'Changed test payment type'
133 $results = $this->zdb
->execute($select);
134 $this->assertSame(count($this->i18n
->getArrayList()), count($results));
136 $type = new \Galette\Entity\
PaymentType($this->zdb
, \Galette\Entity\PaymentType
::CASH
);
137 $this->expectException(\RuntimeException
::class);
138 $this->expectExceptionMessage('You cannot delete system payment types!');
141 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
142 $this->assertTrue($type->remove());
144 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
147 'text_orig' => 'Test payment type'
150 $results = $this->zdb
->execute($select);
151 $this->assertSame(0, $results->count());