Skip to content

Commit

Permalink
Travis 5.3 test (#46)
Browse files Browse the repository at this point in the history
* add the PHP 5.3 in Travis Build.
* Fix some issues for the source code when running the PHP 5.3 Travis build.
  • Loading branch information
peter279k authored and meyfa committed Mar 1, 2018
1 parent 1da1bbc commit e309858
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ php:
- 7.0
- 7.1
- 7.2
matrix:
include:
- php: 5.3
dist: precise
install:
- composer install --no-interaction
script: vendor/bin/phpunit --configuration .phpunit.xml
4 changes: 2 additions & 2 deletions src/Utilities/SVGStyleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public static function parseStyles($string)
*/
public static function parseCss($css)
{
$result = [];
$result = array();
preg_match_all('/(?ims)([a-z0-9\s\,\.\:#_\-@^*()\[\]\"\'=]+)\{([^\}]*)\}/', $css, $arr);

foreach ($arr[0] as $i => $x) {
$selectors = explode(',', trim($arr[1][$i]));
if (in_array($selectors[0], ['@font-face', '@keyframes', '@media'])) {
if (in_array($selectors[0], array('@font-face', '@keyframes', '@media'))) {
continue;
}
$rules = self::parseStyles(trim($arr[2][$i]));
Expand Down
3 changes: 2 additions & 1 deletion src/Writing/SVGWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SVGWriter
public function __construct()
{
$this->outString = '<?xml version="1.0" encoding="utf-8"?>';
defined('ENT_XML1') ? ENT_XML1 : define('ENT_XML1', 16);
}

/**
Expand Down Expand Up @@ -120,7 +121,7 @@ private function appendAttributes(array $attrs)
* @return void
*/
private function appendAttribute($attrName, $attrValue)
{
{
$attrName = htmlspecialchars($attrName, ENT_XML1 | ENT_COMPAT);
$attrValue = htmlspecialchars($attrValue, ENT_XML1 | ENT_COMPAT);

Expand Down
44 changes: 29 additions & 15 deletions tests/Nodes/SVGNodeContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,27 @@ public function testRasterize()
public function testGetElementsByTagName()
{
$obj = new SVGNodeContainerSubclass();
$root_0 = new \SVG\Nodes\Structures\SVGGroup();
$root_0_0 = new \SVG\Nodes\Shapes\SVGLine();
$root_0_1 = new \SVG\Nodes\Shapes\SVGRect();
$obj->addChild(
$root_0 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_0_0 = new \SVG\Nodes\Shapes\SVGLine()
$root_0->addChild(
$root_0_0
)->addChild(
$root_0_1 = new \SVG\Nodes\Shapes\SVGRect()
$root_0_1
)
);
$root_1 = new \SVG\Nodes\Structures\SVGGroup();
$root_1_0 = new \SVG\Nodes\Structures\SVGGroup();
$root_1_0_0 = new \SVG\Nodes\Shapes\SVGRect();
$root_1_1 = new \SVG\Nodes\Shapes\SVGRect();
$obj->addChild(
$root_1 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_1_0 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_1_0_0 = new \SVG\Nodes\Shapes\SVGRect()
$root_1->addChild(
$root_1_0->addChild(
$root_1_0_0
)
)->addChild(
$root_1_1 = new \SVG\Nodes\Shapes\SVGRect()
$root_1_1
)
);

Expand All @@ -122,21 +129,28 @@ public function testGetElementsByTagName()

public function testGetElementsByClassName()
{
$obj = (new SVGNodeContainerSubclass());
$obj = new SVGNodeContainerSubclass();
$root_0 = new \SVG\Nodes\Structures\SVGGroup();
$root_0_0 = new \SVG\Nodes\Shapes\SVGRect();
$root_0_1 = new \SVG\Nodes\Shapes\SVGRect();
$obj->addChild(
$root_0 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_0_0 = new \SVG\Nodes\Shapes\SVGRect()
$root_0->addChild(
$root_0_0
)->addChild(
$root_0_1 = new \SVG\Nodes\Shapes\SVGRect()
$root_0_1
)
);
$root_1 = new \SVG\Nodes\Structures\SVGGroup();
$root_1_0 = new \SVG\Nodes\Structures\SVGGroup();
$root_1_0_0 = new \SVG\Nodes\Shapes\SVGRect();
$root_1_1 = new \SVG\Nodes\Shapes\SVGRect();
$obj->addChild(
$root_1 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_1_0 = (new \SVG\Nodes\Structures\SVGGroup())->addChild(
$root_1_0_0 = new \SVG\Nodes\Shapes\SVGRect()
$root_1->addChild(
$root_1_0->addChild(
$root_1_0_0
)
)->addChild(
$root_1_1 = new \SVG\Nodes\Shapes\SVGRect()
$root_1_1
)
);

Expand Down
10 changes: 10 additions & 0 deletions tests/Nodes/Shapes/SVGPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public function testSetDescription()
$this->assertSame(self::$sampleDescription, $obj->getAttribute('d'));
}

public function testRasterizeWithNull()
{
$rast = $this->getMockBuilder('\SVG\Rasterization\SVGRasterizer')
->disableOriginalConstructor()
->getMock();
$obj = new SVGPath();

$this->assertNull($obj->rasterize($rast));
}

public function testRasterize()
{
$obj = new SVGPath(self::$sampleDescription);
Expand Down
3 changes: 2 additions & 1 deletion tests/Nodes/Shapes/SVGPolygonalShapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public function testGetPoint()
array(37, 37),
));
$obj->setPoint(1, array(100, 100));
$point = $obj->getPoint(0);

$this->assertSame(42.5, $obj->getPoint(0)[0]);
$this->assertSame(42.5, $point[0]);
}

public function testGetSerializableAttributes()
Expand Down
4 changes: 2 additions & 2 deletions tests/Rasterization/Renderers/SVGImageRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class SVGImageRendererTest extends \PHPUnit\Framework\TestCase
public function testRender()
{
$rast = new \SVG\Rasterization\SVGRasterizer(10, 20, null, 100, 200);
$options = [
$options = array(
'href' => __DIR__.'/../../sample.svg',
'x' => 10.5,
'y' => 10.5,
'width' => 100.5,
'height' => 100.5
];
);
$svgImageRender = new SVGImageRenderer();
$context = new SVGNodeClass();

Expand Down
30 changes: 19 additions & 11 deletions tests/Reading/SVGReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ public function setUp()
public function testShouldReturnAnImageOrNull()
{
// should return an instance of SVGImage
$result = (new SVGReader())->parseString($this->xml);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xml);
$this->assertInstanceOf('\SVG\SVGImage', $result);

// should return null when parsing fails
$result = (new SVGReader())->parseString('<rect />');
$result = $svgReader->parseString('<rect />');
$this->assertNull($result);
}

public function testShouldSetAllAttributesAndNamespaces()
{
// should retain all document attributes and namespaces
$result = (new SVGReader())->parseString($this->xml);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xml);
$this->assertEquals(array(
'xmlns' => 'http://www.w3.org/2000/svg',
'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
Expand All @@ -81,7 +83,8 @@ public function testShouldSetAllAttributesAndNamespaces()
), $result->getDocument()->getSerializableAttributes());

// should deal with missing viewBox
$result = (new SVGReader())->parseString($this->xmlNoViewBox);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xmlNoViewBox);
$this->assertEquals(array(
'xmlns' => 'http://www.w3.org/2000/svg',
'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
Expand All @@ -90,15 +93,17 @@ public function testShouldSetAllAttributesAndNamespaces()
), $result->getDocument()->getSerializableAttributes());

// should deal with missing width/height
$result = (new SVGReader())->parseString($this->xmlNoWH);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xmlNoWH);
$this->assertEquals(array(
'xmlns' => 'http://www.w3.org/2000/svg',
'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
'viewBox' => '10 20 74 84',
), $result->getDocument()->getSerializableAttributes());

// should set all attributes, including namespace prefixed ones
$result = (new SVGReader())->parseString($this->xml);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xml);
$rect = $result->getDocument()->getChild(0);
$this->assertEquals(array(
'id' => 'testrect',
Expand All @@ -109,7 +114,8 @@ public function testShouldSetAllAttributesAndNamespaces()

public function testShouldSetStyles()
{
$result = (new SVGReader())->parseString($this->xml);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xml);
$rect = $result->getDocument()->getChild(0);

// should detect style attributes
Expand All @@ -124,8 +130,8 @@ public function testShouldSetStyles()
public function testShouldRecursivelyAddChildren()
{
// should recursively add all child nodes

$result = (new SVGReader())->parseString($this->xml);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xml);
$g = $result->getDocument()->getChild(1);

$this->assertSame(2, $g->countChildren());
Expand All @@ -149,7 +155,8 @@ public function testShouldRecursivelyAddChildren()
public function testShouldIgnoreUnknownNodes()
{
// should skip unknown node types without failing
$result = (new SVGReader())->parseString($this->xmlUnknown);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xmlUnknown);
$doc = $result->getDocument();
$this->assertSame(2, $doc->countChildren());
$this->assertSame('circle', $doc->getChild(0)->getName());
Expand All @@ -158,7 +165,8 @@ public function testShouldIgnoreUnknownNodes()

public function testShouldDecodeEntities()
{
$result = (new SVGReader())->parseString($this->xmlEntities);
$svgReader = new SVGReader();
$result = $svgReader->parseString($this->xmlEntities);
$doc = $result->getDocument();

// should decode entities in attributes
Expand Down
20 changes: 10 additions & 10 deletions tests/Writing/SVGWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ public function testShouldWriteChildren()
// should write children
$obj = new SVGWriter();
$node = new \SVG\Nodes\Structures\SVGGroup();
$node->addChild(
(new \SVG\Nodes\Structures\SVGGroup())
->addChild(new \SVG\Nodes\Shapes\SVGRect())
);
$childNode = new \SVG\Nodes\Structures\SVGGroup();
$svgRect = new \SVG\Nodes\Shapes\SVGRect();
$childNode->addChild($svgRect);

$node->addChild($childNode);
$obj->writeNode($node);
$expect = $this->xmlDeclaration.'<g><g><rect /></g></g>';
$this->assertEquals($expect, $obj->getString());
Expand All @@ -90,18 +91,17 @@ public function testShouldEncodeEntities()
{
// should encode entities in attributes
$obj = new SVGWriter();
$obj->writeNode(
(new \SVG\Nodes\Structures\SVGGroup())
->setAttribute('id', '" foo&bar>')
->setStyle('content', '" foo&bar>')
);
$svgGroup = new \SVG\Nodes\Structures\SVGGroup();
$svgGroup->setAttribute('id', '" foo&bar>')->setStyle('content', '" foo&bar>');
$obj->writeNode($svgGroup);
$expect = $this->xmlDeclaration.'<g id="&quot; foo&amp;bar&gt;" '.
'style="content: &quot; foo&amp;bar&gt;"></g>';
$this->assertEquals($expect, $obj->getString());

// should encode entities in style body
$obj = new SVGWriter();
$obj->writeNode(new \SVG\Nodes\Structures\SVGStyle('" foo&bar>'));
$svgStyle = new \SVG\Nodes\Structures\SVGStyle('" foo&bar>');
$obj->writeNode($svgStyle);
$expect = $this->xmlDeclaration.'<style type="text/css">'.
'<![CDATA[&quot; foo&amp;bar&gt;]]></style>';
$this->assertEquals($expect, $obj->getString());
Expand Down

0 comments on commit e309858

Please sign in to comment.