]>
git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/History.php
e275802f493243be8cd78b3c380540f9ea606260
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2016 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 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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Core\test\units
;
40 use Galette\GaletteTestCase
;
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
54 class History
extends GaletteTestCase
57 * Test class constants
61 public function testConstants()
63 $this->string(\Galette\Core\History
::TABLE
)->isIdenticalTo('logs');
64 $this->string(\Galette\Core\History
::PK
)->isIdenticalTo('id_log');
68 * Test history workflow
72 public function testHistoryFlow()
74 $this->i18n
->changeLanguage('en_US');
75 //nothing in the logs at the begining
76 $list = $this->history
->getHistory();
77 $this->array($list)->hasSize(0);
80 $add = $this->history
->add(
82 'Something was added from tests'
84 $this->boolean($add)->isTrue();
86 $add = $this->history
->add(
88 'Something else was added from tests',
89 'SELECT * FROM none WHERE non ORDER BY none'
91 $this->boolean($add)->isTrue();
93 $add = $this->history
->add(
95 'And something else, again'
97 $this->boolean($add)->isTrue();
99 //check what has been stored
100 $list = $this->history
->getHistory();
101 $this->array($list)->hasSize(3);
103 $actions = $this->history
->getActionsList();
104 $this->array($actions)
106 ->string[0]->isIdenticalTo('AnotherTest')
107 ->string[1]->isIdenticalTo('Test');
110 $this->history
->filters
->action_filter
= 'Test';
111 $list = $this->history
->getHistory();
112 $this->array($list)->hasSize(2);
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);
120 $cleaned = $this->history
->clean();
121 $this->boolean($cleaned)->isTrue();
123 $list = $this->history
->getHistory();
124 $this->array($list)->hasSize(1);
126 $this->zdb
->db
->query(
127 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
128 \Zend\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
133 * Test add that throws an exception
137 public function testAddWException()
139 $this->zdb
= new \mock\Galette\Core\
Db();
140 $this->calling($this->zdb
)->execute
= function ($o) {
141 throw new \
LogicException('Error executing query!', 123);
144 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
, $this->preferences
);
145 $add = $this->history
->add('Test');
146 $this->boolean($add)->isFalse();
150 * Test getHistory that throws an exception
154 public function testGetHistoryWException()
156 $this->zdb
= new \mock\Galette\Core\
Db();
157 $this->calling($this->zdb
)->execute
= function ($o) {
158 throw new \
LogicException('Error executing query!', 123);
161 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
, $this->preferences
);
162 $list = $this->history
->getHistory();
163 $this->boolean($list)->isFalse();