]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/SavedSeach.php
No longer look for saved searches duplicates
[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 $login;
60
61 /**
62 * Set up tests
63 *
64 * @param string $testMethod Calling method
65 *
66 * @return void
67 */
68 public function beforeTestMethod($testMethod)
69 {
70 $this->zdb = new \Galette\Core\Db();
71 $this->i18n = new \Galette\Core\I18n();
72
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
77 }
78
79 /**
80 * Tear down tests
81 *
82 * @param string $testMethod Calling method
83 *
84 * @return void
85 */
86 public function afterTestMethod($testMethod)
87 {
88 $this->deleteCreated();
89 }
90
91 /**
92 * Delete status
93 *
94 * @return void
95 */
96 private function deleteCreated()
97 {
98 $this->zdb->db->query(
99 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Entity\SavedSearch::TABLE,
100 \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
101 );
102 }
103
104 /**
105 * Test saved search
106 *
107 * @return void
108 */
109 public function testSave()
110 {
111 global $i18n, $translator; // globals :(
112 $i18n = $this->i18n;
113 $i18n->changeLanguage('en_US');
114
115 $saved = new \Galette\Entity\SavedSearch($this->zdb, $this->login);
116 $searches = new \Galette\Repository\SavedSearches($this->zdb, $this->login);
117
118 $post = [
119 'parameters' => [
120 'filter_str' => '',
121 'field_filter' => 0,
122 'membership_filter' => 0,
123 'filter_account' => 0,
124 'roup_filter' => 0,
125 'email_filter' => 5,
126 'nbshow' => 10
127 ],
128 'form' => 'Adherent',
129 'name' => 'Simple search'
130 ];
131
132 $errored = $post;
133 unset($errored['form']);
134 $this->boolean($saved->check($errored))->isFalse();
135 $this->array($saved->getErrors())->isIdenticalTo(['form' => 'Form is mandatory!']);
136
137 //store search
138 $this->boolean($saved->check($post))->isTrue();
139 $this->boolean($saved->store())->isTrue();
140 $this->array($searches->getList(true))->hasSize(1);
141 //store again, got a duplicate
142 $this->boolean($saved->store())->isTrue();
143 $this->array($searches->getList(true))->hasSize(2);
144 }
145 }