|
| 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