]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/Title.php
202ebe10f096d8c675beef80227f4ef8f20a4c43
[galette.git] / tests / Galette / Entity / tests / units / Title.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Titles 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2019-12-14
36 */
37
38 namespace Galette\Entity\test\units;
39
40 use atoum;
41 use Laminas\Db\Adapter\Adapter;
42
43 /**
44 * Status tests
45 *
46 * @category Entity
47 * @name Title
48 * @package GaletteTests
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2019-2023 The Galette Team
51 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
52 * @link http://galette.tuxfamily.org
53 * @since 2019-12-14
54 */
55 class Title extends atoum
56 {
57 private \Galette\Core\Db $zdb;
58 private array $remove = [];
59
60 /**
61 * Set up tests
62 *
63 * @param string $method Calling method
64 *
65 * @return void
66 */
67 public function beforeTestMethod($method)
68 {
69 $this->zdb = new \Galette\Core\Db();
70 }
71
72 /**
73 * Tear down tests
74 *
75 * @param string $method Calling method
76 *
77 * @return void
78 */
79 public function afterTestMethod($method)
80 {
81 if (TYPE_DB === 'mysql') {
82 $this->array($this->zdb->getWarnings())->isIdenticalTo([]);
83 }
84 $this->deleteTitle();
85 }
86
87 /**
88 * Delete status
89 *
90 * @return void
91 */
92 private function deleteTitle()
93 {
94 if (is_array($this->remove) && count($this->remove) > 0) {
95 $delete = $this->zdb->delete(\Galette\Entity\Title::TABLE);
96 $delete->where->in(\Galette\Entity\Title::PK, $this->remove);
97 $this->zdb->execute($delete);
98 }
99
100 //Clean logs
101 $this->zdb->db->query(
102 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
103 \Laminas\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
104 );
105 }
106
107 /**
108 * Test title
109 *
110 * @return void
111 */
112 public function testTitle()
113 {
114 global $zdb;
115 $zdb = $this->zdb;
116
117 $titles = new \Galette\Repository\Titles($this->zdb);
118 if (count($titles->getList($this->zdb)) === 0) {
119 $res = $titles->installInit($this->zdb);
120 $this->boolean($res)->isTrue();
121 }
122
123 $title = new \Galette\Entity\Title();
124
125 $title->short = 'Te.';
126 $title->long = 'Test';
127 $this->boolean($title->store($this->zdb))->isTrue();
128
129 $id = $title->id;
130 $this->remove[] = $id;
131 $title = new \Galette\Entity\Title($id); //reload
132
133 $title->long = 'Test title';
134 $this->boolean($title->store($this->zdb))->isTrue();
135 $title = new \Galette\Entity\Title($id); //reload
136
137 $this->string($title->long)->isIdenticalTo('Test title');
138
139 $title = new \Galette\Entity\Title(\Galette\Entity\Title::MR);
140 $this->exception(
141 function () use ($title) {
142 $title->remove($this->zdb);
143 }
144 )
145 ->hasMessage('You cannot delete Mr. or Mrs. titles!')
146 ->isInstanceOf('\RuntimeException');
147
148 $title = new \Galette\Entity\Title($id); //reload
149 $this->boolean(
150 $title->remove($this->zdb)
151 )->isTrue();
152 }
153 }