Completed
Push — develop ( 0477e6...7aa623 )
by Adrien
19:00
created

XEEValidatorTest::providerInvalidSimpleXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Cell\DataType;
6
use PhpOffice\PhpSpreadsheet\Reader\BaseReader;
7
use PhpOffice\PhpSpreadsheet\Reader\Xml;
8
use PhpOffice\PhpSpreadsheet\Spreadsheet;
9
use PHPUnit_Framework_TestCase;
10
11
class XEEValidatorTest extends PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var Spreadsheet
15
     */
16
    private $spreadsheetXEETest;
17
18
    /**
19
     * @return Spreadsheet
20
     */
21
    protected function loadXEETestFile()
22
    {
23
        if (!$this->spreadsheetXEETest) {
24
            $filename = '../samples/templates/Excel2003XMLTest.xml';
25
26
            // Load into this instance
27
            $reader = new Xml();
28
            $this->spreadsheetXEETest = $reader->load($filename);
29
        }
30
31
        return $this->spreadsheetXEETest;
32
    }
33
34
    /**
35
     * @dataProvider providerInvalidXML
36
     * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
37
     *
38
     * @param mixed $filename
39
     */
40
    public function testInvalidXML($filename)
41
    {
42
        $reader = $this->getMockForAbstractClass(BaseReader::class);
43
        $expectedResult = 'FAILURE: Should throw an Exception rather than return a value';
44
        $result = $reader->securityScanFile($filename);
45
        self::assertEquals($expectedResult, $result);
46
    }
47
48 View Code Duplication
    public function providerInvalidXML()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $tests = [];
51
        foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidUTF*.xml') as $file) {
52
            $tests[basename($file)] = [realpath($file)];
53
        }
54
55
        return $tests;
56
    }
57
58
    /**
59
     * @dataProvider providerInvalidSimpleXML
60
     * @expectedException \PhpOffice\PhpSpreadsheet\Reader\Exception
61
     *
62
     * @param $filename
63
     */
64
    public function testInvalidSimpleXML($filename)
65
    {
66
        $xmlReader = new Xml();
67
        $xmlReader->trySimpleXMLLoadString($filename);
68
    }
69
70 View Code Duplication
    public function providerInvalidSimpleXML()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $tests = [];
73
        foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestInvalidSimpleXML*.xml') as $file) {
74
            $tests[basename($file)] = [realpath($file)];
75
        }
76
77
        return $tests;
78
    }
79
80
    /**
81
     * @dataProvider providerValidXML
82
     *
83
     * @param mixed $filename
84
     * @param mixed $expectedResult
85
     */
86
    public function testValidXML($filename, $expectedResult)
87
    {
88
        $reader = $this->getMockForAbstractClass(BaseReader::class);
89
        $result = $reader->securityScanFile($filename);
90
        self::assertEquals($expectedResult, $result);
91
    }
92
93 View Code Duplication
    public function providerValidXML()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $tests = [];
96
        foreach (glob(__DIR__ . '/../../data/Reader/XEE/XEETestValid*.xml') as $file) {
97
            $tests[basename($file)] = [realpath($file), file_get_contents($file)];
98
        }
99
100
        return $tests;
101
    }
102
103
    /**
104
     * Check if it can read XML Hyperlink correctly.
105
     */
106 View Code Duplication
    public function testReadHyperlinks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        $spreadsheet = $this->loadXEETestFile();
109
        $firstSheet = $spreadsheet->getSheet(0);
110
111
        $hyperlink = $firstSheet->getCell('L1');
112
113
        self::assertEquals(DataType::TYPE_STRING, $hyperlink->getDataType());
114
        self::assertEquals('PhpSpreadsheet', $hyperlink->getValue());
115
        self::assertEquals('http://phpspreadsheet.readthedocs.io/', $hyperlink->getHyperlink()->getUrl());
116
    }
117
}
118