Skip to content

Commit 3bf399f

Browse files
author
Marek Szymczuk
committed
Updated tests.
1 parent 8311c7a commit 3bf399f

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

lib/PHPExif/Mapper/Native.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ protected function extractGPSCoordinate(array $components)
219219
{
220220
$components = array_map(array($this, 'normalizeGPSComponent'), $components);
221221

222-
return intval($components[0]) + (intval($components[1]) / 60) + (floatval($components[2]) / 3600);
222+
if (count($components) > 2) {
223+
return intval($components[0]) + (intval($components[1]) / 60) + (floatval($components[2]) / 3600);
224+
}
225+
226+
return reset($components);
223227
}
224228

225229
/**
@@ -232,14 +236,14 @@ protected function normalizeGPSComponent($component)
232236
{
233237
$parts = explode('/', $component);
234238

235-
if (count($parts) > 0) {
239+
if (count($parts) > 1) {
236240
if ($parts[1]) {
237-
return (int) $parts[0] / (int) $parts[1];
241+
return intval($parts[0]) / intval($parts[1]);
238242
}
239243

240244
return 0;
241245
}
242246

243-
return $parts[0];
247+
return floatval(reset($parts));
244248
}
245249
}

tests/PHPExif/Mapper/ExiftoolMapperTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public function testMapRawDataCorrectlyFormatsCreationDate()
116116
);
117117
}
118118

119+
/**
120+
* @group mapper
121+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
122+
*/
123+
public function testMapRawDataCorrectlyIgnoresIncorrectCreationDate()
124+
{
125+
$rawData = array(
126+
\PHPExif\Mapper\Exiftool::CREATEDATE => '2015:04:01',
127+
);
128+
129+
$mapped = $this->mapper->mapRawData($rawData);
130+
131+
$this->assertEquals(false, reset($mapped));
132+
}
133+
119134
/**
120135
* @group mapper
121136
* @covers \PHPExif\Mapper\Exiftool::mapRawData

tests/PHPExif/Mapper/NativeMapperTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ public function testMapRawDataCorrectlyFormatsDateTimeOriginal()
8686
);
8787
}
8888

89+
/**
90+
* @group mapper
91+
* @covers \PHPExif\Mapper\Native::mapRawData
92+
*/
93+
public function testMapRawDataCorrectlyIgnoresIncorrectDateTimeOriginal()
94+
{
95+
$rawData = array(
96+
\PHPExif\Mapper\Native::DATETIMEORIGINAL => '2015:04:01',
97+
);
98+
99+
$mapped = $this->mapper->mapRawData($rawData);
100+
101+
$this->assertEquals(false, reset($mapped));
102+
}
103+
89104
/**
90105
* @group mapper
91106
* @covers \PHPExif\Mapper\Native::mapRawData
@@ -188,6 +203,12 @@ public function testMapRawDataCorrectlyFormatsGPSData()
188203
'GPSLongitude' => array('0/0', '0/0', '0/0'),
189204
'GPSLongitudeRef' => 'W',
190205
),
206+
'71.706936,-42.604303' => array(
207+
'GPSLatitude' => array('71.706936'),
208+
'GPSLatitudeRef' => 'N',
209+
'GPSLongitude' => array('42.604303'),
210+
'GPSLongitudeRef' => 'W',
211+
),
191212
);
192213

193214
foreach ($expected as $key => $value) {

0 commit comments

Comments
 (0)