Passed
Push — master ( e3bfe5...0c7a8b )
by Johannes
04:20
created

GH_16_Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testThisDoesNotWorkAsExpected() 0 37 4
A tearDown() 0 3 1
1
<?php
2
/**
3
 * PEL: PHP Exif Library.
4
 * A library with support for reading and
5
 * writing all Exif headers in JPEG and TIFF images using PHP.
6
 *
7
 * Copyright (C) 2004, 2006, 2007 Martin Geisler.
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program in the file COPYING; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22
 * Boston, MA 02110-1301 USA
23
 */
24
namespace Pel\Test;
25
26
use PHPUnit\Framework\TestCase;
27
use lsolesen\pel\PelDataWindow;
28
use lsolesen\pel\PelEntryWindowsString;
29
use lsolesen\pel\PelExif;
30
use lsolesen\pel\PelIfd;
31
use lsolesen\pel\PelJpeg;
32
use lsolesen\pel\PelTag;
33
use lsolesen\pel\PelTiff;
34
35
class GH_16_Test extends TestCase
36
{
37
38
    protected $file;
39
40
    protected function setUp(): void
41
    {
42
        $this->file = dirname(__FILE__) . '/images/gh-16-tmp.jpg';
43
        $file = dirname(__FILE__) . '/images/gh-16.jpg';
44
        copy($file, $this->file);
45
    }
46
47
    public function tearDown(): void
48
    {
49
        unlink($this->file);
50
    }
51
52
    public function testThisDoesNotWorkAsExpected()
53
    {
54
        $subject = "Превед, медвед!";
55
56
        $data = new PelDataWindow(file_get_contents($this->file));
57
58
        $this->assertTrue(PelJpeg::isValid($data));
59
60
        if (PelJpeg::isValid($data)) {
61
            $jpeg = new PelJpeg();
62
            $jpeg->load($data);
63
            $exif = $jpeg->getExif();
64
65
            if (null === $exif) {
66
                $exif = new PelExif();
67
                $jpeg->setExif($exif);
68
                $tiff = new PelTiff();
69
                $exif->setTiff($tiff);
70
            }
71
72
            $tiff = $exif->getTiff();
73
74
            $ifd0 = $tiff->getIfd();
75
            if (null === $ifd0) {
76
                $ifd0 = new PelIfd(PelIfd::IFD0);
77
                $tiff->setIfd($ifd0);
78
            }
79
            $ifd0->addEntry(new PelEntryWindowsString(PelTag::XP_SUBJECT, $subject));
80
81
            file_put_contents($this->file, $jpeg->getBytes());
82
83
            $jpeg = new PelJpeg($this->file);
84
            $exif = $jpeg->getExif();
85
            $tiff = $exif->getTiff();
86
            $ifd0 = $tiff->getIfd();
87
            $written_subject = $ifd0->getEntry(PelTag::XP_SUBJECT);
88
            $this->assertEquals($subject, $written_subject->getValue());
89
        }
90
    }
91
}
92