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
64 * @param string $method Calling method
68 public function beforeTestMethod($method)
70 $this->zdb
= new \Galette\Core\
Db();
71 $this->i18n
= new \Galette\Core\
I18n();
73 $this->login
= new \mock\Galette\Core\
Login($this->zdb
, $this->i18n
);
74 $this->calling($this->login
)->isLogged
= true;
75 $this->calling($this->login
)->isSuperAdmin
= true;
76 $this->calling($this->login
)->__get
= 0; //to get login id
82 * @param string $method Calling method
86 public function afterTestMethod($method)
88 if (TYPE_DB
=== 'mysql') {
89 $this->array($this->zdb
->getWarnings())->isIdenticalTo([]);
91 $this->deleteCreated();
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, $translator; // globals :(
116 $i18n->changeLanguage('en_US');
118 $saved = new \Galette\Entity\
SavedSearch($this->zdb
, $this->login
);
119 $searches = new \Galette\Repository\
SavedSearches($this->zdb
, $this->login
);
125 'membership_filter' => 0,
126 'filter_account' => 0,
131 'form' => 'Adherent',
132 'name' => 'Simple search'
136 unset($errored['form']);
137 $this->boolean($saved->check($errored))->isFalse();
138 $this->array($saved->getErrors())->isIdenticalTo(['form' => 'Form is mandatory!']);
141 $this->boolean($saved->check($post))->isTrue();
142 $this->boolean($saved->store())->isTrue();
143 $this->array($searches->getList(true))->hasSize(1);
144 //store again, got a duplicate
145 $this->boolean($saved->store())->isTrue();
146 $this->array($searches->getList(true))->hasSize(2);