Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Mar 26, 2023
1 parent 92c77d6 commit c164978
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 75 deletions.
4 changes: 4 additions & 0 deletions galette/lib/Galette/Core/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public function __construct($dsn = null)
'password' => $_pwd_db,
'database' => $_name_db
);
if (defined('GALETTE_TESTS')){
$this->options['driver_options'][\PDO::ATTR_PERSISTENT] = true;
$this->options['driver_options'][\PDO::ATTR_ERRMODE] = \PDO::ERRMODE_EXCEPTION;
}
if ($_type_db === self::MYSQL && !defined('NON_UTF_DBCONNECT')) {
$this->options['charset'] = 'utf8';
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Galette/Core/tests/units/Galette.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ public function testSerialization()
*/
public function testGetMenus()
{
global $preferences, $login;
global $preferences, $login, $plugins;
$db = new \Galette\Core\Db();
$plugins = new \Galette\Core\Plugins($db);
$preferences = $this->getMockBuilder(\Galette\Core\Preferences::class)
->setConstructorArgs(array($db))
->onlyMethods(array('showPublicPages'))
Expand Down
11 changes: 5 additions & 6 deletions tests/Galette/Core/tests/units/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function tearDown(): void
$delete = $this->zdb->delete(\Galette\Core\Links::TABLE);
$this->zdb->execute($delete);

$this->cleanHistory();
parent::tearDown();
}

Expand All @@ -125,15 +124,15 @@ public function testGenerateNewLink()
$this->assertSame(1, $results->count());

$this->assertSame(
$links->isHashValid($res, 'phoarau@tele2.fr'),
$links->isHashValid($res, $this->adh->getEmail()),
[
\Galette\Core\Links::TARGET_MEMBERCARD,
$id
]
);

$this->assertFalse($links->isHashValid($res, 'any@mail.com'));
$this->assertFalse($links->isHashValid(base64_encode('sthingthatisnotahash'), 'phoarau@tele2.fr'));
$this->assertFalse($links->isHashValid(base64_encode('sthingthatisnotahash'), $this->adh->getEmail()));

$this->createContribution();
$cid = $this->contrib->id;
Expand All @@ -144,7 +143,7 @@ public function testGenerateNewLink()

$this->assertNotEmpty($res);
$this->assertSame(
$links->isHashValid($res, 'phoarau@tele2.fr'),
$links->isHashValid($res, $this->adh->getEmail()),
[
\Galette\Core\Links::TARGET_INVOICE,
$cid
Expand All @@ -171,7 +170,7 @@ public function testExpiredValidate()
$this->assertNotEmpty($res);

$this->assertSame(
$links->isHashValid($res, 'phoarau@tele2.fr'),
$links->isHashValid($res, $this->adh->getEmail()),
[
\Galette\Core\Links::TARGET_MEMBERCARD,
$id
Expand All @@ -190,7 +189,7 @@ public function testExpiredValidate()
->where(['hash' => base64_decode($res)]);
$this->zdb->execute($update);

$this->assertFalse($links->isHashValid($res, 'phoarau@tele2.fr'));
$this->assertFalse($links->isHashValid($res, $this->adh->getEmail()));
}

/**
Expand Down
12 changes: 11 additions & 1 deletion tests/Galette/Entity/tests/units/Adherent.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Adherent extends GaletteTestCase
*/
public function tearDown(): void
{
parent::tearDown();
$this->zdb = new \Galette\Core\Db();

$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
Expand All @@ -73,8 +74,17 @@ public function tearDown(): void
$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
$delete->where(['fingerprint' => 'FAKER' . $this->seed]);
$this->zdb->execute($delete);
}

$this->cleanHistory();
/**
* Cleanup after class
*
* @return void
*/
public static function tearDownAfterClass(): void
{
$self = new self(__METHOD__);
$self->tearDown();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Galette/Entity/tests/units/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public function tearDown(): void
$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
$delete->where(['fingerprint' => 'FAKER' . $this->seed]);
$this->zdb->execute($delete);

$this->cleanHistory();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Galette/Entity/tests/units/FieldsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function setUp(): void
{
$this->zdb = new \Galette\Core\Db();

include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
include GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
$this->members_fields = $members_fields;
include_once GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
include GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
$this->members_fields_cats = $members_fields_cats;

$this->fields_config = new \Galette\Entity\FieldsConfig(
Expand Down
4 changes: 2 additions & 2 deletions tests/Galette/Entity/tests/units/ListsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public function setUp(): void
{
$this->zdb = new \Galette\Core\Db();

include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
include GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
$this->members_fields = $members_fields;
include_once GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
include GALETTE_ROOT . 'includes/fields_defs/members_fields_cats.php';
$this->members_fields_cats = $members_fields_cats;

$this->lists_config = new \Galette\Entity\ListsConfig(
Expand Down
50 changes: 2 additions & 48 deletions tests/Galette/Entity/tests/units/PdfModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,32 +320,7 @@ public function testReplacements()
], \ArrayObject::ARRAY_AS_PROPS);
$model = new \Galette\Entity\PdfInvoice($this->zdb, $this->preferences, $rs);

$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',
'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);
Expand Down Expand Up @@ -376,7 +351,7 @@ public function testReplacements()
);

$this->assertSame(
'name: DURAND René login: arthur.hamon birthdate: 1937-12-26 dynlabel: Dynamic text field dynvalue: ' .
'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: 2020-12-03',
Expand All @@ -396,27 +371,6 @@ public function testReplacements()
$this->assertTrue(isset($legend['contribution']['patterns']['label_dynfield_' . $cdf->getId() . '_contrib']));
}

/**
* Create member from data
*
* @param array $data Data to use to create member
*
* @return Adherent
*/
public function createMember(array $data)
{
$adh = $this->adh;
$check = $adh->check($data, [], []);
if (is_array($check)) {
var_dump($check);
}
$this->assertTrue($check);

$store = $adh->store();
$this->assertTrue($store);
return $adh;
}

/**
* Create test contribution in database
*
Expand Down
2 changes: 0 additions & 2 deletions tests/Galette/Entity/tests/units/Social.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public function tearDown(): void
$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
$delete->where(['fingerprint' => 'FAKER' . $this->seed]);
$this->zdb->execute($delete);

$this->cleanHistory();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Galette/Entity/tests/units/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public function tearDown(): void
$delete = $this->zdb->delete(\Galette\Entity\Adherent::TABLE);
$delete->where(['fingerprint' => 'FAKER' . $this->seed]);
$this->zdb->execute($delete);

$this->cleanHistory();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Galette/Util/tests/units/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function testPersonalInformation()
);
$login = new \Galette\Core\Login($this->zdb, $i18n);
$history = new \Galette\Core\History($this->zdb, $login, $this->preferences);
include_once GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
include GALETTE_ROOT . 'includes/fields_defs/members_fields.php';
$members_fields = $members_fields;

$adh = new \Galette\Entity\Adherent($this->zdb);
Expand Down
17 changes: 9 additions & 8 deletions tests/GaletteTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function tearDown(): void
if (TYPE_DB === 'mysql') {
$this->assertSame($this->expected_mysql_warnings, $this->zdb->getWarnings());
}
$this->cleanHistory();
}

/**
Expand Down Expand Up @@ -190,8 +191,8 @@ protected function dataAdherentOne(): array
'ville_adh' => 'Martel',
'cp_adh' => '39 069',
'adresse_adh' => '66, boulevard De Oliveira',
'email_adh' => 'meunier.josephine@ledoux.com',
'login_adh' => 'arthur.hamon',
'email_adh' => 'meunier.josephine' . $this->seed . '@ledoux.com',
'login_adh' => 'arthur.hamon' . $this->seed,
'mdp_adh' => 'J^B-()f',
'mdp_adh2' => 'J^B-()f',
'bool_admin_adh' => false,
Expand Down Expand Up @@ -236,8 +237,8 @@ protected function dataAdherentTwo(): array
'ville_adh' => 'Reynaudnec',
'cp_adh' => '63077',
'adresse_adh' => '2, boulevard Legros',
'email_adh' => 'phoarau@tele2.fr',
'login_adh' => 'nathalie51',
'email_adh' => 'phoarau' . $this->seed . '@tele2.fr',
'login_adh' => 'nathalie51' . $this->seed,
'mdp_adh' => 'T.u!IbKOi|06',
'mdp_adh2' => 'T.u!IbKOi|06',
'bool_admin_adh' => false,
Expand Down Expand Up @@ -309,8 +310,8 @@ protected function checkMemberOneExpected($adh = null, $new_expecteds = [])
'prenom_adh' => 'René',
'ville_adh' => 'Martel',
'adresse_adh' => '66, boulevard De Oliveira',
'email_adh' => 'meunier.josephine@ledoux.com',
'login_adh' => 'arthur.hamon',
'email_adh' => 'meunier.josephine' . $this->seed . '@ledoux.com',
'login_adh' => 'arthur.hamon' . $this->seed,
'mdp_adh' => 'J^B-()f',
'bool_admin_adh' => false,
'bool_exempt_adh' => false,
Expand Down Expand Up @@ -413,8 +414,8 @@ protected function checkMemberTwoExpected($adh = null, $new_expecteds = [])
'ville_adh' => 'Reynaudnec',
'cp_adh' => '63077',
'adresse_adh' => '2, boulevard Legros',
'email_adh' => 'phoarau@tele2.fr',
'login_adh' => 'nathalie51',
'email_adh' => 'phoarau' . $this->seed . '@tele2.fr',
'login_adh' => 'nathalie51' . $this->seed,
'mdp_adh' => 'T.u!IbKOi|06',
'bool_admin_adh' => false,
'bool_exempt_adh' => false,
Expand Down

0 comments on commit c164978

Please sign in to comment.