Files
nextcloud-maps/tests/Unit/Helper/ExifGeoDataTest.php
Maximilian Bosch 03cc1dbf05 Bump app to Nextcloud 30
Closes #1333

I decided to not cross-check the availability of all all deprecated
things with older majors, so both min and max version are v30 for now.

A list of all things that I've fixed:

* Deprecated SCSS variables updated as documented in the upgrade notes[1].
* Fixed a bunch of query builder deprecations:
  * $qb->resetQueryParts() is deprecated, one should just create a new
    query-builder object. Done that.
  * Calling `$qb->expr()->andX()` (and `orX()`) with no arguments is
    deprecated. Instead, one should list all arguments in an array and
    pass that to the method. Reworked queries where necessary to do so.
* The PHPUnit version I got by running `make test` downloaded a version
  that prohibits non-static data providers. Made all affected data
  providers static.

With that, everything from `make test` passes in a local dev
installation of Nextcloud 30 except for two tests:

    1) OCA\Maps\Controller\PhotosControllerTest::testAddGetPhotos
    Failed asserting that actual size 0 matches expected size 1.

    /home/ma27/Projects/nextcloud/apps/maps/tests/Unit/Controller/PhotosControllerTest.php:206

    2) OCA\Maps\Controller\TracksControllerTest::testAddGetTracks
    Failed asserting that false matches expected true.

    /home/ma27/Projects/nextcloud/apps/maps/tests/Unit/Controller/TracksControllerTest.php:205

Both tests failed on the previous commit already, so I decided to leave
those for now.

[1] https://docs.nextcloud.com/server/latest/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_30.html#front-end-changes

Signed-off-by: Maximilian Bosch <maximilian@mbosch.me>
2024-10-07 17:26:12 +02:00

100 lines
6.0 KiB
PHP

<?php
namespace OCA\Maps\Helper;
use PHPUnit\Framework\TestCase;
class ExifGeoDataTest extends TestCase {
public static function imageWithDateAndLocationProvider(): array {
return [
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation1.JPG', 1311984000 + 7200, 47.071717, 10.339557],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation2.JPG', 1312156800 + 7200, 46.862350, 10.916452],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation3.JPG', 1312070400 + 7200, 47.069058, 10.329370],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation4.JPG', 1312070400 + 7200, 47.059160, 10.312354],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation5.JPG', 1568101093 + 7200, 47.357735, 11.177585],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation6.JPG', 1577630208 + 3600, 50.083045, 9.986018],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation7.jpg', 1568999599 + 7200, 49.420833, 11.114444],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation8.JPG', 1501431401 + 7200, 45.306983, 10.700902],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation9.JPG', 1302998400 + 7200, 52.363055, 4.903418],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation10.JPG', 1501238375 + 7200, 46.388742, 11.266598],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation11.JPG', 1501567361 + 7200, 44.827830, 10.956387],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation12.JPG', 1501591333 + 7200, 44.528283, 11.262207],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation13.jpg', 1640083235 + 3600, 54.359561, 10.017325],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation14.jpg', 1559327910 + 7200, 52.976844, 12.988281],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation15.jpg', 1559332394 + 7200, 52.983697, 12.935217],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation16.jpeg', 1593458542 + 7200, 62.733947, 6.779617],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation17.jpeg', 1593458620 + 7200, 62.733769, 6.777794],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation18.jpeg', 1596136867 + 7200, 54.350891, 9.903506],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation19.jpeg', 1596136833 + 7200, 54.350894, 9.903505],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation20.jpeg', 1592913150 + 7200, 61.351753, 6.519107],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation21.jpg', 1653565075 + 7200, 48.704331, 8.418475],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation22.jpeg', 1593890841 + 7200, 62.735419, 7.155311],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation23.jpeg', 1592904886 + 7200, 61.217086, 6.558886],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation24.jpeg', 1592677991 + 7200, 60.427481, 6.548446],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation25.jpeg', 1592650395 + 7200, 59.860523, 6.696346],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation26.jpeg', 1592770386 + 7200, 60.594022, 6.581317],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation27.jpeg', 1592654095 + 7200, 60.033561, 6.563068],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation28.jpg', 1595326357 + 7200, 59.852992, 6.714458],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation29.jpg', 1594918175 + 7200, 57.595925, 9.976864],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation30.jpg', 1595418724 + 7200, 60.669492, 6.807386],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation31.jpg', 1594934141 + 7200, 57.801164, 8.314269],
['tests/test_files/Photos/WithDateAndLocation/imageWithDateAndLocation32.jpeg', 1595629060 + 7200, 59.598981, 9.677297],
];
}
/**
* @dataProvider imageWithDateAndLocationProvider
*/
public function testImagesWithDateAndLocation(string $path, int $date, float $lat, float $lng) {
$exif_geo_data = ExifGeoData::get($path);
$exif_geo_data->validate(true);
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
$this->assertEqualsWithDelta($lat, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta($lng, $exif_geo_data->lng, 0.000005);
}
public static function imageWithZeroIslandProvider(): array {
return [
['tests/test_files/Photos/ZeroIsland/imageZeroIsland1.JPG', 1653829180 + 7200],
];
}
/**
* @dataProvider imageWithZeroIslandProvider
*/
public function testImagesWithZeroIslandException(string $path, int $date) {
$this->expectException(ExifDataNoLocationException::class);
$this->expectExceptionMessage('Zero island is not valid');
$exif_geo_data = ExifGeoData::get($path);
$exif_geo_data->validate(true);
}
/**
* @dataProvider imageWithZeroIslandProvider
*/
public function testImagesWithZeroIslandGeoDataNull(string $path, int $date) {
$exif_geo_data = ExifGeoData::get($path);
try {
$exif_geo_data->validate(true);
$this->assertEquals(true, false);
} catch (ExifDataNoLocationException $e) {
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
$this->assertEqualsWithDelta(null, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta(null, $exif_geo_data->lng, 0.000005);
}
}
/**
* @dataProvider imageWithZeroIslandProvider
*/
public function testImagesWithZeroIsland(string $path, int $date) {
$exif_geo_data = ExifGeoData::get($path);
$exif_geo_data->validate(false);
$this->assertEquals($date, $exif_geo_data->dateTaken);
//This is the same upto ~55cm
$this->assertEqualsWithDelta(0.0, $exif_geo_data->lat, 0.000005);
$this->assertEqualsWithDelta(0.0, $exif_geo_data->lng, 0.000005);
}
}