3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2019 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 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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Entity\test\units
;
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2019 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
54 class PaymentType
extends atoum
66 * @param string $testMethod Calling method
70 public function beforeTestMethod($testMethod)
72 $this->zdb
= new \Galette\Core\
Db();
73 $this->preferences
= new \Galette\Core\
Preferences($this->zdb
);
74 $this->i18n
= new \Galette\Core\
I18n(
75 \Galette\Core\I18n
::DEFAULT_LANG
77 $this->session
= new \RKA\
Session();
78 $this->login
= new \Galette\Core\
Login($this->zdb
, $this->i18n
, $this->session
);
80 $types = new \Galette\Repository\
PaymentTypes($this->zdb
, $this->preferences
, $this->login
);
81 $res = $types->installInit(false);
82 $this->boolean($res)->isTrue();
88 * @param string $testMethod Calling method
92 public function afterTestMethod($testMethod)
94 $this->deletePaymentType();
102 private function deletePaymentType()
104 if (is_array($this->remove
) && count($this->remove
) > 0) {
105 $delete = $this->zdb
->delete(\Galette\Entity\PaymentType
::TABLE
);
106 $delete->where
->in(\Galette\Entity\PaymentType
::PK
, $this->remove
);
107 $this->zdb
->execute($delete);
111 $this->zdb
->db
->query(
112 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
113 \Zend\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
122 public function testPaymentType()
124 global $i18n; // globals :(
127 $type = new \Galette\Entity\
PaymentType($this->zdb
);
129 $type->name
= 'Test payment type';
130 $this->boolean($type->store())->isTrue();
132 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
135 'text_orig' => 'Test payment type'
138 $results = $this->zdb
->execute($select);
139 $result = $results->current();
141 $this->array((array)$result)
142 ->string['text_orig']->isIdenticalTo('Test payment type');
145 $this->remove
[] = $id;
147 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
148 $type->name
= 'Changed test payment type';
149 $this->boolean($type->store())->isTrue();
151 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
152 $this->string($type->getName())->isIdenticalTo('Changed test payment type');
154 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
157 'text_orig' => 'Changed test payment type'
160 $results = $this->zdb
->execute($select);
161 $this->integer(count($results))->isIdenticalTo(10);
163 $type = new \Galette\Entity\
PaymentType($this->zdb
, \Galette\Entity\PaymentType
::CASH
);
165 function () use ($type) {
169 ->hasMessage('You cannot delete system payment types!')
170 ->isInstanceOf('\RuntimeException');
172 $type = new \Galette\Entity\
PaymentType($this->zdb
, $id);
173 $this->boolean($type->remove())->isTrue();
175 $select = $this->zdb
->select(\Galette\Core\L10n
::TABLE
);
178 'text_orig' => 'Test payment type'
181 $results = $this->zdb
->execute($select);
182 $this->integer($results->count())->isIdenticalTo(0);