*
* PHP version 5
*
- * Copyright © 2020 The Galette Team
+ * Copyright © 2020-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* @package GaletteTests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2020 The Galette Team
+ * @copyright 2020-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
- * @version SVN: $Id$
* @link http://galette.tuxfamily.org
* @since 2020-11-21
*/
namespace Galette\Entity\test\units;
-use atoum;
use Galette\Entity\Adherent;
use Galette\DynamicFields\DynamicField;
+use Galette\GaletteTestCase;
/**
* PDF model tests
* @name PdfModel
* @package GaletteTests
* @author Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2020 The Galette Team
+ * @copyright 2020-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since 2020-11-21
*/
-class PdfModel extends atoum
+class PdfModel extends GaletteTestCase
{
- private $zdb;
- private $preferences;
- private $login;
- private $remove = [];
- private $i18n;
- private $container;
- private $seed = 95842354;
- private $history;
-
- private $adh;
- private $contrib;
- private $members_fields;
+ private array $remove = [];
+ protected int $seed = 95842354;
/**
* Set up tests
*
- * @param string $testMethod Calling method
- *
* @return void
*/
- public function beforeTestMethod($testMethod)
+ public function setUp(): void
{
- $this->zdb = new \Galette\Core\Db();
- $this->preferences = new \Galette\Core\Preferences($this->zdb);
- $this->i18n = new \Galette\Core\I18n(
- \Galette\Core\I18n::DEFAULT_LANG
- );
- $this->login = new \Galette\Core\Login($this->zdb, $this->i18n);
+ parent::setUp();
$models = new \Galette\Repository\PdfModels($this->zdb, $this->preferences, $this->login);
$res = $models->installInit(false);
- $this->boolean($res)->isTrue();
-
- $container = new class {
- /**
- * Get (only router)
- *
- * @param string $name Param name
- *
- * @return mixed
- */
- public function get($name)
- {
- $router = new class {
- /**
- * Get path ('')
- *
- * @param sttring $name Route name
- *
- * @return string
- */
- public function pathFor($name)
- {
- return '';
- }
- };
- return $router;
- }
- };
- $_SERVER['HTTP_HOST'] = '';
- $this->container = $container;
-
- $this->history = new \Galette\Core\History($this->zdb, $this->login, $this->preferences);
-
- include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
- $this->members_fields = $members_fields;
+ $this->assertTrue($res);
$this->adh = new \Galette\Entity\Adherent($this->zdb);
$this->adh->setDependencies(
$this->members_fields,
$this->history
);
-
- global $container, $zdb;
- $zdb = $this->zdb; //globals '(
- $container = $this->container; //globals '(
+ $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
}
/**
* Tear down tests
*
- * @param string $testMethod Calling method
- *
* @return void
*/
- public function afterTestMethod($testMethod)
+ public function tearDown(): void
{
+ parent::tearDown();
+
$delete = $this->zdb->delete(\Galette\Entity\Contribution::TABLE);
$delete->where(['info_cotis' => 'FAKER' . $this->seed]);
$this->zdb->execute($delete);
]
]);
$this->zdb->execute($delete);
-
- /*if ($this->contents_table !== null) {
- $this->zdb->drop($this->contents_table);
- }*/
}
/**
'asso_address_multi' => '/{ASSO_ADDRESS_MULTI}/',
'asso_website' => '/{ASSO_WEBSITE}/',
'asso_logo' => '/{ASSO_LOGO}/',
- 'date_now' => '/{DATE_NOW}/'
+ 'date_now' => '/{DATE_NOW}/',
+ 'login_uri' => '/{LOGIN_URI}/',
+ 'asso_footer' => '/{ASSO_FOOTER}/',
];
- $this->array($model->patterns)->isIdenticalTo($main_expected);
+ $this->assertSame($main_expected, $model->getPatterns());
$model = new \Galette\Entity\PdfMain($this->zdb, $this->preferences);
- $this->array($model->patterns)->isIdenticalTo($main_expected);
+ $this->assertSame($main_expected, $model->getPatterns());
$expected = $main_expected + [
'adh_title' => '/{TITLE_ADH}/',
'adh_id' => '/{ID_ADH}/',
+ 'adh_num' => '/{NUM_ADH}/',
'adh_name' => '/{NAME_ADH}/',
'adh_last_name' => '/{LAST_NAME_ADH}/',
'adh_first_name' => '/{FIRST_NAME_ADH}/',
'adh_profession' => '/{PROFESSION_ADH}/',
'adh_company' => '/{COMPANY_ADH}/',
'adh_address' => '/{ADDRESS_ADH}/',
+ 'adh_address_multi' => '/{ADDRESS_ADH_MULTI}/',
'adh_zip' => '/{ZIP_ADH}/',
'adh_town' => '/{TOWN_ADH}/',
'adh_country' => '/{COUNTRY_ADH}/',
'adh_email' => '/{EMAIL_ADH}/',
'adh_login' => '/{LOGIN_ADH}/',
'adh_main_group' => '/{GROUP_ADH}/',
- 'adh_groups' => '/{GROUPS_ADH}/'
+ 'adh_groups' => '/{GROUPS_ADH}/',
+ 'adh_dues' => '/{ADH_DUES}/',
+ 'days_remaining' => '/{DAYS_REMAINING}/',
+ 'days_expired' => '/{DAYS_EXPIRED}/',
+ '_adh_company' => '/{COMPANY_NAME_ADH}/',
+ '_adh_last_name' => '/{LASTNAME_ADH}/',
+ '_adh_first_name' => '/{FIRSTNAME_ADH}/',
+ '_adh_login' => '/{LOGIN}/',
+ '_adh_email' => '/{MAIL_ADH}/',
];
$model = new \Galette\Entity\PdfAdhesionFormModel($this->zdb, $this->preferences);
- $this->array($model->patterns)->isIdenticalTo($expected);
+ $this->assertSame($expected, $model->getPatterns());
- $expected = $expected + [
+ $expected += [
'contrib_label' => '/{CONTRIB_LABEL}/',
'contrib_amount' => '/{CONTRIB_AMOUNT}/',
'contrib_amount_letters' => '/{CONTRIB_AMOUNT_LETTERS}/',
'contrib_edate' => '/{CONTRIB_END_DATE}/',
'contrib_id' => '/{CONTRIB_ID}/',
'contrib_payment' => '/{CONTRIB_PAYMENT_TYPE}/',
+ 'contrib_info' => '/{CONTRIB_INFO}/',
'_contrib_label' => '/{CONTRIBUTION_LABEL}/',
'_contrib_amount' => '/{CONTRIBUTION_AMOUNT}/',
'_contrib_amount_letters' => '/{CONTRIBUTION_AMOUNT_LETTERS}/',
'_contrib_bdate' => '/{CONTRIBUTION_BEGIN_DATE}/',
'_contrib_edate' => '/{CONTRIBUTION_END_DATE}/',
'_contrib_id' => '/{CONTRIBUTION_ID}/',
- '_contrib_payment' => '/{CONTRIBUTION_PAYMENT_TYPE}/'
+ '_contrib_payment' => '/{CONTRIBUTION_PAYMENT_TYPE}/',
+ '_contrib_info' => '/{CONTRIBUTION_INFO}/',
+ '__contrib_label' => '/{CONTRIB_TYPE}/',
+ 'deadline' => '/{DEADLINE}/'
];
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences);
- $this->array($model->patterns)->isIdenticalTo($expected);
+ $this->assertSame($expected, $model->getPatterns());
$model = new \Galette\Entity\PdfReceipt($this->zdb, $this->preferences);
- $this->array($model->patterns)->isIdenticalTo($expected);
+ $this->assertSame($expected, $model->getPatterns());
}
/**
*
* @return array
*/
- protected function typesProvider(): array
+ public static function typesProvider(): array
{
return [
[
*/
public function testGetypeClass($type, $expected)
{
- $this->string(\Galette\Entity\PdfModel::getTypeClass($type))->isIdenticalTo($expected);
+ $this->assertSame($expected, \Galette\Entity\PdfModel::getTypeClass($type));
}
/**
$stored = $adf->store($field_data);
$error_detected = $adf->getErrors();
$warning_detected = $adf->getWarnings();
- $this->boolean($stored)->isTrue(
+ $this->assertTrue(
+ $stored,
implode(
' ',
$adf->getErrors() + $adf->getWarnings()
)
);
- $this->array($error_detected)->isEmpty(implode(' ', $adf->getErrors()));
- $this->array($warning_detected)->isEmpty(implode(' ', $adf->getWarnings()));
+ $this->assertEmpty($error_detected, implode(' ', $adf->getErrors()));
+ $this->assertEmpty($warning_detected, implode(' ', $adf->getWarnings()));
$field_data = [
'form_name' => 'contrib',
$stored = $cdf->store($field_data);
$error_detected = $cdf->getErrors();
$warning_detected = $cdf->getWarnings();
- $this->boolean($stored)->isTrue(
+ $this->assertTrue(
+ $stored,
implode(
' ',
$cdf->getErrors() + $cdf->getWarnings()
)
);
- $this->array($error_detected)->isEmpty(implode(' ', $cdf->getErrors()));
- $this->array($warning_detected)->isEmpty(implode(' ', $cdf->getWarnings()));
+ $this->assertEmpty($error_detected, implode(' ', $cdf->getErrors()));
+ $this->assertEmpty($warning_detected, implode(' ', $cdf->getWarnings()));
//prepare model
- $rs = new \stdClass();
$pk = \Galette\Entity\PdfModel::PK;
- $rs->$pk = 42;
- $rs->model_name = 'Test model';
- $rs->model_title = 'A simple tmodel for tests';
- $rs->model_subtitle = 'The subtitle';
- $rs->model_header = null;
- $rs->model_footer = null;
- $rs->model_body = 'name: {NAME_ADH} login: {LOGIN_ADH} birthdate: {ADH_BIRTH_DATE} dynlabel: {LABEL_DYNFIELD_' .
+ $rs = new \ArrayObject([
+ $pk => 42,
+ 'model_name' => 'Test model',
+ 'model_title' => 'A simple tmodel for tests',
+ 'model_subtitle' => 'The subtitle',
+ 'model_header' => null,
+ 'model_footer' => null,
+ 'model_body' => 'name: {NAME_ADH} login: {LOGIN_ADH} birthdate: {ADH_BIRTH_DATE} dynlabel: {LABEL_DYNFIELD_' .
$adf->getId() . '_ADH} dynvalue: {INPUT_DYNFIELD_' . $adf->getId() . '_ADH} ' .
'- enddate: {CONTRIB_END_DATE} amount: {CONTRIB_AMOUNT} ({CONTRIB_AMOUNT_LETTERS}) dynlabel: ' .
- '{LABEL_DYNFIELD_' . $cdf->getId() . '_CONTRIB} dynvalue: {INPUT_DYNFIELD_' . $cdf->getId() . '_CONTRIB}';
- $rs->model_styles = null;
- $rs->model_parent = \Galette\Entity\PdfModel::MAIN_MODEL;
-
+ '{LABEL_DYNFIELD_' . $cdf->getId() . '_CONTRIB} dynvalue: {INPUT_DYNFIELD_' . $cdf->getId() . '_CONTRIB}',
+ 'model_styles' => null,
+ 'model_parent' => \Galette\Entity\PdfModel::MAIN_MODEL
+ ], \ArrayObject::ARRAY_AS_PROPS);
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences, $rs);
- $this->string($model->hheader)->isIdenticalTo("<table>
- <tr>
- <td id=\"pdf_assoname\"><strong id=\"asso_name\">Galette</strong><br/></td>
- <td id=\"pdf_logo\"><img src=\"http://\" width=\"129\" height=\"60\"/></td>
- </tr>
-</table>");
-
- $this->string($model->hfooter)->isIdenticalTo('<div id="pdf_footer">
- Association Galette - Galette
-Palais des Papes
-Au milieu
-84000 Avignon - France<br/>
-
-</div>');
-
- $data = [
- 'nom_adh' => 'Durand',
- 'prenom_adh' => 'René',
- 'ville_adh' => 'Martel',
- 'cp_adh' => '39 069',
- 'adresse_adh' => '66, boulevard De Oliveira',
- 'email_adh' => 'meunier.josephine@ledoux.com',
- 'login_adh' => 'arthur.hamon',
- 'mdp_adh' => 'J^B-()f',
- 'mdp_adh2' => 'J^B-()f',
- 'bool_admin_adh' => false,
- 'bool_exempt_adh' => false,
- 'bool_display_info' => true,
- 'sexe_adh' => 0,
- 'prof_adh' => 'Chef de fabrication',
- 'titre_adh' => null,
- 'ddn_adh' => '1937-12-26',
- 'lieu_naissance' => 'Gonzalez-sur-Meunier',
- 'pseudo_adh' => 'ubertrand',
- 'pays_adh' => 'Antarctique',
- 'tel_adh' => '0439153432',
- 'url_adh' => 'http://bouchet.com/',
- 'activite_adh' => true,
- 'id_statut' => 9,
- 'date_crea_adh' => '2020-06-10',
- 'pref_lang' => 'en_US',
- 'fingerprint' => 'FAKER' . $this->seed,
+ $data = $this->dataAdherentOne() + [
'info_field_' . $adf->getId() . '_1' => 'My value (:'
];
$this->createMember($data);
$model->setMember($this->adh);
- $this->createContribution($cdf);
+ $this->createPdfContribution($cdf);
$model->setContribution($this->contrib);
- $this->string($model->hbody)->isEqualTo(
- 'name: DURAND René login: arthur.hamon birthdate: 1937-12-26 dynlabel: Dynamic text field dynvalue: ' .
- '<textarea id="Dynamic text field" name="Dynamic text field" value="My value (:"/> ' .
+ $this->assertStringContainsString(
+ '<td id="pdf_assoname"><strong id="asso_name">Galette</strong><br/></td>',
+ $model->hheader
+ );
+
+ $this->assertMatchesRegularExpression(
+ '/<td id="pdf_logo"><img src="@.+" width="129" height="60" alt="" \/><\/td>/',
+ $model->hheader
+ );
+
+ $this->assertSame(
+ '<div id="pdf_footer">
+ Association Galette - Galette
+Palais des Papes
+Au milieu
+84000 Avignon - France<br/>
+
+</div>',
+ $model->hfooter
+ );
+
+ $this->assertSame(
+ 'name: DURAND René login: arthur.hamon' . $this->seed . ' birthdate: ' . $data['ddn_adh'] . ' dynlabel: Dynamic text field dynvalue: ' .
+ 'My value (: ' .
'- enddate: ' . $this->contrib->end_date . ' amount: 92 (ninety-two) dynlabel: Dynamic date field ' .
- 'dynvalue: <input type="text" name="Dynamic date field" value="2020-12-03" size="10" />'
+ 'dynvalue: 2020-12-03',
+ $model->hbody
);
$legend = $model->getLegend();
- $this->array($legend)
- ->hasSize(3)
- ->hasKeys(['main', 'member', 'contribution']);
-
- $this->array($legend['main']['patterns'])->hasSize(7);
- $this->array($legend['member']['patterns'])
- ->hasSize(23)
- ->hasKeys(['LABEL_DYNFIELD_' . $adf->getId() . '_ADH', 'INPUT_DYNFIELD_' . $adf->getId() . '_ADH']);
- $this->array($legend['contribution']['patterns'])
- ->hasSize(12)
- ->hasKeys(['LABEL_DYNFIELD_' . $cdf->getId() . '_CONTRIB', 'INPUT_DYNFIELD_' . $cdf->getId() . '_CONTRIB']);
- }
-
- /**
- * Create member from data
- *
- * @param array $data Data to use to create member
- *
- * @return \Galette\Entity\Adherent
- */
- public function createMember(array $data)
- {
- $adh = $this->adh;
- $check = $adh->check($data, [], []);
- if (is_array($check)) {
- var_dump($check);
- }
- $this->boolean($check)->isTrue();
-
- $store = $adh->store();
- $this->boolean($store)->isTrue();
+ $this->assertCount(3, $legend);
+ $this->assertArrayHasKey('main', $legend);
+ $this->assertArrayHasKey('member', $legend);
+ $this->assertArrayHasKey('contribution', $legend);
+
+ $this->assertCount(9, $legend['main']['patterns']);
+ $this->assertCount(28, $legend['member']['patterns']);
+ $this->assertTrue(isset($legend['member']['patterns']['label_dynfield_' . $adf->getId() . '_adh']));
+ $this->assertCount(14, $legend['contribution']['patterns']);
+ $this->assertTrue(isset($legend['contribution']['patterns']['label_dynfield_' . $cdf->getId() . '_contrib']));
}
/**
*
* @return void
*/
- private function createContribution($cdf)
+ protected function createPdfContribution($cdf)
{
$bdate = new \DateTime(); // 2020-11-07
$bdate->sub(new \DateInterval('P5M')); // 2020-06-07
$this->createContrib($data);
}
- /**
- * Create contribution from data
- *
- * @param array $data Data to use to create contribution
- *
- * @return \Galette\Entity\Contribution
- */
- public function createContrib(array $data)
- {
- $this->contrib = new \Galette\Entity\Contribution($this->zdb, $this->login);
- $contrib = $this->contrib;
- $check = $contrib->check($data, [], []);
- if (is_array($check)) {
- var_dump($check);
- }
- $this->boolean($check)->isTrue();
-
- $store = $contrib->store();
- $this->boolean($store)->isTrue();
- }
-
/**
* Test model storage in db
*
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences);
$orig_title = $model->title;
- $this->string($orig_title)->isIdenticalTo('_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}');
+ $this->assertSame('_T("Invoice") {CONTRIBUTION_YEAR}-{CONTRIBUTION_ID}', $orig_title);
$model->title = 'Another test';
- $this->boolean($model->store())->isTrue();
+ $this->assertTrue($model->store());
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences);
- $this->string($model->title)->isIdenticalTo('Another test');
+ $this->assertSame('Another test', $model->title);
}
}