123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832 |
- <?php
- /**
- * ezcDocumentPdfStyleInferenceTests
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- * @package Document
- * @version //autogen//
- * @subpackage Tests
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- */
- /**
- * Test suite for class.
- *
- * @package Document
- * @subpackage Tests
- */
- class ezcDocumentPcssValueParserTests extends ezcTestCase
- {
- protected $document;
- protected $xpath;
- public static function suite()
- {
- return new PHPUnit_Framework_TestSuite( __CLASS__ );
- }
- public static function getMeasureBoxValues()
- {
- return array(
- array(
- "11",
- array(
- 'top' => 11.,
- 'right' => 11.,
- 'bottom' => 11.,
- 'left' => 11.,
- ),
- '11.00mm 11.00mm 11.00mm 11.00mm',
- ),
- array(
- "11pt",
- array(
- 'top' => 3.9,
- 'right' => 3.9,
- 'bottom' => 3.9,
- 'left' => 3.9,
- ),
- '3.88mm 3.88mm 3.88mm 3.88mm',
- ),
- array(
- "11 12",
- array(
- 'top' => 11.,
- 'right' => 12.,
- 'bottom' => 11.,
- 'left' => 12.,
- ),
- '11.00mm 12.00mm 11.00mm 12.00mm',
- ),
- array(
- "11\t \r \n \t12",
- array(
- 'top' => 11.,
- 'right' => 12.,
- 'bottom' => 11.,
- 'left' => 12.,
- ),
- '11.00mm 12.00mm 11.00mm 12.00mm',
- ),
- array(
- "11 12 13",
- array(
- 'top' => 11.,
- 'right' => 12.,
- 'bottom' => 13.,
- 'left' => 12.,
- ),
- '11.00mm 12.00mm 13.00mm 12.00mm',
- ),
- array(
- "11 12 13 14",
- array(
- 'top' => 11.,
- 'right' => 12.,
- 'bottom' => 13.,
- 'left' => 14.,
- ),
- '11.00mm 12.00mm 13.00mm 14.00mm'
- ),
- array(
- "11mm 12in 13px 14pt",
- array(
- 'top' => 11.,
- 'right' => 304.8,
- 'bottom' => 4.6,
- 'left' => 4.94,
- ),
- '11.00mm 304.80mm 4.59mm 4.94mm',
- ),
- );
- }
- /**
- * @dataProvider getMeasureBoxValues
- */
- public function testMeasureBoxValueHandler( $input, $expectation, $string )
- {
- $value = new ezcDocumentPcssStyleMeasureBoxValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid box measures read.', .1
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid measure box string serialization.'
- );
- }
- public static function getColorValues()
- {
- return array(
- array(
- "#000000",
- array(
- 'red' => 0.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- '#000000',
- ),
- array(
- "#ffffff",
- array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- '#ffffff',
- ),
- array(
- "#babdb6",
- array(
- 'red' => .73,
- 'green' => .74,
- 'blue' => .71,
- 'alpha' => 0.,
- ),
- '#babdb6',
- ),
- array(
- "#babdb6b0",
- array(
- 'red' => .73,
- 'green' => .74,
- 'blue' => .71,
- 'alpha' => .69,
- ),
- '#babdb6b0',
- ),
- array(
- "#BABDB6",
- array(
- 'red' => .73,
- 'green' => .74,
- 'blue' => .71,
- 'alpha' => 0.,
- ),
- '#babdb6',
- ),
- array(
- "#000",
- array(
- 'red' => 0.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- '#000000',
- ),
- array(
- "#fff",
- array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- '#ffffff',
- ),
- array(
- "#bad",
- array(
- 'red' => .73,
- 'green' => .67,
- 'blue' => .87,
- 'alpha' => 0.,
- ),
- '#bbaadd',
- ),
- array(
- "#bad6",
- array(
- 'red' => .73,
- 'green' => .67,
- 'blue' => .87,
- 'alpha' => .4,
- ),
- '#bbaadd66',
- ),
- array(
- "#BAD",
- array(
- 'red' => .73,
- 'green' => .67,
- 'blue' => .87,
- 'alpha' => 0.,
- ),
- '#bbaadd',
- ),
- array(
- "rgb( 0, 255, 9823 )",
- array(
- 'red' => .0,
- 'green' => 1.,
- 'blue' => .37,
- 'alpha' => 0.,
- ),
- '#00ff5f',
- ),
- array(
- " RGB ( 0 , 10 , 127 ) ",
- array(
- 'red' => .0,
- 'green' => .04,
- 'blue' => .5,
- 'alpha' => 0.,
- ),
- '#000a7f',
- ),
- array(
- "rgba( 0, 255, 1023, 127 )",
- array(
- 'red' => .0,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => .5,
- ),
- '#00ffff7f',
- ),
- array(
- " RGBA ( 12 , 23 , 1023 , 12 ) ",
- array(
- 'red' => .05,
- 'green' => .1,
- 'blue' => 1.,
- 'alpha' => .05,
- ),
- '#0c17ff0c',
- ),
- array(
- "transparent",
- array(
- 'red' => 0.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 1.,
- ),
- '#000000ff',
- ),
- array(
- "none",
- array(
- 'red' => 0.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 1.,
- ),
- '#000000ff',
- ),
- );
- }
- /**
- * @dataProvider getColorValues
- */
- public function testColorValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleColorValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid color values read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid color string serialization.'
- );
- }
- public function testInvalidColorSpecification()
- {
- try {
- $value = new ezcDocumentPcssStyleColorValue();
- $value->parse( 'something invalid' );
- $this->fail( 'Expected ezcDocumentParserException.' );
- } catch ( ezcDocumentParserException $e )
- { /* Expected */ }
- }
- public static function getLineStyleValues()
- {
- return array(
- array(
- "solid",
- "solid",
- 'solid',
- ),
- array(
- " dotted ",
- 'dotted',
- 'dotted',
- ),
- array(
- "\t\ngroove\r",
- 'groove',
- 'groove',
- ),
- );
- }
- /**
- * @dataProvider getLineStyleValues
- */
- public function testLineValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleLineValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid style style value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid style style string serialization.'
- );
- }
- public static function getBorderStyleValues()
- {
- return array(
- array(
- "1mm",
- array(
- 'width' => 1,
- 'style' => 'solid',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- ),
- '1.00mm solid #ffffff',
- ),
- array(
- "dashed",
- array(
- 'width' => 0,
- 'style' => 'dashed',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- ),
- '0.00mm dashed #ffffff',
- ),
- array(
- "rgb( 255, 0, 0 )",
- array(
- 'width' => 0,
- 'style' => 'solid',
- 'color' => array(
- 'red' => 1.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- '0.00mm solid #ff0000',
- ),
- array(
- "1pt #F00",
- array(
- 'width' => .35,
- 'style' => 'solid',
- 'color' => array(
- 'red' => 1.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- '0.35mm solid #ff0000',
- ),
- array(
- "1 inset #0f0",
- array(
- 'width' => 1.,
- 'style' => 'inset',
- 'color' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- '1.00mm inset #00ff00',
- ),
- );
- }
- /**
- * @dataProvider getBorderStyleValues
- */
- public function testBorderValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleBorderValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid border style value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid border style string serialization.'
- );
- }
- public static function getColorBoxStyleValues()
- {
- return array(
- array(
- "#0f0 #ff0000 rgb( 0, 0, 255 )",
- array(
- 'top' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- 'right' => array(
- 'red' => 1.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- 'bottom' => array(
- 'red' => 0.,
- 'green' => 0.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- 'left' => array(
- 'red' => 1.,
- 'green' => 0.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- '#00ff00 #ff0000 #0000ff #ff0000',
- ),
- array(
- "#fF0",
- array(
- 'top' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- 'right' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- 'bottom' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- 'left' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- '#ffff00 #ffff00 #ffff00 #ffff00',
- ),
- );
- }
- /**
- * @dataProvider getColorBoxStyleValues
- */
- public function testColorBoxValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleColorBoxValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid color value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid color box string serialization.'
- );
- }
- public static function getLineBoxStyleValues()
- {
- return array(
- array(
- "solid double outset",
- array(
- 'top' => 'solid',
- 'right' => 'double',
- 'bottom' => 'outset',
- 'left' => 'double',
- ),
- 'solid double outset double',
- ),
- array(
- "inset",
- array(
- 'top' => 'inset',
- 'right' => 'inset',
- 'bottom' => 'inset',
- 'left' => 'inset',
- ),
- 'inset inset inset inset',
- ),
- );
- }
- /**
- * @dataProvider getLineBoxStyleValues
- */
- public function testLineBoxValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleLineBoxValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid style value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid style box string serialization.'
- );
- }
- public static function getBorderBoxStyleValues()
- {
- return array(
- array(
- "1 inset #0f0",
- array(
- 'top' => array(
- 'width' => 1.,
- 'style' => 'inset',
- 'color' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- 'right' => array(
- 'width' => 1.,
- 'style' => 'inset',
- 'color' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- 'bottom' => array(
- 'width' => 1.,
- 'style' => 'inset',
- 'color' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- 'left' => array(
- 'width' => 1.,
- 'style' => 'inset',
- 'color' => array(
- 'red' => 0.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- ),
- '1.00mm inset #00ff00 1.00mm inset #00ff00 1.00mm inset #00ff00 1.00mm inset #00ff00',
- ),
- array(
- "1mm #fF0 outset 2mm",
- array(
- 'top' => array(
- 'width' => 1.,
- 'style' => 'solid',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 0.,
- 'alpha' => 0.,
- ),
- ),
- 'right' => array(
- 'width' => 0.,
- 'style' => 'outset',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- ),
- 'bottom' => array(
- 'width' => 2.,
- 'style' => 'solid',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- ),
- 'left' => array(
- 'width' => 0.,
- 'style' => 'outset',
- 'color' => array(
- 'red' => 1.,
- 'green' => 1.,
- 'blue' => 1.,
- 'alpha' => 0.,
- ),
- ),
- ),
- '1.00mm solid #ffff00 0.00mm outset #ffffff 2.00mm solid #ffffff 0.00mm outset #ffffff',
- ),
- );
- }
- /**
- * @dataProvider getBorderBoxStyleValues
- */
- public function testBorderBoxValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleBorderBoxValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid border style value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid border style string serialization.'
- );
- }
- public static function getUrlStyleValues()
- {
- return array(
- array(
- "url( foo.ttf )",
- array(
- "foo.ttf"
- ),
- "url( foo.ttf )",
- ),
- array(
- "url(foo.ttf),local(font.pfb),url(/some/../path/to/font.foo)",
- array(
- "foo.ttf",
- "font.pfb",
- "/some/../path/to/font.foo",
- ),
- "url( foo.ttf ), url( font.pfb ), url( /some/../path/to/font.foo )",
- ),
- );
- }
- /**
- * @dataProvider getUrlStyleValues
- */
- public function testSrcValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleSrcValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Invalid src style value read.', .01
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid src style string serialization.'
- );
- }
- public static function getListStyleValues()
- {
- return array(
- array(
- 'single',
- array( 'single' ),
- 'single'
- ),
- array(
- 'single ',
- array( 'single' ),
- 'single'
- ),
- array(
- 'first second',
- array( 'first', 'second' ),
- 'first second'
- ),
- array(
- 'first second ',
- array( 'first', 'second' ),
- 'first second'
- ),
- array(
- ' first second ',
- array( 'first', 'second' ),
- 'first second'
- ),
- array(
- ' first second third',
- array( 'first', 'second', 'third' ),
- 'first second third'
- ),
- );
- }
- /**
- * @dataProvider getListStyleValues
- */
- public function testListValueHandler( $input, $expectation, $string = '' )
- {
- $value = new ezcDocumentPcssStyleListValue();
- $value->parse( $input );
- $this->assertEquals(
- $expectation,
- $value->value,
- 'Incorrect list value read.'
- );
- $this->assertEquals(
- $string,
- (string) $value,
- 'Invalid list value string serialization.'
- );
- }
- }
- ?>
|