Skip to content

Commit a2a0272

Browse files
author
Tom Van Herreweghe
committed
Unit test for Native mapper
Signed-off-by: Tom Van Herreweghe <[email protected]>
1 parent 7b16cd4 commit a2a0272

File tree

2 files changed

+170
-1
lines changed

2 files changed

+170
-1
lines changed

tests/PHPExif/Mapper/ExiftoolMapperTest.php

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

0 commit comments

Comments
 (0)