/** * Test function getAttributes() */ public function test_getAttributes() { $xmlCode = '<test attr1="1" attr2="22" attr3="333" attr4="4444" attr5="55555"></test>'; $attributes = array(); $found = XMLUtil::getAttributes($attributes, $xmlCode); $this->assertEquals(5, $found); $this->assertEquals('1', $attributes['attr1']); $this->assertEquals('22', $attributes['attr2']); $this->assertEquals('333', $attributes['attr3']); $this->assertEquals('4444', $attributes['attr4']); $this->assertEquals('55555', $attributes['attr5']); }
/** * Test setProperty() and toString(), including tab-stops. * This is a test case for issue #123. */ public function test_set_toc_paragraph() { $indent = 2; $properties = array(); $properties['style-name'] = 'TOC-Test'; $properties['style-parent'] = 'Index'; $properties['style-class'] = 'index'; $properties['style-position'] = 17 - $indent . 'cm'; $properties['style-type'] = 'right'; $properties['style-leader-style'] = 'dotted'; $properties['style-leader-text'] = '.'; $properties['margin-left'] = $indent . 'cm'; $properties['margin-right'] = '0cm'; $properties['text-indent'] = '0cm'; // This variable is just used to show the expected result but is not used for test comparsion. // We explicitly parse the exported XML code to be independent from attributes position. // The attrbitues positions might change in the future if ODTParagraphStyle.php is changed. $expected = '<style:style style:name="TOC-Test" style:parent-style-name="Index" style:class="index" style:family="paragraph" >'; $expected .= '<style:paragraph-properties fo:margin-left="2cm" fo:margin-right="0cm" fo:text-indent="0cm" >'; $expected .= '<style:tab-stops>'; $expected .= '<style:tab-stop style:position="15cm" style:type="right" style:leader-style="dotted" style:leader-text="." />'; $expected .= '</style:tab-stops>'; $expected .= '</style:paragraph-properties>'; $expected .= '</style:style>'; // Create style, set all properties and get XML code of the style $style = new ODTParagraphStyle(); $this->assertNotNull($style); foreach ($properties as $key => $value) { $style->setProperty($key, $value); } $style_string = $style->toString(); // We should have the following elements: // style:style, style:paragraph-properties, style:text-properties, style:tab-stops $style_style = XMLUtil::getElementOpenTag('style:style', $style_string); $this->assertNotNull($style_style); $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string); $paragraph = XMLUtil::getElement('style:paragraph-properties', $style_string); $this->assertNotNull($paragraph_props); $tab_stops_props = XMLUtil::getElement('style:tab-stops', $paragraph); $this->assertNotNull($tab_stops_props); $tab_stop_props = XMLUtil::getElementOpenTag('style:tab-stop', $tab_stops_props); $this->assertNotNull($tab_stop_props); // Check attribute values of element "style:style", see $expected // Remark: attribute 'style:family' must always be present even if it was not set $attributes = array(); $found = XMLUtil::getAttributes($attributes, $style_style); $this->assertEquals(4, $found); $this->assertEquals('TOC-Test', $attributes['style:name']); $this->assertEquals('Index', $attributes['style:parent-style-name']); $this->assertEquals('index', $attributes['style:class']); $this->assertEquals('paragraph', $attributes['style:family']); // Check attribute values of element "style:paragraph-properties", see $expected $attributes = array(); $found = XMLUtil::getAttributes($attributes, $paragraph_props); $this->assertEquals(3, $found); $this->assertEquals('2cm', $attributes['fo:margin-left']); $this->assertEquals('0cm', $attributes['fo:margin-right']); $this->assertEquals('0cm', $attributes['fo:text-indent']); // Check attribute values of element "style:tab-stop", see $expected $attributes = array(); $found = XMLUtil::getAttributes($attributes, $tab_stop_props); $this->assertEquals(4, $found); $this->assertEquals('15cm', $attributes['style:position']); $this->assertEquals('right', $attributes['style:type']); $this->assertEquals('dotted', $attributes['style:leader-style']); $this->assertEquals('.', $attributes['style:leader-text']); }
/** * Test setProperty() and toString(). * This is a test case for issue #120. */ public function test_set_and_to_string() { $properties = array(); $properties['style-name'] = 'Heading'; $properties['style-parent'] = 'Standard'; $properties['style-class'] = 'text'; $properties['style-next'] = 'Text_20_body'; $properties['margin-top'] = '0.423cm'; $properties['margin-bottom'] = '0.212cm'; $properties['keep-with-next'] = 'always'; $properties['font-size'] = '14pt'; $properties['font-size-asian'] = '14pt'; $properties['font-size-complex'] = '14pt'; $properties['font-name'] = 'Bitstream Vera Sans1'; $properties['font-name-asian'] = 'Bitstream Vera Sans2'; $properties['font-name-complex'] = 'Bitstream Vera Sans2'; $expected = '<style:style style:name="Heading" style:parent-style-name="Standard" style:class="text" style:next-style-name="Text_20_body" style:family="paragraph" >' . "\n"; $expected .= '<style:paragraph-properties fo:margin-top="0.423cm" fo:margin-bottom="0.212cm" fo:keep-with-next="always" />' . "\n"; $expected .= '<style:text-properties fo:font-size="14pt" style:font-size-asian="14pt" style:font-size-complex="14pt" style:font-name="Bitstream Vera Sans1" style:font-name-asian="Bitstream Vera Sans2" style:font-name-complex="Bitstream Vera Sans2" />' . "\n"; $expected .= '</style:style>' . "\n"; $style = new ODTParagraphStyle(); $this->assertNotNull($style); foreach ($properties as $key => $value) { $style->setProperty($key, $value); } $style_string = $style->toString(); // We should have the following elements: // style:style, style:paragraph-properties, style:text-properties $style_style = XMLUtil::getElementOpenTag('style:style', $style_string); $this->assertNotNull($style_style); $paragraph_props = XMLUtil::getElementOpenTag('style:paragraph-properties', $style_string); $this->assertNotNull($paragraph_props); $text_props = XMLUtil::getElementOpenTag('style:text-properties', $style_string); $this->assertNotNull($text_props); // Check attribute values of element "style:style", see $expected // Remark: attribute 'style:family' must always be present even if it was not set $attributes = array(); $found = XMLUtil::getAttributes($attributes, $style_style); $this->assertEquals(5, $found); $this->assertEquals('Heading', $attributes['style:name']); $this->assertEquals('Standard', $attributes['style:parent-style-name']); $this->assertEquals('text', $attributes['style:class']); $this->assertEquals('Text_20_body', $attributes['style:next-style-name']); $this->assertEquals('paragraph', $attributes['style:family']); // Check attribute values of element "style:paragraph-properties", see $expected $attributes = array(); $found = XMLUtil::getAttributes($attributes, $paragraph_props); $this->assertEquals(3, $found); $this->assertEquals('0.423cm', $attributes['fo:margin-top']); $this->assertEquals('0.212cm', $attributes['fo:margin-bottom']); $this->assertEquals('always', $attributes['fo:keep-with-next']); // Check attribute values of element "style:text-properties", see $expected $attributes = array(); $found = XMLUtil::getAttributes($attributes, $text_props); $this->assertEquals(6, $found); $this->assertEquals('14pt', $attributes['fo:font-size']); $this->assertEquals('14pt', $attributes['style:font-size-asian']); $this->assertEquals('14pt', $attributes['style:font-size-complex']); $this->assertEquals('Bitstream Vera Sans1', $attributes['style:font-name']); $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-asian']); $this->assertEquals('Bitstream Vera Sans2', $attributes['style:font-name-complex']); }
/** * This function checks the rendering of deleted text. */ public function test_deleted_text() { $files = array(); $ok = ODTTestUtils::getRenderedODTDocument($files, '<del>This is strike-through text.</del>'); $this->assertFalse($ok == false, 'Error rendering, creating, unpacking, reading ODT doc!'); // Examine ODT XML content. // Get office:text $office_text = XMLUtil::getElementContent('office:text', $files['content-xml']); $this->assertFalse($office_text == NULL, 'Element "office:text" not found!'); // Get first paragraph $paragraph = XMLUtil::getElementContent('text:p', $office_text); $this->assertFalse($paragraph == NULL, 'Element "text:p" not found!'); // The paragraph shouild have a text span. $span_attrs = XMLUtil::getElementOpenTag('text:span', $office_text); $span_content = XMLUtil::getElementContent('text:span', $office_text); $this->assertFalse($span_content == NULL, 'Element "text:p" not found!'); // The span should have our text content and the style for bold text $this->assertEquals($span_content, 'This is strike-through text.'); $attributes = array(); $found = XMLUtil::getAttributes($attributes, $span_attrs); $this->assertEquals(1, $found); $this->assertEquals('del', $attributes['text:style-name']); }