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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Entity\test\units
;
41 use Laminas\Db\Adapter\Adapter
;
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
55 class Title
extends atoum
57 private \Galette\Core\Db
$zdb;
58 private array $remove = [];
63 * @param string $method Calling method
67 public function beforeTestMethod($method)
69 $this->zdb
= new \Galette\Core\
Db();
75 * @param string $method Calling method
79 public function afterTestMethod($method)
81 if (TYPE_DB
=== 'mysql') {
82 $this->array($this->zdb
->getWarnings())->isIdenticalTo([]);
92 private function deleteTitle()
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);
101 $this->zdb
->db
->query(
102 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
103 \Laminas\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
112 public function testTitle()
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();
123 $title = new \Galette\Entity\
Title();
125 $title->short
= 'Te.';
126 $title->long
= 'Test';
127 $this->boolean($title->store($this->zdb
))->isTrue();
130 $this->remove
[] = $id;
131 $title = new \Galette\Entity\
Title($id); //reload
133 $title->long
= 'Test title';
134 $this->boolean($title->store($this->zdb
))->isTrue();
135 $title = new \Galette\Entity\
Title($id); //reload
137 $this->string($title->long
)->isIdenticalTo('Test title');
139 $title = new \Galette\Entity\
Title(\Galette\Entity\Title
::MR
);
141 function () use ($title) {
142 $title->remove($this->zdb
);
145 ->hasMessage('You cannot delete Mr. or Mrs. titles!')
146 ->isInstanceOf('\RuntimeException');
148 $title = new \Galette\Entity\
Title($id); //reload
150 $title->remove($this->zdb
)