]> git.agnieray.net Git - galette.git/blob - tests/Galette/Entity/tests/units/SavedSeach.php
Check MySQL warning in tests suite
[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 $method Calling method
65 *
66 * @return void
67 */
68 public function beforeTestMethod($method)
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 $method Calling method
83 *
84 * @return void
85 */
86 public function afterTestMethod($method)
87 {
88 if (TYPE_DB === 'mysql') {
89 $this->array($this->zdb->getWarnings())->isIdenticalTo([]);
90 }
91 $this->deleteCreated();
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, $translator; // globals :(
115 $i18n = $this->i18n;
116 $i18n->changeLanguage('en_US');
117
118 $saved = new \Galette\Entity\SavedSearch($this->zdb, $this->login);
119 $searches = new \Galette\Repository\SavedSearches($this->zdb, $this->login);
120
121 $post = [
122 'parameters' => [
123 'filter_str' => '',
124 'field_filter' => 0,
125 'membership_filter' => 0,
126 'filter_account' => 0,
127 'roup_filter' => 0,
128 'email_filter' => 5,
129 'nbshow' => 10
130 ],
131 'form' => 'Adherent',
132 'name' => 'Simple search'
133 ];
134
135 $errored = $post;
136 unset($errored['form']);
137 $this->boolean($saved->check($errored))->isFalse();
138 $this->array($saved->getErrors())->isIdenticalTo(['form' => 'Form is mandatory!']);
139
140 //store search
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);
147 }
148 }