Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 17, 2024
1 parent d040f45 commit b876c62
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,9 @@ jobs:
mysql -e 'use galette_tests; source galette-core/galette/install/scripts/mysql.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
mysql -e 'use galette_tests; source galette-core/galette/plugins/plugin-maps/scripts/mysql.sql;' -u galette_tests --password=g@l3tte -h 127.0.0.1 -P 3306
if: env.skip != 'true' && (startsWith(matrix.db-image, 'mysql') || startsWith(matrix.db-image, 'mariadb'))

- name: Unit tests
if: env.skip != 'true'
run: |
cd galette-core/galette/plugins/plugin-maps
../../vendor/bin/phpunit --test-suffix=.php --bootstrap tests/TestsBootstrap.php --no-coverage --process-isolation tests/GaletteMaps/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ webroot/images/*
!webroot/images/marker-galette.png
!webroot/images/marker-galette-pro.png
tempcache/
tests/coverage/
2 changes: 1 addition & 1 deletion lib/GaletteMaps/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function listCoords(): array
&& !$login->isStaff()
&& !$login->isSuperAdmin()
) {
//limit query to public up to date profiles
//limit query to public up-to-date profiles
$select->where(
array(
new PredicateSet(
Expand Down
88 changes: 88 additions & 0 deletions tests/GaletteMaps/tests/units/Coordinates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GaletteMaps\tests\units;

use Galette\GaletteTestCase;

/**
* Color tests
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/
class Coordinates extends GaletteTestCase
{
protected int $seed = 20240517214956;

/**
* Cleanup after each test method
*
* @return void
*/
public function tearDown(): void
{
$delete = $this->zdb->delete(MAPS_PREFIX . \GaletteMaps\Coordinates::TABLE);
$this->zdb->execute($delete);
parent::tearDown();
}

public function testCoordinates(): void
{
$member = $this->getMemberOne();
$coords = new \GaletteMaps\Coordinates();
$this->assertSame([], $coords->getCoords($member->id));
$this->assertSame([], $coords->listCoords());

$this->logSuperAdmin();
$this->assertSame([], $coords->getCoords($member->id));
$this->assertSame([], $coords->listCoords());

//set coordinates for member one
$this->assertTrue($coords->setCoords($member->id, 50.362038,3.472998));
$this->assertSame(
[
'id_adh' => $member->id,
'latitude' => '50.362038',
'longitude' => '3.472998'
],
(array)$coords->getCoords($member->id)
);
$this->assertSame(
[
[
'id_adh' => $member->id,
'lat' => '50.362038',
'lng' => '3.472998',
'name' => 'DURAND René',
'nickname' => 'ubertrand'
]
],
$coords->listCoords()
);

//update coordinates for member one
$this->assertTrue($coords->setCoords($member->id, 51.362038,3.572998));

//remove coordinates for member one
$this->assertTrue($coords->removeCoords($member->id));
$this->assertSame([], $coords->getCoords($member->id));
}
}
32 changes: 32 additions & 0 deletions tests/TestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Bootstrap tests file for Galette Auto plugin
*
* @author Johan Cwiklinski <johan@x-tnd.be>
*/

define('GALETTE_PLUGINS_PATH', __DIR__ . '/../../');
$basepath = '../../../galette/';

include_once '../../../tests/TestsBootstrap.php';
require_once __DIR__ . '/../_config.inc.php';

0 comments on commit b876c62

Please sign in to comment.