]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/History.php
497aebb36eab7d211e3ac4c5c5b4b06ff53bfec0
[galette.git] / tests / Galette / Core / tests / units / History.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * History tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2016 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 Core
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2016 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 2016-11-26
36 */
37
38 namespace Galette\Core\test\units;
39
40 use Galette\GaletteTestCase;
41
42 /**
43 * History tests class
44 *
45 * @category Core
46 * @name History
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2016 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2016-11-26
53 */
54 class History extends GaletteTestCase
55 {
56 /**
57 * Test class constants
58 *
59 * @return void
60 */
61 public function testConstants()
62 {
63 $this->string(\Galette\Core\History::TABLE)->isIdenticalTo('logs');
64 $this->string(\Galette\Core\History::PK)->isIdenticalTo('id_log');
65 }
66
67 /**
68 * Test history workflow
69 *
70 * @return void
71 */
72 public function testHistoryFlow()
73 {
74 $this->i18n->changeLanguage('en_US');
75 //nothing in the logs at the beginning
76 $list = $this->history->getHistory();
77 $this->array($list)->hasSize(0);
78
79 //add some entries
80 $add = $this->history->add(
81 'Test',
82 'Something was added from tests'
83 );
84 $this->boolean($add)->isTrue();
85
86 $add = $this->history->add(
87 'Test',
88 'Something else was added from tests',
89 'SELECT * FROM none WHERE non ORDER BY none'
90 );
91 $this->boolean($add)->isTrue();
92
93 $add = $this->history->add(
94 'AnotherTest',
95 'And something else, again'
96 );
97 $this->boolean($add)->isTrue();
98
99 //check what has been stored
100 $list = $this->history->getHistory();
101 $this->array($list)->hasSize(3);
102
103 $actions = $this->history->getActionsList();
104 $this->array($actions)
105 ->hasSize(2)
106 ->string[0]->isIdenticalTo('AnotherTest')
107 ->string[1]->isIdenticalTo('Test');
108
109 //some filtering
110 $this->history->filters->action_filter = 'Test';
111 $list = $this->history->getHistory();
112 $this->array($list)->hasSize(2);
113
114 $this->history->filters->start_date_filter = date('Y-m-d');
115 $this->history->filters->end_date_filter = date('Y-m-d');
116 $list = $this->history->getHistory();
117 $this->array($list)->hasSize(2);
118
119 //let's clean now
120 $cleaned = $this->history->clean();
121 $this->boolean($cleaned)->isTrue();
122
123 $list = $this->history->getHistory();
124 $this->array($list)->hasSize(1);
125
126 $this->cleanHistory();
127 }
128
129 /**
130 * Test add that throws an exception
131 *
132 * @return void
133 */
134 public function testAddWException()
135 {
136 $this->zdb = new \mock\Galette\Core\Db();
137 $this->calling($this->zdb)->execute = function ($o) {
138 throw new \LogicException('Error executing query!', 123);
139 };
140
141 $this->history = new \Galette\Core\History($this->zdb, $this->login, $this->preferences);
142 $add = $this->history->add('Test');
143 $this->boolean($add)->isFalse();
144 }
145
146 /**
147 * Test getHistory that throws an exception
148 *
149 * @return void
150 */
151 public function testGetHistoryWException()
152 {
153 $this->zdb = new \mock\Galette\Core\Db();
154 $this->calling($this->zdb)->execute = function ($o) {
155 throw new \LogicException('Error executing query!', 123);
156 };
157
158 $this->history = new \Galette\Core\History($this->zdb, $this->login, $this->preferences);
159 $list = $this->history->getHistory();
160 $this->boolean($list)->isFalse();
161 }
162 }