Skip to content

Commit 86c4dac

Browse files
author
Tom Van Herreweghe
committed
Unit tests for Exiftool mapper
Signed-off-by: Tom Van Herreweghe <[email protected]>
1 parent 874d645 commit 86c4dac

File tree

2 files changed

+148
-1
lines changed

2 files changed

+148
-1
lines changed

Diff for: lib/PHPExif/Mapper/Exiftool.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class Exiftool implements MapperInterface
6262
self::ARTIST => Exif::AUTHOR,
6363
self::MODEL => Exif::CAMERA,
6464
self::CAPTION => Exif::CAPTION,
65-
self::CAPTIONABSTRACT => Exif::CAPTION,
6665
self::COLORSPACE => Exif::COLORSPACE,
6766
self::COPYRIGHT => Exif::COPYRIGHT,
6867
self::CREATEDATE => Exif::CREATION_DATE,
@@ -84,6 +83,7 @@ class Exiftool implements MapperInterface
8483
self::TITLE => Exif::TITLE,
8584
self::YRESOLUTION => Exif::VERTICAL_RESOLUTION,
8685
self::IMAGEWIDTH => Exif::WIDTH,
86+
self::CAPTIONABSTRACT => Exif::CAPTION,
8787
);
8888

8989
/**

Diff for: tests/PHPExif/Mapper/ExiftoolMapperTest.php

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/**
3+
* @covers \PHPExif\Mapper\Exiftool::<!public>
4+
*/
5+
class ExiftoolMapperTest extends \PHPUnit_Framework_TestCase
6+
{
7+
protected $mapper;
8+
9+
public function setUp()
10+
{
11+
$this->mapper = new \PHPExif\Mapper\Exiftool;
12+
}
13+
14+
/**
15+
* @group mapper
16+
* @covers \PHPExif\Mapper\Exiftool::__construct
17+
*/
18+
public function testMapRawDataImplementsCorrectInterface()
19+
{
20+
$this->assertInstanceOf('\\PHPExif\\Mapper\\MapperInterface', $this->mapper);
21+
}
22+
23+
/**
24+
* @group mapper
25+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
26+
*/
27+
public function testMapRawDataIgnoresFieldIfItDoesntExist()
28+
{
29+
$rawData = array('foo' => 'bar');
30+
$mapped = $this->mapper->mapRawData($rawData);
31+
32+
$this->assertCount(0, $mapped);
33+
}
34+
35+
/**
36+
* @group mapper
37+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
38+
*/
39+
public function testMapRawDataMapsFieldsCorrectly()
40+
{
41+
$reflProp = new \ReflectionProperty(get_class($this->mapper), 'map');
42+
$reflProp->setAccessible(true);
43+
$map = $reflProp->getValue($this->mapper);
44+
45+
// ignore custom formatted data stuff:
46+
unset($map[\PHPExif\Mapper\Exiftool::APERTURE]);
47+
unset($map[\PHPExif\Mapper\Exiftool::APPROXIMATEFOCUSDISTANCE]);
48+
unset($map[\PHPExif\Mapper\Exiftool::CREATEDATE]);
49+
unset($map[\PHPExif\Mapper\Exiftool::EXPOSURETIME]);
50+
unset($map[\PHPExif\Mapper\Exiftool::FOCALLENGTH]);
51+
52+
// create raw data
53+
$keys = array_keys($map);
54+
$values = array();
55+
$values = array_pad($values, count($keys), 'foo');
56+
$rawData = array_combine($keys, $values);
57+
58+
59+
$mapped = $this->mapper->mapRawData($rawData);
60+
61+
$i = 0;
62+
foreach ($mapped as $key => $value) {
63+
$this->assertEquals($map[$keys[$i]], $key);
64+
$i++;
65+
}
66+
}
67+
68+
/**
69+
* @group mapper
70+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
71+
*/
72+
public function testMapRawDataCorrectlyFormatsAperture()
73+
{
74+
$rawData = array(
75+
\PHPExif\Mapper\Exiftool::APERTURE => 0.123,
76+
);
77+
78+
$mapped = $this->mapper->mapRawData($rawData);
79+
80+
$this->assertEquals('f/0.1', reset($mapped));
81+
}
82+
83+
/**
84+
* @group mapper
85+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
86+
*/
87+
public function testMapRawDataCorrectlyFormatsFocusDistance()
88+
{
89+
$rawData = array(
90+
\PHPExif\Mapper\Exiftool::APPROXIMATEFOCUSDISTANCE => 50,
91+
);
92+
93+
$mapped = $this->mapper->mapRawData($rawData);
94+
95+
$this->assertEquals('50m', reset($mapped));
96+
}
97+
98+
/**
99+
* @group mapper
100+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
101+
*/
102+
public function testMapRawDataCorrectlyFormatsCreationDate()
103+
{
104+
$rawData = array(
105+
\PHPExif\Mapper\Exiftool::CREATEDATE => '2015:04:01 12:11:09',
106+
);
107+
108+
$mapped = $this->mapper->mapRawData($rawData);
109+
110+
$result = reset($mapped);
111+
$this->assertInstanceOf('\\DateTime', $result);
112+
$this->assertEquals(
113+
reset($rawData),
114+
$result->format('Y:m:d H:i:s')
115+
);
116+
}
117+
118+
/**
119+
* @group mapper
120+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
121+
*/
122+
public function testMapRawDataCorrectlyFormatsExposureTime()
123+
{
124+
$rawData = array(
125+
\PHPExif\Mapper\Exiftool::EXPOSURETIME => 1/400,
126+
);
127+
128+
$mapped = $this->mapper->mapRawData($rawData);
129+
130+
$this->assertEquals('1/400', reset($mapped));
131+
}
132+
133+
/**
134+
* @group mapper
135+
* @covers \PHPExif\Mapper\Exiftool::mapRawData
136+
*/
137+
public function testMapRawDataCorrectlyFormatsFocalLength()
138+
{
139+
$rawData = array(
140+
\PHPExif\Mapper\Exiftool::FOCALLENGTH => '15 m',
141+
);
142+
143+
$mapped = $this->mapper->mapRawData($rawData);
144+
145+
$this->assertEquals(15, reset($mapped));
146+
}
147+
}

0 commit comments

Comments
 (0)