]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/PaymentType.php
fe971503bdfbab7a0f1bc74757bd38dc864e6a6e
[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 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 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2019-12-15
36 */
37
38 namespace Galette\Entity\test\units;
39
40 use atoum;
41
42 /**
43 * Payment type tests
44 *
45 * @category Entity
46 * @name PaymentType
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
52 * @since 2019-12-15
53 */
54 class PaymentType extends atoum
55 {
56 private $zdb;
57 private $preferences;
58 private $session;
59 private $login;
60 private $remove = [];
61 private $i18n;
62
63 /**
64 * Set up tests
65 *
66 * @param string $testMethod Calling method
67 *
68 * @return void
69 */
70 public function beforeTestMethod($testMethod)
71 {
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
76 );
77 $this->session = new \RKA\Session();
78 $this->login = new \Galette\Core\Login($this->zdb, $this->i18n, $this->session);
79
80 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
81 $res = $types->installInit(false);
82 $this->boolean($res)->isTrue();
83 }
84
85 /**
86 * Tear down tests
87 *
88 * @param string $testMethod Calling method
89 *
90 * @return void
91 */
92 public function afterTestMethod($testMethod)
93 {
94 $this->deletePaymentType();
95 }
96
97 /**
98 * Delete payment type
99 *
100 * @return void
101 */
102 private function deletePaymentType()
103 {
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);
108 }
109
110 //Clean logs
111 $this->zdb->db->query(
112 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
113 \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
114 );
115 }
116
117 /**
118 * Test payment type
119 *
120 * @return void
121 */
122 public function testPaymentType()
123 {
124 global $i18n; // globals :(
125 $i18n = $this->i18n;
126
127 $type = new \Galette\Entity\PaymentType($this->zdb);
128
129 $type->name = 'Test payment type';
130 $this->boolean($type->store())->isTrue();
131
132 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
133 $select->where(
134 array(
135 'text_orig' => 'Test payment type'
136 )
137 );
138 $results = $this->zdb->execute($select);
139 $result = $results->current();
140
141 $this->array((array)$result)
142 ->string['text_orig']->isIdenticalTo('Test payment type');
143
144 $id = $type->id;
145 $this->remove[] = $id;
146
147 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
148 $type->name = 'Changed test payment type';
149 $this->boolean($type->store())->isTrue();
150
151 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
152 $this->string($type->getName())->isIdenticalTo('Changed test payment type');
153
154 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
155 $select->where(
156 array(
157 'text_orig' => 'Changed test payment type'
158 )
159 );
160 $results = $this->zdb->execute($select);
161 $this->integer(count($results))->isIdenticalTo(10);
162
163 $type = new \Galette\Entity\PaymentType($this->zdb, \Galette\Entity\PaymentType::CASH);
164 $this->exception(
165 function () use ($type) {
166 $type->remove();
167 }
168 )
169 ->hasMessage('You cannot delete system payment types!')
170 ->isInstanceOf('\RuntimeException');
171
172 $type = new \Galette\Entity\PaymentType($this->zdb, $id);
173 $this->boolean($type->remove())->isTrue();
174
175 $select = $this->zdb->select(\Galette\Core\L10n::TABLE);
176 $select->where(
177 array(
178 'text_orig' => 'Test payment type'
179 )
180 );
181 $results = $this->zdb->execute($select);
182 $this->integer($results->count())->isIdenticalTo(0);
183 }
184 }