3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2020 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 2020 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\Controllers\test\units
;
43 * PDF controller tests
45 * @category Controllers
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2020 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 PdfController
extends atoum
66 private $members_fields;
68 private $mocked_router;
70 private $flash_data = [];
76 * @param string $method Calling method
80 public function beforeTestMethod($method)
82 $this->zdb
= new \Galette\Core\
Db();
83 $this->preferences
= new \Galette\Core\
Preferences($this->zdb
);
84 $this->i18n
= new \Galette\Core\
I18n(
85 \Galette\Core\I18n
::DEFAULT_LANG
87 $this->login
= new \Galette\Core\
Login($this->zdb
, $this->i18n
);
89 $models = new \Galette\Repository\
PdfModels($this->zdb
, $this->preferences
, $this->login
);
90 $res = $models->installInit(false);
91 $this->boolean($res)->isTrue();
93 $this->mocked_router
= new \mock\Slim\
Router();
94 $this->calling($this->mocked_router
)->pathFor
= function ($name, $params) {
98 $this->session
= new \RKA\
Session();
99 $this->history
= new \Galette\Core\
History($this->zdb
, $this->login
, $this->preferences
);
101 $this->flash_data
= &$flash_data;
102 $this->flash
= new \Slim\Flash\
Messages($flash_data);
104 $_SERVER['HTTP_HOST'] = '';
106 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields.php';
107 $this->members_fields
= $members_fields;
109 $this->adh
= new \Galette\Entity\
Adherent($this->zdb
);
110 $this->adh
->setDependencies(
112 $this->members_fields
,
116 $app = new \Slim\
App(['router' => $this->mocked_router
, 'flash' => $this->flash
]);
117 $this->container
= $app->getContainer();
119 $this->container
['view'] = null;
120 $this->container
['zdb'] = $this->zdb
;
121 $this->container
['login'] = $this->login
;
122 $this->container
['session'] = $this->session
;
123 $this->container
['preferences'] = $this->preferences
;
124 $this->container
['logo'] = null;
125 $this->container
['print_logo'] = null;
126 $this->container
['plugins'] = null;
127 $this->container
['history'] = $this->history
;
128 $this->container
['i18n'] = null;
129 $this->container
['fields_config'] = null;
130 $this->container
['lists_config'] = null;
131 $this->container
['l10n'] = null;
132 $this->container
['members_fields'] = $this->members_fields
;
133 $members_form_fields = $this->members_fields
;
134 foreach ($members_form_fields as $k => $field) {
135 if ($field['position'] == -1) {
136 unset($members_form_fields[$k]);
139 //$this->members_form_fields = $members_form_fields;
140 $this->container
['members_form_fields'] = $members_form_fields;
142 include_once GALETTE_ROOT
. 'includes/fields_defs/members_fields_cats.php';
143 $this->container
['members_fields_cats'] = $members_fields_cats;
145 global $container, $zdb, $i18n, $login, $hist;
146 $zdb = $this->zdb
; //globals '(
147 $container = $this->container
; //globals '(
149 $login = $this->login
;
150 $hist = $this->history
;
156 * @param string $method Calling method
160 public function afterTestMethod($method)
162 if (TYPE_DB
=== 'mysql') {
163 $this->array($this->zdb
->getWarnings())->isIdenticalTo([]);
172 public function testStoreModels()
174 $model = new \Galette\Entity\
PdfInvoice($this->zdb
, $this->preferences
);
175 $this->string($model->title
)->isIdenticalTo('_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}');
177 $environment = \Slim\Http\Environment
::mock(
179 'REQUEST_METHOD' => 'POST',
180 'REQUEST_URI' => '/models/pdf'
183 $uri = \Slim\Http\Uri
::createFromEnvironment($environment);
184 $headers = \Slim\Http\Headers
::createFromEnvironment($environment);
186 $serverParams = $environment->all();
188 $body = new \Slim\Http\
RequestBody();
192 'models_id' => \Galette\Entity\PdfModel
::INVOICE_MODEL
,
193 'model_type' => \Galette\Entity\PdfModel
::INVOICE_MODEL
,
194 'model_title' => 'DaTitle'
198 $request = new \Slim\Http\
Request('POST', $uri, $headers, $cookies, $serverParams, $body);
199 $request = $request->withHeader('Content-Type', 'application/json');
200 $response = new \Slim\Http\
Response();
201 $controller = new \Galette\Controllers\
PdfController($this->container
);
203 $test_response = $controller->storeModels($request, $response);
204 $this->array($this->flash_data
['slimFlash'])->isIdenticalTo([
205 'success_detected' => [
206 'Model has been successfully stored!'
210 $model = new \Galette\Entity\
PdfInvoice($this->zdb
, $this->preferences
);
211 $this->string($model->title
)->isIdenticalTo('DaTitle');