]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/SavedSeach.php
9bea780c3d5050f75dfee2d284e6a0bb6fbd3bf4
[galette.git] / tests / Galette / Entity / tests / units / SavedSeach.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Saved search 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 Entity
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-05-08
36 */
37
38 namespace Galette\Entity\test\units;
39
40 use \atoum;
41 use Zend\Db\Adapter\Adapter;
42
43 /**
44 * Saved search tests
45 *
46 * @category Entity
47 * @name SavedSearch
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
53 * @since 2019-05-08
54 */
55 class SavedSearch extends atoum
56 {
57 private $zdb;
58 private $i18n;
59 private $session;
60 private $login;
61
62 /**
63 * Set up tests
64 *
65 * @param string $testMethod Calling method
66 *
67 * @return void
68 */
69 public function beforeTestMethod($testMethod)
70 {
71 $this->zdb = new \Galette\Core\Db();
72 $this->i18n = new \Galette\Core\I18n();
73 $this->session = new \RKA\Session();
74
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);
79 }
80
81 /**
82 * Tear down tests
83 *
84 * @param string $testMethod Calling method
85 *
86 * @return void
87 */
88 public function afterTestMethod($testMethod)
89 {
90 $this->deleteCreated();
91 parent::afterTestMethod($testMethod);
92 }
93
94 /**
95 * Delete status
96 *
97 * @return void
98 */
99 private function deleteCreated()
100 {
101 $this->zdb->db->query(
102 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Entity\SavedSearch::TABLE,
103 \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
104 );
105 }
106
107 /**
108 * Test saved search
109 *
110 * @return void
111 */
112 public function testSave()
113 {
114 global $i18n; // globals :(
115 $i18n = $this->i18n;
116
117 $saved = new \Galette\Entity\SavedSearch($this->zdb, $this->login);
118
119 $post = [
120 'parameters' => [
121 'filter_str' => '',
122 'field_filter' => 0,
123 'membership_filter' => 0,
124 'filter_account' => 0,
125 'roup_filter' => 0,
126 'email_filter' => 5,
127 'nbshow' => 10
128 ],
129 'form' => 'Adherent',
130 'name' => 'Simple search'
131 ];
132
133 $errored = $post;
134 unset($errored['form']);
135 $this->boolean($saved->check($errored))->isFalse();
136 $this->array($saved->getErrors())->isIdenticalTo(['form' => 'Form is mandatory!']);
137
138 //store search
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();
143 }
144 }