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/>.
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
;
41 use Zend\Db\Adapter\Adapter
;
48 * @package GaletteTests
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2019 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 SavedSearch
extends atoum
65 * @param string $testMethod Calling method
69 public function beforeTestMethod($testMethod)
71 $this->zdb
= new \Galette\Core\
Db();
72 $this->i18n
= new \Galette\Core\
I18n();
73 $this->session
= new \RKA\
Session();
75 $this->login
= new \mock\Galette\Core\
Login($this->zdb
, $this->i18n
, $this->session
);
76 $this->calling($this->login
)->isLogged
= true;
77 $this->calling($this->login
)->isSuperAdmin
= true;
78 parent
::beforeTestMethod($testMethod);
84 * @param string $testMethod Calling method
88 public function afterTestMethod($testMethod)
90 $this->deleteCreated();
91 parent
::afterTestMethod($testMethod);
99 private function deleteCreated()
101 $this->zdb
->db
->query(
102 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Entity\SavedSearch
::TABLE
,
103 \Zend\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
112 public function testSave()
114 global $i18n; // globals :(
117 $saved = new \Galette\Entity\
SavedSearch($this->zdb
, $this->login
);
123 'membership_filter' => 0,
124 'filter_account' => 0,
129 'form' => 'Adherent',
130 'name' => 'Simple search'
134 unset($errored['form']);
135 $this->boolean($saved->check($errored))->isFalse();
136 $this->array($saved->getErrors())->isIdenticalTo(['form' => 'Form is mandatory!']);
139 $this->boolean($saved->check($post))->isTrue();
140 $this->boolean($saved->store())->isTrue();
141 //store again, got a duplicate
142 $this->variable($saved->store())->isNull();