]>
git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/History.php
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
;
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 atoum
56 private $history = null;
65 * @param string $testMethod Method name
69 public function beforeTestMethod($testMethod)
71 $this->zdb
= new \Galette\Core\
Db();
72 $this->i18n
= new \Galette\Core\
I18n();
73 $this->session
= new \RKA\
Session();
74 $this->login
= new \Galette\Core\
Login($this->zdb
, $this->i18n
, $this->session
);
75 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
);
79 * Test class constants
83 public function testConstants()
85 $this->string(\Galette\Core\History
::TABLE
)->isIdenticalTo('logs');
86 $this->string(\Galette\Core\History
::PK
)->isIdenticalTo('id_log');
90 * Test history workflow
94 public function testHistoryFlow()
96 //nothing in the logs at the begining
97 $list = $this->history
->getHistory();
98 $this->array($list)->hasSize(0);
101 $add = $this->history
->add(
103 'Something was added from tests'
105 $this->boolean($add)->isTrue();
107 $add = $this->history
->add(
109 'Something else was added from tests',
110 'SELECT * FROM none WHERE non ORDER BY none'
112 $this->boolean($add)->isTrue();
114 $add = $this->history
->add(
116 'And something else, again'
118 $this->boolean($add)->isTrue();
120 //check what has been stored
121 $list = $this->history
->getHistory();
122 $this->array($list)->hasSize(3);
124 $actions = $this->history
->getActionsList();
125 $this->array($actions)
127 ->string[0]->isIdenticalTo('AnotherTest')
128 ->string[1]->isIdenticalTo('Test');
131 $this->history
->filters
->action_filter
= 'Test';
132 $list = $this->history
->getHistory();
133 $this->array($list)->hasSize(2);
135 $this->history
->filters
->start_date_filter
= date('Y-m-d');
136 $this->history
->filters
->end_date_filter
= date('Y-m-d');
137 $list = $this->history
->getHistory();
138 $this->array($list)->hasSize(2);
141 $cleaned = $this->history
->clean();
142 $this->boolean($cleaned)->isTrue();
144 $list = $this->history
->getHistory();
145 $this->array($list)->hasSize(1);
147 $this->zdb
->db
->query(
148 'TRUNCATE TABLE ' . PREFIX_DB
. \Galette\Core\History
::TABLE
,
149 \Zend\Db\Adapter\Adapter
::QUERY_MODE_EXECUTE
154 * Test add that throws an exception
158 public function testAddWException()
160 $this->zdb
= new \mock\Galette\Core\
Db();
161 $this->calling($this->zdb
)->execute
= function ($o) {
162 throw new \
LogicException('Error executing query!', 123);
165 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
);
166 $add = $this->history
->add('Test');
167 $this->boolean($add)->isFalse();
171 * Test getHistory that throws an exception
175 public function testGetHistoryWException()
177 $this->zdb
= new \mock\Galette\Core\
Db();
178 $this->calling($this->zdb
)->execute
= function ($o) {
179 throw new \
LogicException('Error executing query!', 123);
182 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
);
183 $list = $this->history
->getHistory();
184 $this->boolean($list)->isFalse();