From 2a5c66784b5e723d0cdae9249f80d44522196a3b Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Fri, 6 Feb 2015 22:28:31 +0400 Subject: [PATCH] #51 (updated tests, refactored a little). --- docs/general.rst | 14 +- docs/src/documentation.md | 14 +- samples/Sample_01_SimpleText.php | 72 +++--- samples/Sample_02_TabStops.php | 6 +- samples/Sample_03_Sections.php | 14 +- samples/Sample_04_Textrun.php | 26 +- samples/Sample_05_Multicolumn.php | 10 +- samples/Sample_06_Footnote.php | 26 +- samples/Sample_07_TemplateCloneRow.php | 70 +++--- samples/Sample_08_ParagraphPagination.php | 22 +- samples/Sample_09_Tables.php | 48 ++-- samples/Sample_10_EastAsianFontStyle.php | 2 +- samples/Sample_12_HeaderFooter.php | 25 +- samples/Sample_13_Images.php | 16 +- samples/Sample_14_ListItem.php | 64 ++--- samples/Sample_15_Link.php | 4 +- samples/Sample_16_Object.php | 2 +- samples/Sample_17_TitleTOC.php | 42 ++-- samples/Sample_18_Watermark.php | 2 +- samples/Sample_19_TextBreak.php | 12 +- samples/Sample_20_BGColor.php | 6 +- samples/Sample_21_TableRowRules.php | 16 +- samples/Sample_22_CheckBox.php | 8 +- samples/Sample_25_TextBox.php | 20 +- samples/Sample_27_Field.php | 10 +- samples/Sample_29_Line.php | 8 +- samples/Sample_31_Shape.php | 12 +- samples/Sample_32_Chart.php | 4 +- samples/Sample_33_FormField.php | 10 +- samples/Sample_34_SDT.php | 6 +- samples/Sample_35_InternalLink.php | 8 +- samples/Sample_36_RTL.php | 4 +- samples/resources/Sample_28_ReadRTF.rtf | 2 +- tests/PhpWord/Tests/AutoloaderTest.php | 8 +- .../Tests/Element/AbstractElementTest.php | 4 +- tests/PhpWord/Tests/Element/CellTest.php | 40 +-- tests/PhpWord/Tests/Element/CheckBoxTest.php | 20 +- tests/PhpWord/Tests/Element/FieldTest.php | 17 +- tests/PhpWord/Tests/Element/FooterTest.php | 18 +- tests/PhpWord/Tests/Element/FootnoteTest.php | 10 +- tests/PhpWord/Tests/Element/HeaderTest.php | 30 +-- tests/PhpWord/Tests/Element/ImageTest.php | 45 ++-- tests/PhpWord/Tests/Element/LineTest.php | 28 +-- tests/PhpWord/Tests/Element/LinkTest.php | 28 +-- .../PhpWord/Tests/Element/ListItemRunTest.php | 30 +-- tests/PhpWord/Tests/Element/ListItemTest.php | 13 +- tests/PhpWord/Tests/Element/ObjectTest.php | 18 +- .../Tests/Element/PreserveTextTest.php | 21 +- tests/PhpWord/Tests/Element/RowTest.php | 4 +- tests/PhpWord/Tests/Element/SectionTest.php | 46 ++-- tests/PhpWord/Tests/Element/TOCTest.php | 8 +- tests/PhpWord/Tests/Element/TableTest.php | 20 +- tests/PhpWord/Tests/Element/TextBoxTest.php | 18 +- tests/PhpWord/Tests/Element/TextRunTest.php | 24 +- tests/PhpWord/Tests/Element/TextTest.php | 18 +- tests/PhpWord/Tests/Element/TitleTest.php | 8 +- tests/PhpWord/Tests/IOFactoryTest.php | 2 +- tests/PhpWord/Tests/MediaTest.php | 12 +- tests/PhpWord/Tests/Metadata/DocInfoTest.php | 90 ++----- tests/PhpWord/Tests/PhpWordTest.php | 2 +- tests/PhpWord/Tests/SettingsTest.php | 4 +- tests/PhpWord/Tests/Shared/HtmlTest.php | 4 +- tests/PhpWord/Tests/Shared/XMLReaderTest.php | 6 +- tests/PhpWord/Tests/Shared/ZipArchiveTest.php | 18 +- .../PhpWord/Tests/Style/AbstractStyleTest.php | 3 +- tests/PhpWord/Tests/Style/CellTest.php | 24 +- tests/PhpWord/Tests/Style/FontTest.php | 83 +++---- tests/PhpWord/Tests/Style/ImageTest.php | 30 +-- tests/PhpWord/Tests/Style/IndentationTest.php | 6 +- .../PhpWord/Tests/Style/LineNumberingTest.php | 6 +- tests/PhpWord/Tests/Style/LineTest.php | 38 +-- .../Tests/Style/NumberingLevelTest.php | 22 +- tests/PhpWord/Tests/Style/NumberingTest.php | 4 +- tests/PhpWord/Tests/Style/ParagraphTest.php | 48 ++-- tests/PhpWord/Tests/Style/RowTest.php | 8 +- tests/PhpWord/Tests/Style/SectionTest.php | 11 +- tests/PhpWord/Tests/Style/SpacingTest.php | 6 +- tests/PhpWord/Tests/Style/TableTest.php | 46 ++-- tests/PhpWord/Tests/Style/TextBoxTest.php | 137 +++++------ tests/PhpWord/Tests/StyleTest.php | 2 +- tests/PhpWord/Tests/TemplateProcessorTest.php | 22 +- .../PhpWord/Tests/Writer/HTML/ElementTest.php | 10 +- tests/PhpWord/Tests/Writer/HTMLTest.php | 44 ++-- .../Writer/ODText/Part/AbstractPartTest.php | 14 +- .../Tests/Writer/ODText/Part/ContentTest.php | 33 ++- tests/PhpWord/Tests/Writer/ODTextTest.php | 27 +-- tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php | 4 +- tests/PhpWord/Tests/Writer/PDF/MPDFTest.php | 4 +- tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php | 4 +- tests/PhpWord/Tests/Writer/PDFTest.php | 2 +- tests/PhpWord/Tests/Writer/RTFTest.php | 26 +- .../Tests/Writer/Word2007/ElementTest.php | 63 +++-- .../Writer/Word2007/Part/AbstractPartTest.php | 14 +- .../Writer/Word2007/Part/DocumentTest.php | 229 ++++++++++-------- .../Tests/Writer/Word2007/Part/FooterTest.php | 8 +- .../Writer/Word2007/Part/FootnotesTest.php | 12 +- .../Tests/Writer/Word2007/Part/HeaderTest.php | 8 +- .../Writer/Word2007/Part/NumberingTest.php | 20 +- .../Tests/Writer/Word2007/Part/StylesTest.php | 7 +- .../Tests/Writer/Word2007/Style/FontTest.php | 4 +- tests/PhpWord/Tests/Writer/Word2007Test.php | 45 ++-- .../PhpWord/Tests/_files/documents/reader.rtf | 2 +- .../Tests/_includes/TestHelperDOCX.php | 12 +- tests/PhpWord/Tests/_includes/XmlDocument.php | 2 +- 104 files changed, 1169 insertions(+), 1140 deletions(-) diff --git a/docs/general.rst b/docs/general.rst index 34d3af24..64298928 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -28,7 +28,9 @@ folder `__. htmlspecialchars( '"Learn from yesterday, live for today, hope for tomorrow. ' . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' + . '(Albert Einstein)', + ENT_COMPAT, + 'UTF-8' ) ); @@ -44,7 +46,9 @@ folder `__. htmlspecialchars( '"Great achievement is usually born of great sacrifice, ' . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' + . '(Napoleon Hill)', + ENT_COMPAT, + 'UTF-8' ), array('name' => 'Tahoma', 'size' => 10) ); @@ -59,7 +63,9 @@ folder `__. htmlspecialchars( '"The greatest accomplishment is not in never falling, ' . 'but in rising again after you fall." ' - . '(Vince Lombardi)' + . '(Vince Lombardi)', + ENT_COMPAT, + 'UTF-8' ), $fontStyleName ); @@ -70,7 +76,7 @@ folder `__. $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); $myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') + htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8') ); $myTextElement->setFontStyle($fontStyle); diff --git a/docs/src/documentation.md b/docs/src/documentation.md index 1a59e942..36c8ad6b 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -228,7 +228,9 @@ $section->addText( htmlspecialchars( '"Learn from yesterday, live for today, hope for tomorrow. ' . 'The important thing is not to stop questioning." ' - . '(Albert Einstein)' + . '(Albert Einstein)', + ENT_COMPAT, + 'UTF-8' ) ); @@ -244,7 +246,9 @@ $section->addText( htmlspecialchars( '"Great achievement is usually born of great sacrifice, ' . 'and is never the result of selfishness." ' - . '(Napoleon Hill)' + . '(Napoleon Hill)', + ENT_COMPAT, + 'UTF-8' ), array('name' => 'Tahoma', 'size' => 10) ); @@ -259,7 +263,9 @@ $section->addText( htmlspecialchars( '"The greatest accomplishment is not in never falling, ' . 'but in rising again after you fall." ' - . '(Vince Lombardi)' + . '(Vince Lombardi)', + ENT_COMPAT, + 'UTF-8' ), $fontStyleName ); @@ -270,7 +276,7 @@ $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); $myTextElement = $section->addText( - htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)') + htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)', ENT_COMPAT, 'UTF-8') ); $myTextElement->setFontStyle($fontStyle); diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php index f7aaece3..391622b8 100644 --- a/samples/Sample_01_SimpleText.php +++ b/samples/Sample_01_SimpleText.php @@ -12,16 +12,16 @@ $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); $section = $phpWord->addSection(); // Simple text -$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1); -$section->addText(htmlspecialchars('Hello World!')); +$section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1); +$section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8')); // Two text break $section->addTextBreak(2); // Defined style -$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle'); -$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle'); -$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle'); +$section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle'); +$section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle'); +$section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle'); $section->addTextBreak(); @@ -30,39 +30,39 @@ $fontStyle['name'] = 'Times New Roman'; $fontStyle['size'] = 20; $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle); -$textrun->addText(htmlspecialchars('with ')); -$textrun->addText(htmlspecialchars('color'), array('color' => '996699')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('bold'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('italic'), array('italic' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow')); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('scale'), array('scale' => 200)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10)); -$textrun->addText(htmlspecialchars('. ')); +$textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle); +$textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699')); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow')); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10)); +$textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8')); // Link -$section->addLink('http://www.google.com', htmlspecialchars('Google')); +$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(); // Image diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php index 46d91cec..618454b2 100644 --- a/samples/Sample_02_TabStops.php +++ b/samples/Sample_02_TabStops.php @@ -29,9 +29,9 @@ $phpWord->addParagraphStyle( $section = $phpWord->addSection(); // Add listitem elements -$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab'); -$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab'); -$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab'); +$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree", ENT_COMPAT, 'UTF-8'), null, 'multipleTab'); +$section->addText(htmlspecialchars("Left Aligned\tRight Aligned", ENT_COMPAT, 'UTF-8'), null, 'rightTab'); +$section->addText(htmlspecialchars("\tCenter Aligned", ENT_COMPAT, 'UTF-8'), null, 'centerTab'); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php index a95b15d6..3a7ea19e 100644 --- a/samples/Sample_03_Sections.php +++ b/samples/Sample_03_Sections.php @@ -7,13 +7,15 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); // New portrait section $section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12)); -$section->addText(htmlspecialchars('I am placed on a default section.')); +$section->addText(htmlspecialchars('I am placed on a default section.', ENT_COMPAT, 'UTF-8')); // New landscape section $section = $phpWord->addSection(array('orientation' => 'landscape')); $section->addText( htmlspecialchars( - 'I am placed on a landscape section. Every page starting from this section will be landscape style.' + 'I am placed on a landscape section. Every page starting from this section will be landscape style.', + ENT_COMPAT, + 'UTF-8' ) ); $section->addPageBreak(); @@ -23,7 +25,7 @@ $section->addPageBreak(); $section = $phpWord->addSection( array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); -$section->addText(htmlspecialchars('This section uses other margins with folio papersize.')); +$section->addText(htmlspecialchars('This section uses other margins with folio papersize.', ENT_COMPAT, 'UTF-8')); // New portrait section with Header & Footer $section = $phpWord->addSection( @@ -36,9 +38,9 @@ $section = $phpWord->addSection( 'footerHeight' => 50, ) ); -$section->addText(htmlspecialchars('This section and we play with header/footer height.')); -$section->addHeader()->addText(htmlspecialchars('Header')); -$section->addFooter()->addText(htmlspecialchars('Footer')); +$section->addText(htmlspecialchars('This section and we play with header/footer height.', ENT_COMPAT, 'UTF-8')); +$section->addHeader()->addText(htmlspecialchars('Header', ENT_COMPAT, 'UTF-8')); +$section->addFooter()->addText(htmlspecialchars('Footer', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php index 7ebf6e33..9590f6df 100644 --- a/samples/Sample_04_Textrun.php +++ b/samples/Sample_04_Textrun.php @@ -20,24 +20,24 @@ $section = $phpWord->addSection(); // Add text run $textrun = $section->addTextRun('pStyle'); -$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.')); -$textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText'); -$textrun->addText(htmlspecialchars(' Both ')); -$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true)); -$textrun->addText(htmlspecialchars(' and ')); -$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true)); -$textrun->addText(htmlspecialchars(' are also available.')); +$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars(' No break is placed after adding an element.', ENT_COMPAT, 'UTF-8'), 'BoldText'); +$textrun->addText(htmlspecialchars(' Both ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('superscript', ENT_COMPAT, 'UTF-8'), array('superScript' => true)); +$textrun->addText(htmlspecialchars(' and ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('subscript', ENT_COMPAT, 'UTF-8'), array('subScript' => true)); +$textrun->addText(htmlspecialchars(' are also available.', ENT_COMPAT, 'UTF-8')); $textrun->addText( - htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'), + htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.', ENT_COMPAT, 'UTF-8'), 'ColoredText' ); -$textrun->addText(htmlspecialchars(' Sample Link: ')); -$textrun->addLink('http://www.google.com', null, 'NLink'); -$textrun->addText(htmlspecialchars(' Sample Image: ')); +$textrun->addText(htmlspecialchars(' Sample Link: ', ENT_COMPAT, 'UTF-8')); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink'); +$textrun->addText(htmlspecialchars(' Sample Image: ', ENT_COMPAT, 'UTF-8')); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars(' Sample Object: ')); +$textrun->addText(htmlspecialchars(' Sample Object: ', ENT_COMPAT, 'UTF-8')); $textrun->addObject('resources/_sheet.xls'); -$textrun->addText(htmlspecialchars(' Here is some more text. ')); +$textrun->addText(htmlspecialchars(' Here is some more text. ', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php index b93ab344..5c036729 100644 --- a/samples/Sample_05_Multicolumn.php +++ b/samples/Sample_05_Multicolumn.php @@ -11,7 +11,7 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' // Normal $section = $phpWord->addSection(); -$section->addText(htmlspecialchars("Normal paragraph. {$filler}")); +$section->addText(htmlspecialchars("Normal paragraph. {$filler}", ENT_COMPAT, 'UTF-8')); // Two columns $section = $phpWord->addSection( @@ -21,11 +21,11 @@ $section = $phpWord->addSection( 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}")); +$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8')); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars("Normal paragraph again. {$filler}")); +$section->addText(htmlspecialchars("Normal paragraph again. {$filler}", ENT_COMPAT, 'UTF-8')); // Three columns $section = $phpWord->addSection( @@ -35,11 +35,11 @@ $section = $phpWord->addSection( 'breakType' => 'continuous', ) ); -$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}")); +$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}", ENT_COMPAT, 'UTF-8')); // Normal $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addText(htmlspecialchars('Normal paragraph again.')); +$section->addText(htmlspecialchars('Normal paragraph again.', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php index c7f3d8c0..71c1ff1d 100644 --- a/samples/Sample_06_Footnote.php +++ b/samples/Sample_06_Footnote.php @@ -20,30 +20,32 @@ $phpWord->addLinkStyle( // Add text elements $textrun = $section->addTextRun('pStyle'); -$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle'); +$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. ', ENT_COMPAT, 'UTF-8'), 'pStyle'); $footnote = $textrun->addFootnote(); -$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ')); -$footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText'); -$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText'); +$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ', ENT_COMPAT, 'UTF-8')); +$footnote->addText(htmlspecialchars('No break is placed after adding an element. ', ENT_COMPAT, 'UTF-8'), 'BoldText'); +$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText'); $footnote->addTextBreak(); -$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ')); -$footnote->addText(htmlspecialchars('links like ')); -$footnote->addLink('http://www.google.com', null, 'NLink'); -$footnote->addText(htmlspecialchars(', image like ')); +$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8')); +$footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8')); +$footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink'); +$footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8')); $footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$footnote->addText(htmlspecialchars(', or object like ')); +$footnote->addText(htmlspecialchars(', or object like ', ENT_COMPAT, 'UTF-8')); $footnote->addObject('resources/_sheet.xls'); -$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.')); +$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.', ENT_COMPAT, 'UTF-8')); $section->addText( htmlspecialchars( 'You can also create the footnote directly from the section making it wrap in a paragraph ' - . 'like the footnote below this paragraph. But is is best used from within a textrun.' + . 'like the footnote below this paragraph. But is is best used from within a textrun.', + ENT_COMPAT, + 'UTF-8' ) ); $footnote = $section->addFootnote(); -$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line')); +$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php index 60edacb5..c227a674 100644 --- a/samples/Sample_07_TemplateCloneRow.php +++ b/samples/Sample_07_TemplateCloneRow.php @@ -6,52 +6,52 @@ echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL; $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx'); // Variables on different parts of document -$templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content -$templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer -$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header +$templateProcessor->setValue('weekday', htmlspecialchars(date('l'), ENT_COMPAT, 'UTF-8')); // On section/content +$templateProcessor->setValue('time', htmlspecialchars(date('H:i'), ENT_COMPAT, 'UTF-8')); // On footer +$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__), ENT_COMPAT, 'UTF-8')); // On header // Simple table $templateProcessor->cloneRow('rowValue', 10); -$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun')); -$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury')); -$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus')); -$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth')); -$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars')); -$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter')); -$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn')); -$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus')); -$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun')); -$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto')); +$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1')); -$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2')); -$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3')); -$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4')); -$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5')); -$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6')); -$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7')); -$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8')); -$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9')); -$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10')); +$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10', ENT_COMPAT, 'UTF-8')); // Table with a spanned cell $templateProcessor->cloneRow('userId', 3); -$templateProcessor->setValue('userId#1', htmlspecialchars('1')); -$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James')); -$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor')); -$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773')); +$templateProcessor->setValue('userId#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userId#2', htmlspecialchars('2')); -$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert')); -$templateProcessor->setValue('userName#2', htmlspecialchars('Bell')); -$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774')); +$templateProcessor->setValue('userId#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userName#2', htmlspecialchars('Bell', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774', ENT_COMPAT, 'UTF-8')); -$templateProcessor->setValue('userId#3', htmlspecialchars('3')); -$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael')); -$templateProcessor->setValue('userName#3', htmlspecialchars('Ray')); -$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775')); +$templateProcessor->setValue('userId#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userName#3', htmlspecialchars('Ray', ENT_COMPAT, 'UTF-8')); +$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775', ENT_COMPAT, 'UTF-8')); echo date('H:i:s'), ' Saving the result document...', EOL; $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx'); diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php index dd364562..979d6c0f 100644 --- a/samples/Sample_08_ParagraphPagination.php +++ b/samples/Sample_08_ParagraphPagination.php @@ -19,7 +19,9 @@ $section->addText( htmlspecialchars( 'Below are the samples on how to control your paragraph ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' - . 'window to see the attribute set by these controls.' + . 'window to see the attribute set by these controls.', + ENT_COMPAT, + 'UTF-8' ), array('bold' => true), array('space' => array('before' => 360, 'after' => 480)) @@ -31,7 +33,9 @@ $section->addText( . 'A "widow" is the last line of a paragraph printed by itself at the top ' . 'of a page. An "orphan" is the first line of a paragraph printed by ' . 'itself at the bottom of a page. Set this option to "false" if you want ' - . 'to disable this automatic control.' + . 'to disable this automatic control.', + ENT_COMPAT, + 'UTF-8' ), null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)) @@ -42,7 +46,9 @@ $section->addText( 'Paragraph with keepNext = true (default: false). ' . '"Keep with next" is used to prevent Word from inserting automatic page ' . 'breaks between paragraphs. Set this option to "true" if you do not want ' - . 'your paragraph to be separated with the next paragraph.' + . 'your paragraph to be separated with the next paragraph.', + ENT_COMPAT, + 'UTF-8' ), null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)) @@ -53,20 +59,24 @@ $section->addText( 'Paragraph with keepLines = true (default: false). ' . '"Keep lines together" will prevent Word from inserting an automatic page ' . 'break within a paragraph. Set this option to "true" if you do not want ' - . 'all lines of your paragraph to be in the same page.' + . 'all lines of your paragraph to be in the same page.', + ENT_COMPAT, + 'UTF-8' ), null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)) ); -$section->addText(htmlspecialchars('Keep scrolling. More below.')); +$section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8')); $section->addText( htmlspecialchars( 'Paragraph with pageBreakBefore = true (default: false). ' . 'Different with all other control above, "page break before" separates ' . 'your paragraph into the next page. This option is most useful for ' - . 'heading styles.' + . 'heading styles.', + ENT_COMPAT, + 'UTF-8' ), null, array('pageBreakBefore' => true) diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php index 5c305c83..241efcb9 100644 --- a/samples/Sample_09_Tables.php +++ b/samples/Sample_09_Tables.php @@ -11,20 +11,20 @@ $header = array('size' => 16, 'bold' => true); $rows = 10; $cols = 5; -$section->addText(htmlspecialchars('Basic table'), $header); +$section->addText(htmlspecialchars('Basic table', ENT_COMPAT, 'UTF-8'), $header); $table = $section->addTable(); for ($r = 1; $r <= 8; $r++) { $table->addRow(); for ($c = 1; $c <= 5; $c++) { - $table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}")); + $table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}", ENT_COMPAT, 'UTF-8')); } } // 2. Advanced table $section->addTextBreak(1); -$section->addText(htmlspecialchars('Fancy table'), $header); +$section->addText(htmlspecialchars('Fancy table', ENT_COMPAT, 'UTF-8'), $header); $styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80); $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); @@ -34,25 +34,25 @@ $fontStyle = array('bold' => true, 'align' => 'center'); $phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); $table = $section->addTable('Fancy Table'); $table->addRow(900); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3'), $fontStyle); -$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4'), $fontStyle); -$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5'), $fontStyle); +$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1', ENT_COMPAT, 'UTF-8'), $fontStyle); +$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2', ENT_COMPAT, 'UTF-8'), $fontStyle); +$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3', ENT_COMPAT, 'UTF-8'), $fontStyle); +$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4', ENT_COMPAT, 'UTF-8'), $fontStyle); +$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5', ENT_COMPAT, 'UTF-8'), $fontStyle); for ($i = 1; $i <= 8; $i++) { $table->addRow(); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); - $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}")); + $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); + $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); + $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); + $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8')); $text = (0== $i % 2) ? 'X' : ''; - $table->addCell(500)->addText(htmlspecialchars($text)); + $table->addCell(500)->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')); } // 3. colspan (gridSpan) and rowspan (vMerge) $section->addPageBreak(); -$section->addText(htmlspecialchars('Table with colspan and rowspan'), $header); +$section->addText(htmlspecialchars('Table with colspan and rowspan', ENT_COMPAT, 'UTF-8'), $header); $styleTable = array('borderSize' => 6, 'borderColor' => '999999'); $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00'); @@ -68,32 +68,32 @@ $table->addRow(); $cell1 = $table->addCell(2000, $cellRowSpan); $textrun1 = $cell1->addTextRun($cellHCentered); -$textrun1->addText(htmlspecialchars('A')); -$textrun1->addFootnote()->addText(htmlspecialchars('Row span')); +$textrun1->addText(htmlspecialchars('A', ENT_COMPAT, 'UTF-8')); +$textrun1->addFootnote()->addText(htmlspecialchars('Row span', ENT_COMPAT, 'UTF-8')); $cell2 = $table->addCell(4000, $cellColSpan); $textrun2 = $cell2->addTextRun($cellHCentered); -$textrun2->addText(htmlspecialchars('B')); -$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span')); +$textrun2->addText(htmlspecialchars('B', ENT_COMPAT, 'UTF-8')); +$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span', ENT_COMPAT, 'UTF-8')); -$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E'), null, $cellHCentered); +$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); $table->addRow(); $table->addCell(null, $cellRowContinue); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C'), null, $cellHCentered); -$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D'), null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); +$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D', ENT_COMPAT, 'UTF-8'), null, $cellHCentered); $table->addCell(null, $cellRowContinue); // 4. Nested table $section->addTextBreak(2); -$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.'), $header); +$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.', ENT_COMPAT, 'UTF-8'), $header); $table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center')); $cell = $table->addRow()->addCell(); -$cell->addText(htmlspecialchars('This cell contains nested table.')); +$cell->addText(htmlspecialchars('This cell contains nested table.', ENT_COMPAT, 'UTF-8')); $innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell(); -$innerCell->addText(htmlspecialchars('Inside nested table')); +$innerCell->addText(htmlspecialchars('Inside nested table', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php index f3553bfe..e4cda636 100644 --- a/samples/Sample_10_EastAsianFontStyle.php +++ b/samples/Sample_10_EastAsianFontStyle.php @@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $header = array('size' => 16, 'bold' => true); //1.Use EastAisa FontStyle -$section->addText(htmlspecialchars('中文楷体样式测试'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); +$section->addText(htmlspecialchars('中文楷体样式测试', ENT_COMPAT, 'UTF-8'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php index dc4fc129..b759121c 100644 --- a/samples/Sample_12_HeaderFooter.php +++ b/samples/Sample_12_HeaderFooter.php @@ -15,50 +15,47 @@ $table = $header->addTable(); $table->addRow(); $cell = $table->addCell(4500); $textrun = $cell->addTextRun(); -$textrun->addText(htmlspecialchars('This is the header with ')); -$textrun->addLink('http://google.com', htmlspecialchars('link to Google')); -$table->addCell(4500)->addImage( - 'resources/PhpWord.png', - array('width' => 80, 'height' => 80, 'align' => 'right') -); +$textrun->addText(htmlspecialchars('This is the header with ', ENT_COMPAT, 'UTF-8')); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); +$table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'align' => 'right')); // Add header for all other pages $subsequent = $section->addHeader(); -$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!')); +$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!', ENT_COMPAT, 'UTF-8')); $subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80)); // Add footer $footer = $section->addFooter(); -$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.'), array('align' => 'center')); -$footer->addLink('http://google.com', htmlspecialchars('Direct Google')); +$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.', ENT_COMPAT, 'UTF-8'), array('align' => 'center')); +$footer->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); // Create a second page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); // Create a third page $section->addPageBreak(); // Write some text $section->addTextBreak(); -$section->addText(htmlspecialchars('Some text...')); +$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); // New portrait section $section2 = $phpWord->addSection(); $sec2Header = $section2->addHeader(); -$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!')); +$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!', ENT_COMPAT, 'UTF-8')); // Write some text $section2->addTextBreak(); -$section2->addText(htmlspecialchars('Some text...')); +$section2->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php index d1391211..f24dbfba 100644 --- a/samples/Sample_13_Images.php +++ b/samples/Sample_13_Images.php @@ -7,17 +7,17 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Local image without any styles:')); +$section->addText(htmlspecialchars('Local image without any styles:', ENT_COMPAT, 'UTF-8')); $section->addImage('resources/_mars.jpg'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Local image with styles:')); +$section->addText(htmlspecialchars('Local image with styles:', ENT_COMPAT, 'UTF-8')); $section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center')); $section->addTextBreak(2); // Remote image $source = 'http://php.net/images/logos/php-med-trans-light.gif'; -$section->addText(htmlspecialchars("Remote image from: {$source}")); +$section->addText(htmlspecialchars("Remote image from: {$source}", ENT_COMPAT, 'UTF-8')); $section->addImage($source); //Wrapping style @@ -25,7 +25,7 @@ $text = str_repeat('Hello World! ', 15); $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); foreach ($wrappingStyles as $wrappingStyle) { $section->addTextBreak(5); - $section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}")); + $section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}", ENT_COMPAT, 'UTF-8')); $section->addImage( 'resources/_earth.jpg', array( @@ -37,12 +37,12 @@ foreach ($wrappingStyles as $wrappingStyle) { 'wrappingStyle' => $wrappingStyle, ) ); - $section->addText(htmlspecialchars($text)); + $section->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')); } //Absolute positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page')); +$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page', ENT_COMPAT, 'UTF-8')); $section->addImage( 'resources/_mars.jpg', array( @@ -59,8 +59,8 @@ $section->addImage( //Relative positioning $section->addTextBreak(3); -$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,')); -$section->addText(htmlspecialchars('Vertical position top relative to line')); +$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,', ENT_COMPAT, 'UTF-8')); +$section->addText(htmlspecialchars('Vertical position top relative to line', ENT_COMPAT, 'UTF-8')); $section->addImage( 'resources/_mars.jpg', array( diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php index 3a29e3fd..df5ffee3 100644 --- a/samples/Sample_14_ListItem.php +++ b/samples/Sample_14_ListItem.php @@ -26,46 +26,46 @@ $predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::T // Lists -$section->addText(htmlspecialchars('Multilevel list.')); -$section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel'); +$section->addText(htmlspecialchars('Multilevel list.', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item I', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item I.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item I.b', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item II', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item II.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item III', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Basic simple bulleted list.')); -$section->addListItem(htmlspecialchars('List Item 1')); -$section->addListItem(htmlspecialchars('List Item 2')); -$section->addListItem(htmlspecialchars('List Item 3')); +$section->addText(htmlspecialchars('Basic simple bulleted list.', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Continue from multilevel list above.')); -$section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel'); -$section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel'); +$section->addText(htmlspecialchars('Continue from multilevel list above.', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item IV', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel'); +$section->addListItem(htmlspecialchars('List Item IV.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Multilevel predefined list.')); -$section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 2'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 3'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 4'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 5'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 6'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); -$section->addListItem(htmlspecialchars('List Item 7'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addText(htmlspecialchars('Multilevel predefined list.', ENT_COMPAT, 'UTF-8')); +$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 4', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 5', ENT_COMPAT, 'UTF-8'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 6', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); +$section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addTextBreak(2); -$section->addText(htmlspecialchars('List with inline formatting.')); +$section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8')); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 1')); -$listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true)); +$listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8')); +$listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 2')); -$listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true)); +$listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8')); +$listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); $listItemRun = $section->addListItemRun(); -$listItemRun->addText(htmlspecialchars('List item 3')); -$listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash')); +$listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8')); +$listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); $section->addTextBreak(2); // Numbered heading @@ -84,9 +84,9 @@ $phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumb $phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1)); $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2)); -$section->addTitle(htmlspecialchars('Heading 1'), 1); -$section->addTitle(htmlspecialchars('Heading 2'), 2); -$section->addTitle(htmlspecialchars('Heading 3'), 3); +$section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1); +$section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2); +$section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php index dd06670e..b55db21c 100644 --- a/samples/Sample_15_Link.php +++ b/samples/Sample_15_Link.php @@ -10,8 +10,8 @@ $section = $phpWord->addSection(); // Add hyperlink elements $section->addLink( - 'http://www.google.com', - htmlspecialchars('Best search engine'), + 'https://github.com/PHPOffice/PHPWord', + htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) ); $section->addTextBreak(2); diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php index 2a216c23..950f7743 100644 --- a/samples/Sample_16_Object.php +++ b/samples/Sample_16_Object.php @@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Begin code $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:')); +$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); $section->addObject('resources/_sheet.xls'); diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php index 8f8889b8..6fcf6715 100644 --- a/samples/Sample_17_TitleTOC.php +++ b/samples/Sample_17_TitleTOC.php @@ -19,7 +19,7 @@ $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true)); $phpWord->addTitleStyle(4, array('size' => 12)); // Add text elements -$section->addText(htmlspecialchars('Table of contents 1')); +$section->addText(htmlspecialchars('Table of contents 1', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); // Add TOC #1 @@ -27,11 +27,11 @@ $toc = $section->addTOC($fontStyle); $section->addTextBreak(2); // Filler -$section->addText(htmlspecialchars('Text between TOC')); +$section->addText(htmlspecialchars('Text between TOC', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); // Add TOC #1 -$section->addText(htmlspecialchars('Table of contents 2')); +$section->addText(htmlspecialchars('Table of contents 2', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); $toc2 = $section->addTOC($fontStyle2); $toc2->setMinDepth(2); @@ -40,31 +40,31 @@ $toc2->setMaxDepth(3); // Add Titles $section->addPageBreak(); -$section->addTitle(htmlspecialchars('Foo & Bar'), 1); -$section->addText(htmlspecialchars('Some text...')); +$section->addTitle(htmlspecialchars('Foo & Bar', ENT_COMPAT, 'UTF-8'), 1); +$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1'), 2); +$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1', ENT_COMPAT, 'UTF-8'), 2); $section->addTextBreak(2); -$section->addText(htmlspecialchars('Some more text...')); +$section->addText(htmlspecialchars('Some more text...', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('Another Title (Title 2)'), 1); -$section->addText(htmlspecialchars('Some text...')); +$section->addTitle(htmlspecialchars('Another Title (Title 2)', ENT_COMPAT, 'UTF-8'), 1); +$section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8')); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('I am Title 3'), 1); -$section->addText(htmlspecialchars('And more text...')); +$section->addTitle(htmlspecialchars('I am Title 3', ENT_COMPAT, 'UTF-8'), 1); +$section->addText(htmlspecialchars('And more text...', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(2); -$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3'), 2); -$section->addText(htmlspecialchars('Again and again, more text...')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1'), 3); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1'), 4); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2'), 4); -$section->addText(htmlspecialchars('Text')); -$section->addTitle(htmlspecialchars('Subtitle 3.1.2'), 3); -$section->addText(htmlspecialchars('Text')); +$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3', ENT_COMPAT, 'UTF-8'), 2); +$section->addText(htmlspecialchars('Again and again, more text...', ENT_COMPAT, 'UTF-8')); +$section->addTitle(htmlspecialchars('Subtitle 3.1.1', ENT_COMPAT, 'UTF-8'), 3); +$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); +$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1', ENT_COMPAT, 'UTF-8'), 4); +$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); +$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2', ENT_COMPAT, 'UTF-8'), 4); +$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); +$section->addTitle(htmlspecialchars('Subtitle 3.1.2', ENT_COMPAT, 'UTF-8'), 3); +$section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL; diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php index f630bdf2..5a26fd04 100644 --- a/samples/Sample_18_Watermark.php +++ b/samples/Sample_18_Watermark.php @@ -10,7 +10,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $header = $section->addHeader(); $header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); -$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.')); +$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php index fc0e5419..b0405b6c 100644 --- a/samples/Sample_19_TextBreak.php +++ b/samples/Sample_19_TextBreak.php @@ -13,17 +13,17 @@ $phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480)); $fontStyle = array('size' => 24); $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Text break with no style:')); +$section->addText(htmlspecialchars('Text break with no style:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(); -$section->addText(htmlspecialchars('Text break with defined font style:')); +$section->addText(htmlspecialchars('Text break with defined font style:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(1, 'fontStyle'); -$section->addText(htmlspecialchars('Text break with defined paragraph style:')); +$section->addText(htmlspecialchars('Text break with defined paragraph style:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(1, null, 'paragraphStyle'); -$section->addText(htmlspecialchars('Text break with inline font style:')); +$section->addText(htmlspecialchars('Text break with inline font style:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(1, $fontStyle); -$section->addText(htmlspecialchars('Text break with inline paragraph style:')); +$section->addText(htmlspecialchars('Text break with inline paragraph style:', ENT_COMPAT, 'UTF-8')); $section->addTextBreak(1, null, $paragraphStyle); -$section->addText(htmlspecialchars('Done.')); +$section->addText(htmlspecialchars('Done.', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php index ebee8544..143189ad 100644 --- a/samples/Sample_20_BGColor.php +++ b/samples/Sample_20_BGColor.php @@ -7,14 +7,14 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $section->addText( - htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) '), + htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) ', ENT_COMPAT, 'UTF-8'), array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW) ); $section->addText( - htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)'), + htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)', ENT_COMPAT, 'UTF-8'), array('bgColor' => 'fbbb10') ); -$section->addText(htmlspecialchars('Compatible with font colors'), array('color' => '0000ff', 'bgColor' => 'fbbb10')); +$section->addText(htmlspecialchars('Compatible with font colors', ENT_COMPAT, 'UTF-8'), array('color' => '0000ff', 'bgColor' => 'fbbb10')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php index df3162c3..f22b6165 100644 --- a/samples/Sample_21_TableRowRules.php +++ b/samples/Sample_21_TableRowRules.php @@ -6,14 +6,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.')); +$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.', ENT_COMPAT, 'UTF-8')); $section->addText( - htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell') + htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell', ENT_COMPAT, 'UTF-8') ); $section->addText( htmlspecialchars( 'On the image with the red border, even if we set the row height to the height of the image, ' - . 'the textbreak is still there:' + . 'the textbreak is still there:', + ENT_COMPAT, + 'UTF-8' ) ); @@ -25,7 +27,9 @@ $cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250 $section->addTextBreak(); $section->addText( htmlspecialchars( - "But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:" + "But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:", + ENT_COMPAT, + 'UTF-8' ) ); @@ -43,9 +47,9 @@ $cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250 $section->addTextBreak(); $section->addText( - htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.') + htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.', ENT_COMPAT, 'UTF-8') ); -$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));")); +$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));", ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php index b5d4a7a5..9c8c05a7 100644 --- a/samples/Sample_22_CheckBox.php +++ b/samples/Sample_22_CheckBox.php @@ -6,13 +6,13 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); -$section->addText(htmlspecialchars('Check box in section')); -$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1')); -$section->addText(htmlspecialchars('Check box in table cell')); +$section->addText(htmlspecialchars('Check box in section', ENT_COMPAT, 'UTF-8')); +$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1', ENT_COMPAT, 'UTF-8')); +$section->addText(htmlspecialchars('Check box in table cell', ENT_COMPAT, 'UTF-8')); $table = $section->addTable(); $table->addRow(); $cell = $table->addCell(); -$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2')); +$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_25_TextBox.php b/samples/Sample_25_TextBox.php index afeb863d..ebd597d2 100644 --- a/samples/Sample_25_TextBox.php +++ b/samples/Sample_25_TextBox.php @@ -17,28 +17,28 @@ $textbox = $section->addTextBox( 'borderColor' => '#FF0000', ) ); -$textbox->addText(htmlspecialchars('Text box content in section.')); -$textbox->addText(htmlspecialchars('Another line.')); +$textbox->addText(htmlspecialchars('Text box content in section.', ENT_COMPAT, 'UTF-8')); +$textbox->addText(htmlspecialchars('Another line.', ENT_COMPAT, 'UTF-8')); $cell = $textbox->addTable()->addRow()->addCell(); -$cell->addText(htmlspecialchars('Table inside textbox')); +$cell->addText(htmlspecialchars('Table inside textbox', ENT_COMPAT, 'UTF-8')); // Inside table $section->addTextBreak(2); $cell = $section->addTable()->addRow()->addCell(300); $textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100)); -$textbox->addText(htmlspecialchars('Textbox inside table')); +$textbox->addText(htmlspecialchars('Textbox inside table', ENT_COMPAT, 'UTF-8')); // Inside header with textrun $header = $section->addHeader(); $textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00')); $textrun = $textbox->addTextRun(); -$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ')); -$textrun->addText(htmlspecialchars('with bold text'), array('bold' => true)); -$textrun->addText(htmlspecialchars(', ')); -$textrun->addLink('http://www.google.com', htmlspecialchars('link')); -$textrun->addText(htmlspecialchars(', and image ')); +$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars('with bold text', ENT_COMPAT, 'UTF-8'), array('bold' => true)); +$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); +$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); +$textrun->addText(htmlspecialchars(', and image ', ENT_COMPAT, 'UTF-8')); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); -$textrun->addText(htmlspecialchars('.')); +$textrun->addText(htmlspecialchars('.', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php index 9bdbef82..165a3e8c 100644 --- a/samples/Sample_27_Field.php +++ b/samples/Sample_27_Field.php @@ -10,19 +10,19 @@ $section = $phpWord->addSection(); // Add Field elements // See Element/Field.php for all options -$section->addText(htmlspecialchars('Date field:')); +$section->addText(htmlspecialchars('Date field:', ENT_COMPAT, 'UTF-8')); $section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat')); -$section->addText(htmlspecialchars('Page field:')); +$section->addText(htmlspecialchars('Page field:', ENT_COMPAT, 'UTF-8')); $section->addField('PAGE', array('format' => 'ArabicDash')); -$section->addText(htmlspecialchars('Number of pages field:')); +$section->addText(htmlspecialchars('Number of pages field:', ENT_COMPAT, 'UTF-8')); $section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat')); $textrun = $section->addTextRun(array('align' => 'center')); -$textrun->addText(htmlspecialchars('This is the date of lunar calendar ')); +$textrun->addText(htmlspecialchars('This is the date of lunar calendar ', ENT_COMPAT, 'UTF-8')); $textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); -$textrun->addText(htmlspecialchars(' written in a textrun.')); +$textrun->addText(htmlspecialchars(' written in a textrun.', ENT_COMPAT, 'UTF-8')); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/Sample_29_Line.php b/samples/Sample_29_Line.php index 8bb192cf..5b288803 100644 --- a/samples/Sample_29_Line.php +++ b/samples/Sample_29_Line.php @@ -10,7 +10,7 @@ $section = $phpWord->addSection(); // Add Line elements // See Element/Line.php for all options -$section->addText(htmlspecialchars('Horizontal Line (Inline style):')); +$section->addText(htmlspecialchars('Horizontal Line (Inline style):', ENT_COMPAT, 'UTF-8')); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -18,7 +18,7 @@ $section->addLine( 'positioning' => 'absolute', ) ); -$section->addText(htmlspecialchars('Vertical Line (Inline style):')); +$section->addText(htmlspecialchars('Vertical Line (Inline style):', ENT_COMPAT, 'UTF-8')); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), @@ -29,7 +29,7 @@ $section->addLine( // Two text break $section->addTextBreak(1); -$section->addText(htmlspecialchars('Positioned Line (red):')); +$section->addText(htmlspecialchars('Positioned Line (red):', ENT_COMPAT, 'UTF-8')); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), @@ -44,7 +44,7 @@ $section->addLine( ) ); -$section->addText(htmlspecialchars('Horizontal Formatted Line')); +$section->addText(htmlspecialchars('Horizontal Formatted Line', ENT_COMPAT, 'UTF-8')); $section->addLine( array( 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), diff --git a/samples/Sample_31_Shape.php b/samples/Sample_31_Shape.php index 3df71b4c..d8c4e4f2 100644 --- a/samples/Sample_31_Shape.php +++ b/samples/Sample_31_Shape.php @@ -10,7 +10,7 @@ $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true)); $section = $phpWord->addSection(); // Arc -$section->addTitle(htmlspecialchars('Arc'), 1); +$section->addTitle(htmlspecialchars('Arc', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'arc', array( @@ -21,7 +21,7 @@ $section->addShape( ); // Curve -$section->addTitle(htmlspecialchars('Curve'), 1); +$section->addTitle(htmlspecialchars('Curve', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'curve', array( @@ -38,7 +38,7 @@ $section->addShape( ); // Line -$section->addTitle(htmlspecialchars('Line'), 1); +$section->addTitle(htmlspecialchars('Line', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'line', array( @@ -54,7 +54,7 @@ $section->addShape( ); // Polyline -$section->addTitle(htmlspecialchars('Polyline'), 1); +$section->addTitle(htmlspecialchars('Polyline', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'polyline', array( @@ -64,7 +64,7 @@ $section->addShape( ); // Rectangle -$section->addTitle(htmlspecialchars('Rectangle'), 1); +$section->addTitle(htmlspecialchars('Rectangle', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'rect', array( @@ -77,7 +77,7 @@ $section->addShape( ); // Oval -$section->addTitle(htmlspecialchars('Oval'), 1); +$section->addTitle(htmlspecialchars('Oval', ENT_COMPAT, 'UTF-8'), 1); $section->addShape( 'oval', array( diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php index b61a646f..bc18392e 100644 --- a/samples/Sample_32_Chart.php +++ b/samples/Sample_32_Chart.php @@ -12,7 +12,7 @@ $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' // 2D charts $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('2D charts'), 1); +$section->addTitle(htmlspecialchars('2D charts', ENT_COMPAT, 'UTF-8'), 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); @@ -38,7 +38,7 @@ foreach ($chartTypes as $chartType) { // 3D charts $section = $phpWord->addSection(array('breakType' => 'continuous')); -$section->addTitle(htmlspecialchars('3D charts'), 1); +$section->addTitle(htmlspecialchars('3D charts', ENT_COMPAT, 'UTF-8'), 1); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous')); $chartTypes = array('pie', 'bar', 'column', 'line', 'area'); diff --git a/samples/Sample_33_FormField.php b/samples/Sample_33_FormField.php index 9f356810..df7fcb7a 100644 --- a/samples/Sample_33_FormField.php +++ b/samples/Sample_33_FormField.php @@ -9,15 +9,15 @@ $phpWord->getProtection()->setEditing('forms'); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput ')); +$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput ', ENT_COMPAT, 'UTF-8')); $textrun->addFormField('textinput')->setName('MyTextBox'); -$textrun->addText(htmlspecialchars(', checkbox ')); +$textrun->addText(htmlspecialchars(', checkbox ', ENT_COMPAT, 'UTF-8')); $textrun->addFormField('checkbox')->setDefault(true); -$textrun->addText(htmlspecialchars(', or dropdown ')); +$textrun->addText(htmlspecialchars(', or dropdown ', ENT_COMPAT, 'UTF-8')); $textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); -$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.')); +$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.', ENT_COMPAT, 'UTF-8')); -$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.')); +$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.', ENT_COMPAT, 'UTF-8')); $section->addFormField('textinput')->setValue('Your name'); // Save file diff --git a/samples/Sample_34_SDT.php b/samples/Sample_34_SDT.php index 19ac42fe..3f2cdcc1 100644 --- a/samples/Sample_34_SDT.php +++ b/samples/Sample_34_SDT.php @@ -8,15 +8,15 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Combobox: ')); +$textrun->addText(htmlspecialchars('Combobox: ', ENT_COMPAT, 'UTF-8')); $textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Date: ')); +$textrun->addText(htmlspecialchars('Date: ', ENT_COMPAT, 'UTF-8')); $textrun->addSDT('date'); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('Drop down list: ')); +$textrun->addText(htmlspecialchars('Drop down list: ', ENT_COMPAT, 'UTF-8')); $textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2')); // Save file diff --git a/samples/Sample_35_InternalLink.php b/samples/Sample_35_InternalLink.php index 1b907f87..90bae238 100644 --- a/samples/Sample_35_InternalLink.php +++ b/samples/Sample_35_InternalLink.php @@ -6,13 +6,13 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); -$section->addTitle(htmlspecialchars('This is page 1'), 1); +$section->addTitle(htmlspecialchars('This is page 1', ENT_COMPAT, 'UTF-8'), 1); $linkIsInternal = true; -$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3'), null, null, $linkIsInternal); +$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3', ENT_COMPAT, 'UTF-8'), null, null, $linkIsInternal); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 2'), 1); +$section->addTitle(htmlspecialchars('This is page 2', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); -$section->addTitle(htmlspecialchars('This is page 3'), 1); +$section->addTitle(htmlspecialchars('This is page 3', ENT_COMPAT, 'UTF-8'), 1); $section->addBookmark('MyBookmark'); // Save file diff --git a/samples/Sample_36_RTL.php b/samples/Sample_36_RTL.php index ec326ae0..486e8d6d 100644 --- a/samples/Sample_36_RTL.php +++ b/samples/Sample_36_RTL.php @@ -7,10 +7,10 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); -$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.')); +$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.', ENT_COMPAT, 'UTF-8')); $textrun = $section->addTextRun(array('align' => 'right')); -$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است'), array('rtl' => true)); +$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true)); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); diff --git a/samples/resources/Sample_28_ReadRTF.rtf b/samples/resources/Sample_28_ReadRTF.rtf index 6f9ac0f8..ccccc0e7 100644 --- a/samples/resources/Sample_28_ReadRTF.rtf +++ b/samples/resources/Sample_28_ReadRTF.rtf @@ -16,6 +16,6 @@ \pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par \pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par \par -{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par +{\field {\*\fldinst {HYPERLINK "https://github.com/PHPOffice/PHPWord"}}{\fldrslt {PHPWord on GitHub}}}\par \par } \ No newline at end of file diff --git a/tests/PhpWord/Tests/AutoloaderTest.php b/tests/PhpWord/Tests/AutoloaderTest.php index dace5bdb..9d3cd200 100644 --- a/tests/PhpWord/Tests/AutoloaderTest.php +++ b/tests/PhpWord/Tests/AutoloaderTest.php @@ -48,15 +48,15 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase $this->assertCount( $declaredCount, get_declared_classes(), - 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' . - 'classes outside of the PhpOffice\\PhpWord namespace' + 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' + . 'classes outside of the PhpOffice\\PhpWord namespace' ); // TODO change this class to the main PhpWord class when it is namespaced Autoloader::autoload('PhpOffice\\PhpWord\\Exception\\InvalidStyleException'); $this->assertTrue( in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', get_declared_classes()), - 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' . - 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class' + 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' + . 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class' ); } } diff --git a/tests/PhpWord/Tests/Element/AbstractElementTest.php b/tests/PhpWord/Tests/Element/AbstractElementTest.php index 180dd4d0..53485c6b 100644 --- a/tests/PhpWord/Tests/Element/AbstractElementTest.php +++ b/tests/PhpWord/Tests/Element/AbstractElementTest.php @@ -30,7 +30,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $ival = rand(0, 100); $stub->setElementIndex($ival); - $this->assertEquals($stub->getElementIndex(), $ival); + $this->assertEquals($ival, $stub->getElementIndex()); } /** @@ -40,6 +40,6 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $stub->setElementId(); - $this->assertEquals(strlen($stub->getElementId()), 6); + $this->assertEquals(6, strlen($stub->getElementId())); } } diff --git a/tests/PhpWord/Tests/Element/CellTest.php b/tests/PhpWord/Tests/Element/CellTest.php index aa07ec03..322f6417 100644 --- a/tests/PhpWord/Tests/Element/CellTest.php +++ b/tests/PhpWord/Tests/Element/CellTest.php @@ -34,7 +34,7 @@ class CellTest extends \PHPUnit_Framework_TestCase $oCell = new Cell(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $oCell); - $this->assertEquals($oCell->getWidth(), null); + $this->assertNull($oCell->getWidth()); } /** @@ -45,7 +45,7 @@ class CellTest extends \PHPUnit_Framework_TestCase $oCell = new Cell(null, array('valign' => 'center')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Cell', $oCell->getStyle()); - $this->assertEquals($oCell->getWidth(), null); + $this->assertNull($oCell->getWidth()); } /** @@ -54,7 +54,7 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oCell = new Cell(); - $element = $oCell->addText('text'); + $element = $oCell->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); @@ -66,11 +66,11 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddTextNotUTF8() { $oCell = new Cell(); - $element = $oCell->addText(utf8_decode('ééé')); + $element = $oCell->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -79,7 +79,7 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddLink() { $oCell = new Cell(); - $element = $oCell->addLink(utf8_decode('ééé'), utf8_decode('ééé')); + $element = $oCell->addLink(utf8_decode('ééé'), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); @@ -102,11 +102,11 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddListItem() { $oCell = new Cell(); - $element = $oCell->addListItem('text'); + $element = $oCell->addListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals($element->getTextObject()->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText()); } /** @@ -115,11 +115,11 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddListItemNotUTF8() { $oCell = new Cell(); - $element = $oCell->addListItem(utf8_decode('ééé')); + $element = $oCell->addListItem(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); - $this->assertEquals($element->getTextObject()->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getTextObject()->getText()); } /** @@ -127,7 +127,7 @@ class CellTest extends \PHPUnit_Framework_TestCase */ public function testAddImageSection() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell(); $element = $oCell->addImage($src); @@ -140,7 +140,7 @@ class CellTest extends \PHPUnit_Framework_TestCase */ public function testAddImageHeader() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell('header', 1); $element = $oCell->addImage($src); @@ -153,7 +153,7 @@ class CellTest extends \PHPUnit_Framework_TestCase */ public function testAddImageFooter() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oCell = new Cell('footer', 1); $element = $oCell->addImage($src); @@ -180,7 +180,7 @@ class CellTest extends \PHPUnit_Framework_TestCase */ public function testAddObjectXLS() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oCell = new Cell(); $element = $oCell->addObject($src); @@ -195,7 +195,7 @@ class CellTest extends \PHPUnit_Framework_TestCase */ public function testAddObjectException() { - $src = __DIR__ . "/../_files/xsl/passthrough.xsl"; + $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oCell = new Cell(); $oCell->addObject($src); } @@ -207,7 +207,7 @@ class CellTest extends \PHPUnit_Framework_TestCase { $oCell = new Cell(); $oCell->setDocPart('Header', 1); - $element = $oCell->addPreserveText('text'); + $element = $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -220,11 +220,11 @@ class CellTest extends \PHPUnit_Framework_TestCase { $oCell = new Cell(); $oCell->setDocPart('Header', 1); - $element = $oCell->addPreserveText(utf8_decode('ééé')); + $element = $oCell->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); } /** @@ -236,7 +236,7 @@ class CellTest extends \PHPUnit_Framework_TestCase { $oCell = new Cell(); $oCell->setDocPart('Section', 1); - $oCell->addPreserveText('text'); + $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); } /** @@ -257,7 +257,7 @@ class CellTest extends \PHPUnit_Framework_TestCase public function testAddCheckBox() { $oCell = new Cell(); - $element = $oCell->addCheckBox(utf8_decode('ééé'), utf8_decode('ééé')); + $element = $oCell->addCheckBox(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oCell->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element); diff --git a/tests/PhpWord/Tests/Element/CheckBoxTest.php b/tests/PhpWord/Tests/Element/CheckBoxTest.php index 8f7bf3cd..942c908d 100644 --- a/tests/PhpWord/Tests/Element/CheckBoxTest.php +++ b/tests/PhpWord/Tests/Element/CheckBoxTest.php @@ -35,7 +35,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase $oCheckBox = new CheckBox(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $oCheckBox); - $this->assertEquals(null, $oCheckBox->getText()); + $this->assertNull($oCheckBox->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); } @@ -45,10 +45,10 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase */ public function testCheckBox() { - $oCheckBox = new CheckBox('chkBox', 'CheckBox'); + $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8')); - $this->assertEquals($oCheckBox->getName(), 'chkBox'); - $this->assertEquals($oCheckBox->getText(), 'CheckBox'); + $this->assertEquals(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getName()); + $this->assertEquals(htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getText()); } /** @@ -56,8 +56,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase */ public function testFont() { - $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle'); - $this->assertEquals($oCheckBox->getFontStyle(), 'fontStyle'); + $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle'); + $this->assertEquals('fontStyle', $oCheckBox->getFontStyle()); $oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle()); @@ -69,8 +69,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase public function testFontObject() { $font = new Font(); - $oCheckBox = new CheckBox('chkBox', 'CheckBox', $font); - $this->assertEquals($oCheckBox->getFontStyle(), $font); + $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $font); + $this->assertEquals($font, $oCheckBox->getFontStyle()); } /** @@ -78,8 +78,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase */ public function testParagraph() { - $oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oCheckBox->getParagraphStyle(), 'paragraphStyle'); + $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle'); + $this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle()); $oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); diff --git a/tests/PhpWord/Tests/Element/FieldTest.php b/tests/PhpWord/Tests/Element/FieldTest.php index 2f9193d4..552b5cf5 100644 --- a/tests/PhpWord/Tests/Element/FieldTest.php +++ b/tests/PhpWord/Tests/Element/FieldTest.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Element; use PhpOffice\PhpWord\Element\Field; -use PhpOffice\PhpWord\PhpWord; /** * Test class for PhpOffice\PhpWord\Element\Field @@ -45,7 +44,7 @@ class FieldTest extends \PHPUnit_Framework_TestCase $oField = new Field('DATE'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); + $this->assertEquals('DATE', $oField->getType()); } /** @@ -53,11 +52,11 @@ class FieldTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithTypeProperties() { - $oField = new Field('DATE', array('dateformat'=>'d-M-yyyy')); + $oField = new Field('DATE', array('dateformat' => 'd-M-yyyy')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); - $this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); + $this->assertEquals('DATE', $oField->getType()); + $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties()); } /** @@ -65,12 +64,12 @@ class FieldTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithTypePropertiesOptions() { - $oField = new Field('DATE', array('dateformat'=>'d-M-yyyy'), array('SakaEraCalendar', 'PreserveFormat')); + $oField = new Field('DATE', array('dateformat' => 'd-M-yyyy'), array('SakaEraCalendar', 'PreserveFormat')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); - $this->assertEquals($oField->getType(), 'DATE'); - $this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); - $this->assertEquals($oField->getOptions(), array('SakaEraCalendar', 'PreserveFormat')); + $this->assertEquals('DATE', $oField->getType()); + $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties()); + $this->assertEquals(array('SakaEraCalendar', 'PreserveFormat'), $oField->getOptions()); } /** diff --git a/tests/PhpWord/Tests/Element/FooterTest.php b/tests/PhpWord/Tests/Element/FooterTest.php index c5d04b41..8fe62894 100644 --- a/tests/PhpWord/Tests/Element/FooterTest.php +++ b/tests/PhpWord/Tests/Element/FooterTest.php @@ -35,7 +35,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase $oFooter = new Footer($iVal); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter); - $this->assertEquals($oFooter->getSectionId(), $iVal); + $this->assertEquals($iVal, $oFooter->getSectionId()); } /** @@ -44,7 +44,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oFooter = new Footer(1); - $element = $oFooter->addText('text'); + $element = $oFooter->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); @@ -56,11 +56,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase public function testAddTextNotUTF8() { $oFooter = new Footer(1); - $element = $oFooter->addText(utf8_decode('ééé')); + $element = $oFooter->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -104,7 +104,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oFooter = new Footer(1); $element = $oFooter->addImage($src); @@ -132,7 +132,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase public function testAddPreserveText() { $oFooter = new Footer(1); - $element = $oFooter->addPreserveText('text'); + $element = $oFooter->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -144,11 +144,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase public function testAddPreserveTextNotUTF8() { $oFooter = new Footer(1); - $element = $oFooter->addPreserveText(utf8_decode('ééé')); + $element = $oFooter->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oFooter->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); } /** @@ -171,7 +171,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oFooter->setRelationId($iVal); - $this->assertEquals($oFooter->getRelationId(), $iVal); + $this->assertEquals($iVal, $oFooter->getRelationId()); $this->assertEquals(Footer::AUTO, $oFooter->getType()); } } diff --git a/tests/PhpWord/Tests/Element/FootnoteTest.php b/tests/PhpWord/Tests/Element/FootnoteTest.php index 2ba015d7..745c602f 100644 --- a/tests/PhpWord/Tests/Element/FootnoteTest.php +++ b/tests/PhpWord/Tests/Element/FootnoteTest.php @@ -35,7 +35,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote); $this->assertCount(0, $oFootnote->getElements()); - $this->assertEquals($oFootnote->getParagraphStyle(), null); + $this->assertNull($oFootnote->getParagraphStyle()); } /** @@ -45,7 +45,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase { $oFootnote = new Footnote('pStyle'); - $this->assertEquals($oFootnote->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oFootnote->getParagraphStyle()); } /** @@ -67,7 +67,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oFootnote = new Footnote(); - $element = $oFootnote->addText('text'); + $element = $oFootnote->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oFootnote->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); @@ -90,7 +90,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase public function testAddLink() { $oFootnote = new Footnote(); - $element = $oFootnote->addLink('http://www.google.fr'); + $element = $oFootnote->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertCount(1, $oFootnote->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); @@ -105,7 +105,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oFootnote->setRelationId($iVal); - $this->assertEquals($oFootnote->getRelationId(), $iVal); + $this->assertEquals($iVal, $oFootnote->getRelationId()); } /** diff --git a/tests/PhpWord/Tests/Element/HeaderTest.php b/tests/PhpWord/Tests/Element/HeaderTest.php index 796b24f0..0bce5e4f 100644 --- a/tests/PhpWord/Tests/Element/HeaderTest.php +++ b/tests/PhpWord/Tests/Element/HeaderTest.php @@ -35,8 +35,8 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $oHeader = new Header($iVal); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader); - $this->assertEquals($oHeader->getSectionId(), $iVal); - $this->assertEquals($oHeader->getType(), Header::AUTO); + $this->assertEquals($iVal, $oHeader->getSectionId()); + $this->assertEquals(Header::AUTO, $oHeader->getType()); } /** @@ -45,11 +45,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oHeader = new Header(1); - $element = $oHeader->addText('text'); + $element = $oHeader->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -58,11 +58,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase public function testAddTextNotUTF8() { $oHeader = new Header(1); - $element = $oHeader->addText(utf8_decode('ééé')); + $element = $oHeader->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oHeader->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -113,7 +113,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oHeader = new Header(1); $element = $oHeader->addImage($src); @@ -141,7 +141,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase public function testAddPreserveText() { $oHeader = new Header(1); - $element = $oHeader->addPreserveText('text'); + $element = $oHeader->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); @@ -153,11 +153,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase public function testAddPreserveTextNotUTF8() { $oHeader = new Header(1); - $element = $oHeader->addPreserveText(utf8_decode('ééé')); + $element = $oHeader->addPreserveText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertCount(1, $oHeader->getElements()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); - $this->assertEquals($element->getText(), array('ééé')); + $this->assertEquals(array(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')), $element->getText()); } /** @@ -165,7 +165,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase */ public function testAddWatermark() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oHeader = new Header(1); $element = $oHeader->addWatermark($src); @@ -192,7 +192,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oHeader->setRelationId($iVal); - $this->assertEquals($oHeader->getRelationId(), $iVal); + $this->assertEquals($iVal, $oHeader->getRelationId()); } /** @@ -204,7 +204,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $oHeader->firstPage(); $oHeader->resetType(); - $this->assertEquals($oHeader->getType(), Header::AUTO); + $this->assertEquals(Header::AUTO, $oHeader->getType()); } /** @@ -215,7 +215,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $oHeader = new Header(1); $oHeader->firstPage(); - $this->assertEquals($oHeader->getType(), Header::FIRST); + $this->assertEquals(Header::FIRST, $oHeader->getType()); } /** @@ -226,7 +226,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase $oHeader = new Header(1); $oHeader->evenPage(); - $this->assertEquals($oHeader->getType(), Header::EVEN); + $this->assertEquals(Header::EVEN, $oHeader->getType()); } /** diff --git a/tests/PhpWord/Tests/Element/ImageTest.php b/tests/PhpWord/Tests/Element/ImageTest.php index 11b33d87..e73abb2a 100644 --- a/tests/PhpWord/Tests/Element/ImageTest.php +++ b/tests/PhpWord/Tests/Element/ImageTest.php @@ -31,14 +31,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $src = __DIR__ . "/../_files/images/firefox.png"; + $src = __DIR__ . '/../_files/images/firefox.png'; $oImage = new Image($src); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage); - $this->assertEquals($oImage->getSource(), $src); - $this->assertEquals($oImage->getMediaId(), md5($src)); - $this->assertEquals($oImage->isWatermark(), false); - $this->assertEquals($oImage->getSourceType(), Image::SOURCE_LOCAL); + $this->assertEquals($src, $oImage->getSource()); + $this->assertEquals(md5($src), $oImage->getMediaId()); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x + $this->assertEquals(false, $oImage->isWatermark()); + $this->assertEquals(Image::SOURCE_LOCAL, $oImage->getSourceType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); } @@ -47,11 +48,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithStyle() { - $src = __DIR__ . "/../_files/images/firefox.png"; + $src = __DIR__ . '/../_files/images/firefox.png'; $oImage = new Image( $src, - array('width' => 210, 'height' => 210, 'align' => 'center', - 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND) + array( + 'width' => 210, + 'height' => 210, + 'align' => 'center', + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND, + ) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); @@ -72,15 +77,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase foreach ($images as $imageData) { list($source, $type, $extension, $createFunction, $imageFunction) = $imageData; - $source = __DIR__ . "/../_files/images/" . $source; + $source = __DIR__ . "/../_files/images/{$source}"; $image = new Image($source); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image); - $this->assertEquals($image->getSource(), $source); - $this->assertEquals($image->getMediaId(), md5($source)); - $this->assertEquals($image->getImageType(), $type); - $this->assertEquals($image->getImageExtension(), $extension); - $this->assertEquals($image->getImageCreateFunction(), $createFunction); - $this->assertEquals($image->getImageFunction(), $imageFunction); + $this->assertEquals($source, $image->getSource()); + $this->assertEquals(md5($source), $image->getMediaId()); + $this->assertEquals($type, $image->getImageType()); + $this->assertEquals($extension, $image->getImageExtension()); + $this->assertEquals($createFunction, $image->getImageCreateFunction()); + $this->assertEquals($imageFunction, $image->getImageFunction()); $this->assertFalse($image->isMemImage()); } } @@ -91,7 +96,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase public function testStyle() { $oImage = new Image( - __DIR__ . "/../_files/images/earth.jpg", + __DIR__ . '/../_files/images/earth.jpg', array('height' => 210, 'align' => 'center') ); @@ -105,7 +110,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testInvalidImageLocal() { - new Image(__DIR__ . "/../_files/images/thisisnotarealimage"); + new Image(__DIR__ . '/../_files/images/thisisnotarealimage'); } /** @@ -135,10 +140,10 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testRelationID() { - $oImage = new Image(__DIR__ . "/../_files/images/earth.jpg", array('width' => 100)); + $oImage = new Image(__DIR__ . '/../_files/images/earth.jpg', array('width' => 100)); $iVal = rand(1, 1000); $oImage->setRelationId($iVal); - $this->assertEquals($oImage->getRelationId(), $iVal); + $this->assertEquals($iVal, $oImage->getRelationId()); } /** @@ -146,7 +151,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase */ public function testArchivedImage() { - $archiveFile = __DIR__ . "/../_files/documents/reader.docx"; + $archiveFile = __DIR__ . '/../_files/documents/reader.docx'; $imageFile = 'word/media/image1.jpeg'; $image = new Image("zip://{$archiveFile}#{$imageFile}"); $this->assertEquals('image/jpeg', $image->getImageType()); diff --git a/tests/PhpWord/Tests/Element/LineTest.php b/tests/PhpWord/Tests/Element/LineTest.php index 5add9a6b..66ab257e 100644 --- a/tests/PhpWord/Tests/Element/LineTest.php +++ b/tests/PhpWord/Tests/Element/LineTest.php @@ -35,7 +35,7 @@ class LineTest extends \PHPUnit_Framework_TestCase $oLine = new Line(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Line', $oLine); - $this->assertEquals($oLine->getStyle(), null); + $this->assertNull($oLine->getStyle()); } /** @@ -45,7 +45,7 @@ class LineTest extends \PHPUnit_Framework_TestCase { $oLine = new Line('lineStyle'); - $this->assertEquals($oLine->getStyle(), 'lineStyle'); + $this->assertEquals('lineStyle', $oLine->getStyle()); } /** @@ -55,19 +55,19 @@ class LineTest extends \PHPUnit_Framework_TestCase { $oLine = new Line( array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), - 'positioning' => 'absolute', + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), + 'positioning' => 'absolute', 'posHorizontalRel' => 'page', - 'posVerticalRel' => 'page', - 'flip' => true, - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), - 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10 + 'posVerticalRel' => 'page', + 'flip' => true, + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), + 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, ) ); diff --git a/tests/PhpWord/Tests/Element/LinkTest.php b/tests/PhpWord/Tests/Element/LinkTest.php index ada6a36a..16bd531a 100644 --- a/tests/PhpWord/Tests/Element/LinkTest.php +++ b/tests/PhpWord/Tests/Element/LinkTest.php @@ -33,13 +33,13 @@ class LinkTest extends \PHPUnit_Framework_TestCase */ public function testConstructDefault() { - $oLink = new Link('http://www.google.com'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); - $this->assertEquals($oLink->getSource(), 'http://www.google.com'); - $this->assertEquals($oLink->getText(), $oLink->getSource()); - $this->assertEquals($oLink->getFontStyle(), null); - $this->assertEquals($oLink->getParagraphStyle(), null); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource()); + $this->assertEquals($oLink->getSource(), $oLink->getText()); + $this->assertNull($oLink->getFontStyle()); + $this->assertNull($oLink->getParagraphStyle()); } /** @@ -48,15 +48,15 @@ class LinkTest extends \PHPUnit_Framework_TestCase public function testConstructWithParamsArray() { $oLink = new Link( - 'http://www.google.com', - 'Search Engine', + 'https://github.com/PHPOffice/PHPWord', + htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); - $this->assertEquals($oLink->getSource(), 'http://www.google.com'); - $this->assertEquals($oLink->getText(), 'Search Engine'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource()); + $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $oLink->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oLink->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle()); } @@ -66,10 +66,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithParamsString() { - $oLink = new Link('http://www.google.com', null, 'fontStyle', 'paragraphStyle'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord', null, 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oLink->getFontStyle(), 'fontStyle'); - $this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); + $this->assertEquals('fontStyle', $oLink->getFontStyle()); + $this->assertEquals('paragraphStyle', $oLink->getParagraphStyle()); } /** @@ -77,10 +77,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase */ public function testRelationId() { - $oLink = new Link('http://www.google.com'); + $oLink = new Link('https://github.com/PHPOffice/PHPWord'); $iVal = rand(1, 1000); $oLink->setRelationId($iVal); - $this->assertEquals($oLink->getRelationId(), $iVal); + $this->assertEquals($iVal, $oLink->getRelationId()); } } diff --git a/tests/PhpWord/Tests/Element/ListItemRunTest.php b/tests/PhpWord/Tests/Element/ListItemRunTest.php index 7bb0c25d..2e003a20 100644 --- a/tests/PhpWord/Tests/Element/ListItemRunTest.php +++ b/tests/PhpWord/Tests/Element/ListItemRunTest.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Element; use PhpOffice\PhpWord\Element\ListItemRun; -use PhpOffice\PhpWord\PhpWord; /** * Test class for PhpOffice\PhpWord\Element\ListItemRun @@ -36,7 +35,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun); $this->assertCount(0, $oListItemRun->getElements()); - $this->assertEquals($oListItemRun->getParagraphStyle(), null); + $this->assertNull($oListItemRun->getParagraphStyle()); } /** @@ -48,7 +47,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun); $this->assertCount(0, $oListItemRun->getElements()); - $this->assertEquals($oListItemRun->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oListItemRun->getParagraphStyle()); } /** @@ -82,8 +81,9 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase $oListItemRun = new ListItemRun(1, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItemRun->getStyle()); - $this->assertEquals($oListItemRun->getStyle()->getListType(), \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER); + $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItemRun->getStyle()->getListType()); } + /** * getDepth */ @@ -92,7 +92,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oListItemRun = new ListItemRun($iVal); - $this->assertEquals($oListItemRun->getDepth(), $iVal); + $this->assertEquals($iVal, $oListItemRun->getDepth()); } /** @@ -101,11 +101,11 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addText('text'); + $element = $oListItemRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -114,11 +114,11 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase public function testAddTextNotUTF8() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addText(utf8_decode('ééé')); + $element = $oListItemRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -127,11 +127,11 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase public function testAddLink() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addLink('http://www.google.fr'); + $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); } /** @@ -140,12 +140,12 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase public function testAddLinkWithName() { $oListItemRun = new ListItemRun(); - $element = $oListItemRun->addLink('http://www.google.fr', utf8_decode('ééé')); + $element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oListItemRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); + $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -164,7 +164,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oListItemRun = new ListItemRun(); $element = $oListItemRun->addImage($src); diff --git a/tests/PhpWord/Tests/Element/ListItemTest.php b/tests/PhpWord/Tests/Element/ListItemTest.php index 1362eb43..f8e76d74 100644 --- a/tests/PhpWord/Tests/Element/ListItemTest.php +++ b/tests/PhpWord/Tests/Element/ListItemTest.php @@ -32,7 +32,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase */ public function testText() { - $oListItem = new ListItem('text'); + $oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject()); } @@ -43,17 +43,14 @@ class ListItemTest extends \PHPUnit_Framework_TestCase public function testStyle() { $oListItem = new ListItem( - 'text', + htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 1, null, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle()); - $this->assertEquals( - $oListItem->getStyle()->getListType(), - \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER - ); + $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType()); } /** @@ -62,8 +59,8 @@ class ListItemTest extends \PHPUnit_Framework_TestCase public function testDepth() { $iVal = rand(1, 1000); - $oListItem = new ListItem('text', $iVal); + $oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $iVal); - $this->assertEquals($oListItem->getDepth(), $iVal); + $this->assertEquals($iVal, $oListItem->getDepth()); } } diff --git a/tests/PhpWord/Tests/Element/ObjectTest.php b/tests/PhpWord/Tests/Element/ObjectTest.php index 6b823134..ae72b3d6 100644 --- a/tests/PhpWord/Tests/Element/ObjectTest.php +++ b/tests/PhpWord/Tests/Element/ObjectTest.php @@ -32,12 +32,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithSupportedFiles() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); - $this->assertEquals($oObject->getSource(), $src); + $this->assertEquals($src, $oObject->getSource()); } /** @@ -47,7 +47,7 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithNotSupportedFiles() { - $src = __DIR__ . "/../_files/xsl/passthrough.xsl"; + $src = __DIR__ . '/../_files/xsl/passthrough.xsl'; $oObject = new Object($src); $oObject->getSource(); } @@ -57,12 +57,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithSupportedFilesAndStyle() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src, array('width' => '230px')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); - $this->assertEquals($oObject->getSource(), $src); + $this->assertEquals($src, $oObject->getSource()); } /** @@ -70,12 +70,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testRelationId() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setRelationId($iVal); - $this->assertEquals($oObject->getRelationId(), $iVal); + $this->assertEquals($iVal, $oObject->getRelationId()); } /** @@ -83,11 +83,11 @@ class ObjectTest extends \PHPUnit_Framework_TestCase */ public function testImageRelationId() { - $src = __DIR__ . "/../_files/documents/sheet.xls"; + $src = __DIR__ . '/../_files/documents/sheet.xls'; $oObject = new Object($src); $iVal = rand(1, 1000); $oObject->setImageRelationId($iVal); - $this->assertEquals($oObject->getImageRelationId(), $iVal); + $this->assertEquals($iVal, $oObject->getImageRelationId()); } } diff --git a/tests/PhpWord/Tests/Element/PreserveTextTest.php b/tests/PhpWord/Tests/Element/PreserveTextTest.php index 5d2e4f3e..51679939 100644 --- a/tests/PhpWord/Tests/Element/PreserveTextTest.php +++ b/tests/PhpWord/Tests/Element/PreserveTextTest.php @@ -34,9 +34,9 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase $oPreserveText = new PreserveText(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $oPreserveText); - $this->assertEquals($oPreserveText->getText(), null); - $this->assertEquals($oPreserveText->getFontStyle(), null); - $this->assertEquals($oPreserveText->getParagraphStyle(), null); + $this->assertNull($oPreserveText->getText()); + $this->assertNull($oPreserveText->getFontStyle()); + $this->assertNull($oPreserveText->getParagraphStyle()); } /** @@ -44,10 +44,10 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase */ public function testConstructWithString() { - $oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph'); - $this->assertEquals($oPreserveText->getText(), array('text')); - $this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); - $this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); + $oPreserveText = new PreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'styleFont', 'styleParagraph'); + $this->assertEquals(array(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')), $oPreserveText->getText()); + $this->assertEquals('styleFont', $oPreserveText->getFontStyle()); + $this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle()); } /** @@ -56,14 +56,11 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase public function testConstructWithArray() { $oPreserveText = new PreserveText( - 'text', + htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), array('align' => 'center'), array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle()); - $this->assertInstanceOf( - 'PhpOffice\\PhpWord\\Style\\Paragraph', - $oPreserveText->getParagraphStyle() - ); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle()); } } diff --git a/tests/PhpWord/Tests/Element/RowTest.php b/tests/PhpWord/Tests/Element/RowTest.php index c377bb7c..446884c6 100644 --- a/tests/PhpWord/Tests/Element/RowTest.php +++ b/tests/PhpWord/Tests/Element/RowTest.php @@ -35,7 +35,7 @@ class RowTest extends \PHPUnit_Framework_TestCase $oRow = new Row(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow); - $this->assertEquals($oRow->getHeight(), null); + $this->assertNull($oRow->getHeight()); $this->assertInternalType('array', $oRow->getCells()); $this->assertCount(0, $oRow->getCells()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); @@ -49,7 +49,7 @@ class RowTest extends \PHPUnit_Framework_TestCase $iVal = rand(1, 1000); $oRow = new Row($iVal, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')); - $this->assertEquals($oRow->getHeight(), $iVal); + $this->assertEquals($iVal, $oRow->getHeight()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); } diff --git a/tests/PhpWord/Tests/Element/SectionTest.php b/tests/PhpWord/Tests/Element/SectionTest.php index 853ebc5d..79a21684 100644 --- a/tests/PhpWord/Tests/Element/SectionTest.php +++ b/tests/PhpWord/Tests/Element/SectionTest.php @@ -36,7 +36,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase public function testGetStyle() { $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getStyle(), 'style', new Section(0)); + $this->assertAttributeEquals($oSection->getStyle(), 'style', $oSection); } /** @@ -45,7 +45,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase public function testGetElements() { $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getElements(), 'elements', new Section(0)); + $this->assertAttributeEquals($oSection->getElements(), 'elements', $oSection); } /** @@ -54,7 +54,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase public function testGetFooters() { $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getFooters(), 'footers', new Section(0)); + $this->assertAttributeEquals($oSection->getFooters(), 'footers', $oSection); } /** @@ -63,7 +63,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase public function testGetHeaders() { $oSection = new Section(0); - $this->assertAttributeEquals($oSection->getHeaders(), 'headers', new Section(0)); + $this->assertAttributeEquals($oSection->getHeaders(), 'headers', $oSection); } /** @@ -82,30 +82,42 @@ class SectionTest extends \PHPUnit_Framework_TestCase */ public function testAddElements() { - $objectSource = __DIR__ . "/../_files/documents/reader.docx"; - $imageSource = __DIR__ . "/../_files/images/PhpWord.png"; + $objectSource = __DIR__ . '/../_files/documents/reader.docx'; + $imageSource = __DIR__ . '/../_files/images/PhpWord.png'; // $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; $section = new Section(0); $section->setPhpWord(new PhpWord()); - $section->addText(utf8_decode('ä')); - $section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); + $section->addText(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); + $section->addLink(utf8_decode('http://äää.com'), utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); $section->addTextBreak(); $section->addPageBreak(); $section->addTable(); - $section->addListItem(utf8_decode('ä')); + $section->addListItem(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8'))); $section->addObject($objectSource); $section->addImage($imageSource); - $section->addTitle(utf8_decode('ä'), 1); + $section->addTitle(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')), 1); $section->addTextRun(); $section->addFootnote(); - $section->addCheckBox(utf8_decode('chkä'), utf8_decode('Contentä')); + $section->addCheckBox(utf8_decode(htmlspecialchars('chkä', ENT_COMPAT, 'UTF-8')), utf8_decode(htmlspecialchars('Contentä', ENT_COMPAT, 'UTF-8'))); $section->addTOC(); $elementCollection = $section->getElements(); - $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', - 'Table', 'ListItem', 'Object', 'Image', - 'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC'); + $elementTypes = array( + 'Text', + 'Link', + 'TextBreak', + 'PageBreak', + 'Table', + 'ListItem', + 'Object', + 'Image', + 'Title', + 'TextRun', + 'Footnote', + 'CheckBox', + 'TOC', + ); $elmCount = 0; foreach ($elementTypes as $elementType) { $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]); @@ -120,7 +132,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase */ public function testAddObjectException() { - $source = __DIR__ . "/_files/xsl/passthrough.xsl"; + $source = __DIR__ . '/_files/xsl/passthrough.xsl'; $section = new Section(0); $section->addObject($source); } @@ -133,10 +145,10 @@ class SectionTest extends \PHPUnit_Framework_TestCase Style::addTitleStyle(1, array('size' => 14)); $section = new Section(0); $section->setPhpWord(new PhpWord()); - $section->addTitle('Test', 1); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $elementCollection = $section->getElements(); - $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\Title", $elementCollection[0]); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]); } /** diff --git a/tests/PhpWord/Tests/Element/TOCTest.php b/tests/PhpWord/Tests/Element/TOCTest.php index d0ebf343..e4d984eb 100644 --- a/tests/PhpWord/Tests/Element/TOCTest.php +++ b/tests/PhpWord/Tests/Element/TOCTest.php @@ -34,9 +34,9 @@ class TOCTest extends \PHPUnit_Framework_TestCase public function testConstructWithStyleArray() { $expected = array( - 'position' => 9062, - 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, - 'indent' => 200, + 'position' => 9062, + 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, + 'indent' => 200, ); $object = new TOC(array('size' => 11), array('position' => $expected['position'])); $tocStyle = $object->getStyleTOC(); @@ -86,7 +86,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase $phpWord = new PhpWord(); foreach ($titles as $text => $depth) { - $phpWord->addTitle(new Title($text, $depth)); + $phpWord->addTitle(new Title(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'), $depth)); } $toc = new TOC(); $toc->setPhpWord($phpWord); diff --git a/tests/PhpWord/Tests/Element/TableTest.php b/tests/PhpWord/Tests/Element/TableTest.php index 0977639f..be5df55c 100644 --- a/tests/PhpWord/Tests/Element/TableTest.php +++ b/tests/PhpWord/Tests/Element/TableTest.php @@ -35,9 +35,9 @@ class TableTest extends \PHPUnit_Framework_TestCase $oTable = new Table(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $oTable); - $this->assertEquals($oTable->getStyle(), null); - $this->assertEquals($oTable->getWidth(), null); - $this->assertEquals($oTable->getRows(), array()); + $this->assertNull($oTable->getStyle()); + $this->assertNull($oTable->getWidth()); + $this->assertEquals(array(), $oTable->getRows()); $this->assertCount(0, $oTable->getRows()); } @@ -48,7 +48,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { $oTable = new Table('tableStyle'); - $this->assertEquals($oTable->getStyle(), 'tableStyle'); + $this->assertEquals('tableStyle', $oTable->getStyle()); } /** @@ -56,11 +56,7 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testStyleArray() { - $oTable = new Table(array( - 'borderSize' => 6, - 'borderColor' => '006699', - 'cellMargin' => 80 - )); + $oTable = new Table(array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); } @@ -71,9 +67,9 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testWidth() { $oTable = new Table(); - $iVal = rand(1, 1000); + $iVal = rand(1, 1000); $oTable->setWidth($iVal); - $this->assertEquals($oTable->getWidth(), $iVal); + $this->assertEquals($iVal, $oTable->getWidth()); } /** @@ -81,7 +77,7 @@ class TableTest extends \PHPUnit_Framework_TestCase */ public function testRow() { - $oTable = new Table(); + $oTable = new Table(); $element = $oTable->addRow(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element); $this->assertCount(1, $oTable->getRows()); diff --git a/tests/PhpWord/Tests/Element/TextBoxTest.php b/tests/PhpWord/Tests/Element/TextBoxTest.php index 2c6da465..0dda4899 100644 --- a/tests/PhpWord/Tests/Element/TextBoxTest.php +++ b/tests/PhpWord/Tests/Element/TextBoxTest.php @@ -35,7 +35,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase $oTextBox = new TextBox(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox); - $this->assertEquals($oTextBox->getStyle(), null); + $this->assertNull($oTextBox->getStyle()); } /** @@ -45,7 +45,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase { $oTextBox = new TextBox('textBoxStyle'); - $this->assertEquals($oTextBox->getStyle(), 'textBoxStyle'); + $this->assertEquals('textBoxStyle', $oTextBox->getStyle()); } /** @@ -55,15 +55,15 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase { $oTextBox = new TextBox( array( - 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5), - 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5), + 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5), + 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5), 'positioning' => 'absolute', - 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4), - 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9), - 'stroke' => 0, + 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4), + 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9), + 'stroke' => 0, 'innerMargin' => 0, - 'borderSize' => 1, - 'borderColor' => '' + 'borderSize' => 1, + 'borderColor' => '', ) ); diff --git a/tests/PhpWord/Tests/Element/TextRunTest.php b/tests/PhpWord/Tests/Element/TextRunTest.php index de62a920..5e2dd856 100644 --- a/tests/PhpWord/Tests/Element/TextRunTest.php +++ b/tests/PhpWord/Tests/Element/TextRunTest.php @@ -36,7 +36,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); - $this->assertEquals($oTextRun->getParagraphStyle(), null); + $this->assertNull($oTextRun->getParagraphStyle()); } /** @@ -48,7 +48,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun); $this->assertCount(0, $oTextRun->getElements()); - $this->assertEquals($oTextRun->getParagraphStyle(), 'pStyle'); + $this->assertEquals('pStyle', $oTextRun->getParagraphStyle()); } /** @@ -69,11 +69,11 @@ class TextRunTest extends \PHPUnit_Framework_TestCase public function testAddText() { $oTextRun = new TextRun(); - $element = $oTextRun->addText('text'); + $element = $oTextRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -82,11 +82,11 @@ class TextRunTest extends \PHPUnit_Framework_TestCase public function testAddTextNotUTF8() { $oTextRun = new TextRun(); - $element = $oTextRun->addText(utf8_decode('ééé')); + $element = $oTextRun->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -95,11 +95,11 @@ class TextRunTest extends \PHPUnit_Framework_TestCase public function testAddLink() { $oTextRun = new TextRun(); - $element = $oTextRun->addLink('http://www.google.fr'); + $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord'); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); } /** @@ -108,12 +108,12 @@ class TextRunTest extends \PHPUnit_Framework_TestCase public function testAddLinkWithName() { $oTextRun = new TextRun(); - $element = $oTextRun->addLink('http://www.google.fr', utf8_decode('ééé')); + $element = $oTextRun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertCount(1, $oTextRun->getElements()); - $this->assertEquals($element->getSource(), 'http://www.google.fr'); - $this->assertEquals($element->getText(), 'ééé'); + $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource()); + $this->assertEquals(htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), $element->getText()); } /** @@ -132,7 +132,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase */ public function testAddImage() { - $src = __DIR__ . "/../_files/images/earth.jpg"; + $src = __DIR__ . '/../_files/images/earth.jpg'; $oTextRun = new TextRun(); $element = $oTextRun->addImage($src); diff --git a/tests/PhpWord/Tests/Element/TextTest.php b/tests/PhpWord/Tests/Element/TextTest.php index a306d4b9..3112dbfa 100644 --- a/tests/PhpWord/Tests/Element/TextTest.php +++ b/tests/PhpWord/Tests/Element/TextTest.php @@ -35,7 +35,7 @@ class TextTest extends \PHPUnit_Framework_TestCase $oText = new Text(); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oText); - $this->assertEquals(null, $oText->getText()); + $this->assertNull($oText->getText()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); } @@ -45,9 +45,9 @@ class TextTest extends \PHPUnit_Framework_TestCase */ public function testText() { - $oText = new Text('text'); + $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); - $this->assertEquals($oText->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oText->getText()); } /** @@ -55,8 +55,8 @@ class TextTest extends \PHPUnit_Framework_TestCase */ public function testFont() { - $oText = new Text('text', 'fontStyle'); - $this->assertEquals($oText->getFontStyle(), 'fontStyle'); + $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle'); + $this->assertEquals('fontStyle', $oText->getFontStyle()); $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); @@ -68,8 +68,8 @@ class TextTest extends \PHPUnit_Framework_TestCase public function testFontObject() { $font = new Font(); - $oText = new Text('text', $font); - $this->assertEquals($oText->getFontStyle(), $font); + $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $font); + $this->assertEquals($font, $oText->getFontStyle()); } /** @@ -77,8 +77,8 @@ class TextTest extends \PHPUnit_Framework_TestCase */ public function testParagraph() { - $oText = new Text('text', 'fontStyle', 'paragraphStyle'); - $this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); + $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle'); + $this->assertEquals('paragraphStyle', $oText->getParagraphStyle()); $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); diff --git a/tests/PhpWord/Tests/Element/TitleTest.php b/tests/PhpWord/Tests/Element/TitleTest.php index ca65c8eb..ee72f7fc 100644 --- a/tests/PhpWord/Tests/Element/TitleTest.php +++ b/tests/PhpWord/Tests/Element/TitleTest.php @@ -32,10 +32,10 @@ class TitleTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $oTitle = new Title('text'); + $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle); - $this->assertEquals($oTitle->getText(), 'text'); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $oTitle->getText()); } /** @@ -43,8 +43,8 @@ class TitleTest extends \PHPUnit_Framework_TestCase */ public function testStyleNull() { - $oTitle = new Title('text'); + $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')); - $this->assertEquals($oTitle->getStyle(), null); + $this->assertNull($oTitle->getStyle()); } } diff --git a/tests/PhpWord/Tests/IOFactoryTest.php b/tests/PhpWord/Tests/IOFactoryTest.php index 60db16d0..1f293b0e 100644 --- a/tests/PhpWord/Tests/IOFactoryTest.php +++ b/tests/PhpWord/Tests/IOFactoryTest.php @@ -74,7 +74,7 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase */ public function testLoad() { - $file = __DIR__ . "/_files/templates/blank.docx"; + $file = __DIR__ . '/_files/templates/blank.docx'; $this->assertInstanceOf( 'PhpOffice\\PhpWord\\PhpWord', IOFactory::load($file) diff --git a/tests/PhpWord/Tests/MediaTest.php b/tests/PhpWord/Tests/MediaTest.php index 0196a7e1..8eef6469 100644 --- a/tests/PhpWord/Tests/MediaTest.php +++ b/tests/PhpWord/Tests/MediaTest.php @@ -32,7 +32,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testGetSectionMediaElementsWithNull() { - $this->assertEquals(Media::getElements('section'), array()); + $this->assertEquals(array(), Media::getElements('section')); } /** @@ -48,8 +48,8 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testAddSectionMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; - $object = __DIR__ . "/_files/documents/sheet.xls"; + $local = __DIR__ . '/_files/images/mars.jpg'; + $object = __DIR__ . '/_files/documents/sheet.xls'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('section', 'image', $local, new Image($local)); Media::addElement('section', 'image', $local, new Image($local)); @@ -77,7 +77,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testAddHeaderMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; + $local = __DIR__ . '/_files/images/mars.jpg'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('header1', 'image', $local, new Image($local)); Media::addElement('header1', 'image', $local, new Image($local)); @@ -92,7 +92,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testAddFooterMediaElement() { - $local = __DIR__ . "/_files/images/mars.jpg"; + $local = __DIR__ . '/_files/images/mars.jpg'; $remote = 'http://php.net/images/logos/php-med-trans-light.gif'; Media::addElement('footer1', 'image', $local, new Image($local)); Media::addElement('footer1', 'image', $local, new Image($local)); @@ -112,6 +112,6 @@ class MediaTest extends \PHPUnit_Framework_TestCase */ public function testAddElementImageException() { - Media::addElement('section', 'image', __DIR__ . "/_files/images/mars.jpg"); + Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg'); } } diff --git a/tests/PhpWord/Tests/Metadata/DocInfoTest.php b/tests/PhpWord/Tests/Metadata/DocInfoTest.php index c860a0d9..d9472eb2 100644 --- a/tests/PhpWord/Tests/Metadata/DocInfoTest.php +++ b/tests/PhpWord/Tests/Metadata/DocInfoTest.php @@ -182,42 +182,22 @@ class DocInfoTest extends \PHPUnit_Framework_TestCase $oProperties->setCustomProperty('key3', 3); $oProperties->setCustomProperty('key4', 4.4); $oProperties->setCustomProperty('key5', 'value5'); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - $oProperties->getCustomPropertyType('key1') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_BOOLEAN, - $oProperties->getCustomPropertyType('key2') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - $oProperties->getCustomPropertyType('key3') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_FLOAT, - $oProperties->getCustomPropertyType('key4') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - $oProperties->getCustomPropertyType('key5') - ); - $this->assertEquals(null, $oProperties->getCustomPropertyType('key6')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key1')); - $this->assertEquals(true, $oProperties->getCustomPropertyValue('key2')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key1')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, $oProperties->getCustomPropertyType('key2')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, $oProperties->getCustomPropertyType('key3')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, $oProperties->getCustomPropertyType('key4')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key5')); + $this->assertNull($oProperties->getCustomPropertyType('key6')); + $this->assertNull($oProperties->getCustomPropertyValue('key1')); + $this->assertTrue($oProperties->getCustomPropertyValue('key2')); $this->assertEquals(3, $oProperties->getCustomPropertyValue('key3')); $this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4')); $this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5')); - $this->assertEquals(null, $oProperties->getCustomPropertyValue('key6')); - $this->assertEquals(true, $oProperties->isCustomPropertySet('key5')); + $this->assertNull($oProperties->getCustomPropertyValue('key6')); + $this->assertTrue($oProperties->isCustomPropertySet('key5')); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, $oProperties->isCustomPropertySet('key6')); - $this->assertEquals(array( - 'key1', - 'key2', - 'key3', - 'key4', - 'key5' - ), $oProperties->getCustomProperties()); + $this->assertEquals(array('key1', 'key2', 'key3', 'key4', 'key5'), $oProperties->getCustomProperties()); } /** @@ -226,49 +206,25 @@ class DocInfoTest extends \PHPUnit_Framework_TestCase public function testConvertProperty() { $this->assertEquals('', DocInfo::convertProperty('a', 'empty')); - $this->assertEquals(null, DocInfo::convertProperty('a', 'null')); + $this->assertNull(DocInfo::convertProperty('a', 'null')); $this->assertEquals(8, DocInfo::convertProperty('8', 'int')); $this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint')); $this->assertEquals(8.3, DocInfo::convertProperty('8.3', 'decimal')); $this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr')); $this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date')); - $this->assertEquals(true, DocInfo::convertProperty('true', 'bool')); + $this->assertTrue(DocInfo::convertProperty('true', 'bool')); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, DocInfo::convertProperty('1', 'bool')); $this->assertEquals('1', DocInfo::convertProperty('1', 'array')); $this->assertEquals('1', DocInfo::convertProperty('1', '')); - - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - DocInfo::convertPropertyType('int') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_INTEGER, - DocInfo::convertPropertyType('uint') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_FLOAT, - DocInfo::convertPropertyType('decimal') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_STRING, - DocInfo::convertPropertyType('lpstr') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_DATE, - DocInfo::convertPropertyType('date') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_BOOLEAN, - DocInfo::convertPropertyType('bool') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_UNKNOWN, - DocInfo::convertPropertyType('array') - ); - $this->assertEquals( - DocInfo::PROPERTY_TYPE_UNKNOWN, - DocInfo::convertPropertyType('') - ); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('int')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('uint')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, DocInfo::convertPropertyType('decimal')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, DocInfo::convertPropertyType('lpstr')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_DATE, DocInfo::convertPropertyType('date')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, DocInfo::convertPropertyType('bool')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('array')); + $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('')); } } diff --git a/tests/PhpWord/Tests/PhpWordTest.php b/tests/PhpWord/Tests/PhpWordTest.php index 85c6a7f2..7fdbd689 100644 --- a/tests/PhpWord/Tests/PhpWordTest.php +++ b/tests/PhpWord/Tests/PhpWordTest.php @@ -124,7 +124,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase */ public function testLoadTemplate() { - $templateFqfn = __DIR__ . "/_files/templates/blank.docx"; + $templateFqfn = __DIR__ . '/_files/templates/blank.docx'; $phpWord = new PhpWord(); $this->assertInstanceOf( diff --git a/tests/PhpWord/Tests/SettingsTest.php b/tests/PhpWord/Tests/SettingsTest.php index 0d3d66ae..fb9b6023 100644 --- a/tests/PhpWord/Tests/SettingsTest.php +++ b/tests/PhpWord/Tests/SettingsTest.php @@ -122,8 +122,8 @@ class SettingsTest extends \PHPUnit_Framework_TestCase public function testLoadConfig() { $expected = array( - 'compatibility' => true, - 'zipClass' => 'ZipArchive', + 'compatibility' => true, + 'zipClass' => 'ZipArchive', 'pdfRendererName' => 'DomPDF', 'pdfRendererPath' => '', 'defaultFontName' => 'Arial', diff --git a/tests/PhpWord/Tests/Shared/HtmlTest.php b/tests/PhpWord/Tests/Shared/HtmlTest.php index c4c0fc9d..de746e82 100644 --- a/tests/PhpWord/Tests/Shared/HtmlTest.php +++ b/tests/PhpWord/Tests/Shared/HtmlTest.php @@ -43,8 +43,8 @@ class HtmlTest extends \PHPUnit_Framework_TestCase } // Styles - $content .= '

'; + $content .= '

'; foreach ($styles as $style) { $content .= "<{$style}>{$style}"; } diff --git a/tests/PhpWord/Tests/Shared/XMLReaderTest.php b/tests/PhpWord/Tests/Shared/XMLReaderTest.php index 2bb6ef65..e82f475a 100644 --- a/tests/PhpWord/Tests/Shared/XMLReaderTest.php +++ b/tests/PhpWord/Tests/Shared/XMLReaderTest.php @@ -35,7 +35,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase */ public function testGetDomFromZipException() { - $filename = __DIR__ . "/../_files/documents/foo.zip"; + $filename = __DIR__ . '/../_files/documents/foo.zip'; $object = new XMLReader(); $object->getDomFromZip($filename, 'yadayadaya'); } @@ -45,7 +45,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase */ public function testGetDomFromZipReturnsFalse() { - $filename = __DIR__ . "/../_files/documents/reader.docx.zip"; + $filename = __DIR__ . '/../_files/documents/reader.docx.zip'; $object = new XMLReader(); $this->assertFalse($object->getDomFromZip($filename, 'yadayadaya')); } @@ -64,7 +64,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase */ public function testGetElementReturnsNull() { - $filename = __DIR__ . "/../_files/documents/reader.docx.zip"; + $filename = __DIR__ . '/../_files/documents/reader.docx.zip'; $object = new XMLReader(); $object->getDomFromZip($filename, '[Content_Types].xml'); diff --git a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php index 11a0d9a3..fa407c2a 100644 --- a/tests/PhpWord/Tests/Shared/ZipArchiveTest.php +++ b/tests/PhpWord/Tests/Shared/ZipArchiveTest.php @@ -67,10 +67,10 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase public function testZipArchive($zipClass = 'ZipArchive') { // Preparation - $existingFile = __DIR__ . "/../_files/documents/sheet.xls"; - $zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; - $destination1 = __DIR__ . "/../_files/documents/extract1"; - $destination2 = __DIR__ . "/../_files/documents/extract2"; + $existingFile = __DIR__ . '/../_files/documents/sheet.xls'; + $zipFile = __DIR__ . '/../_files/documents/ziptest.zip'; + $destination1 = __DIR__ . '/../_files/documents/extract1'; + $destination2 = __DIR__ . '/../_files/documents/extract2'; @mkdir($destination1); @mkdir($destination2); @@ -122,12 +122,12 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase private function deleteDir($dir) { foreach (scandir($dir) as $file) { - if ($file === '.' || $file === '..') { + if ('.' === $file || '..' === $file) { continue; - } elseif (is_file($dir . "/" . $file)) { - unlink($dir . "/" . $file); - } elseif (is_dir($dir . "/" . $file)) { - $this->deleteDir($dir . "/" . $file); + } elseif (is_file($dir . '/' . $file)) { + unlink($dir . '/' . $file); + } elseif (is_dir($dir . '/' . $file)) { + $this->deleteDir($dir . '/' . $file); } } diff --git a/tests/PhpWord/Tests/Style/AbstractStyleTest.php b/tests/PhpWord/Tests/Style/AbstractStyleTest.php index d35e1090..946e1f15 100644 --- a/tests/PhpWord/Tests/Style/AbstractStyleTest.php +++ b/tests/PhpWord/Tests/Style/AbstractStyleTest.php @@ -42,7 +42,7 @@ class AbstractStyleTest extends \PHPUnit_Framework_TestCase { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); - $this->assertEquals(true, self::callProtectedMethod($stub, 'setBoolVal', array(true, false))); + $this->assertTrue(self::callProtectedMethod($stub, 'setBoolVal', array(true, false))); $this->assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', array(12, 200))); $this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array(871.1, 2.1))); $this->assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', array('871.1', 2.1))); @@ -56,6 +56,7 @@ class AbstractStyleTest extends \PHPUnit_Framework_TestCase { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); + // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x $this->assertEquals(false, self::callProtectedMethod($stub, 'setBoolVal', array('a', false))); $this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200))); $this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1))); diff --git a/tests/PhpWord/Tests/Style/CellTest.php b/tests/PhpWord/Tests/Style/CellTest.php index f9131728..4f058f0c 100644 --- a/tests/PhpWord/Tests/Style/CellTest.php +++ b/tests/PhpWord/Tests/Style/CellTest.php @@ -35,19 +35,19 @@ class CellTest extends \PHPUnit_Framework_TestCase $object = new Cell(); $attributes = array( - 'valign' => Cell::VALIGN_TOP, - 'textDirection' => Cell::TEXT_DIR_BTLR, - 'bgColor' => 'FFFF00', - 'borderTopSize' => 120, - 'borderTopColor' => 'FFFF00', - 'borderLeftSize' => 120, - 'borderLeftColor' => 'FFFF00', - 'borderRightSize' => 120, - 'borderRightColor' => 'FFFF00', - 'borderBottomSize' => 120, + 'valign' => Cell::VALIGN_TOP, + 'textDirection' => Cell::TEXT_DIR_BTLR, + 'bgColor' => 'FFFF00', + 'borderTopSize' => 120, + 'borderTopColor' => 'FFFF00', + 'borderLeftSize' => 120, + 'borderLeftColor' => 'FFFF00', + 'borderRightSize' => 120, + 'borderRightColor' => 'FFFF00', + 'borderBottomSize' => 120, 'borderBottomColor' => 'FFFF00', - 'gridSpan' => 2, - 'vMerge' => Cell::VMERGE_RESTART, + 'gridSpan' => 2, + 'vMerge' => Cell::VMERGE_RESTART, ); foreach ($attributes as $key => $value) { $set = "set{$key}"; diff --git a/tests/PhpWord/Tests/Style/FontTest.php b/tests/PhpWord/Tests/Style/FontTest.php index c21ea4ce..23b2eae4 100644 --- a/tests/PhpWord/Tests/Style/FontTest.php +++ b/tests/PhpWord/Tests/Style/FontTest.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Style; use PhpOffice\PhpWord\PhpWord; -use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Tests\TestHelperDOCX; @@ -42,9 +41,9 @@ class FontTest extends \PHPUnit_Framework_TestCase */ public function testInitiation() { - $object = new Font('text', array('align' => 'both')); + $object = new Font(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), array('align' => 'both')); - $this->assertEquals('text', $object->getStyleType()); + $this->assertEquals(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $object->getStyleType()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle()); $this->assertTrue(is_array($object->getStyleValues())); } @@ -57,31 +56,31 @@ class FontTest extends \PHPUnit_Framework_TestCase $object = new Font(); $attributes = array( - 'name' => null, - 'size' => null, - 'hint' => null, - 'color' => null, - 'bold' => false, - 'italic' => false, - 'underline' => Font::UNDERLINE_NONE, - 'superScript' => false, - 'subScript' => false, - 'strikethrough' => false, + 'name' => null, + 'size' => null, + 'hint' => null, + 'color' => null, + 'bold' => false, + 'italic' => false, + 'underline' => Font::UNDERLINE_NONE, + 'superScript' => false, + 'subScript' => false, + 'strikethrough' => false, 'doubleStrikethrough' => false, - 'smallCaps' => false, - 'allCaps' => false, - 'fgColor' => null, - 'bgColor' => null, - 'scale' => null, - 'spacing' => null, - 'kerning' => null, + 'smallCaps' => false, + 'allCaps' => false, + 'fgColor' => null, + 'bgColor' => null, + 'scale' => null, + 'spacing' => null, + 'kerning' => null, ); foreach ($attributes as $key => $default) { $get = is_bool($default) ? "is{$key}" : "get{$key}"; $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", null); + $object->setStyleValue($key, null); $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", ''); + $object->setStyleValue($key, ''); $this->assertEquals($default, $object->$get()); } } @@ -94,25 +93,25 @@ class FontTest extends \PHPUnit_Framework_TestCase $object = new Font(); $attributes = array( - 'name' => 'Times New Roman', - 'size' => 9, - 'color' => '999999', - 'hint' => 'eastAsia', - 'bold' => true, - 'italic' => true, - 'underline' => Font::UNDERLINE_HEAVY, - 'superScript' => true, - 'subScript' => false, - 'strikethrough' => true, + 'name' => 'Times New Roman', + 'size' => 9, + 'color' => '999999', + 'hint' => 'eastAsia', + 'bold' => true, + 'italic' => true, + 'underline' => Font::UNDERLINE_HEAVY, + 'superScript' => true, + 'subScript' => false, + 'strikethrough' => true, 'doubleStrikethrough' => false, - 'smallCaps' => true, - 'allCaps' => false, - 'fgColor' => Font::FGCOLOR_YELLOW, - 'bgColor' => 'FFFF00', - 'lineHeight' => 2, - 'scale' => 150, - 'spacing' => 240, - 'kerning' => 10, + 'smallCaps' => true, + 'allCaps' => false, + 'fgColor' => Font::FGCOLOR_YELLOW, + 'bgColor' => 'FFFF00', + 'lineHeight' => 2, + 'scale' => 150, + 'spacing' => 240, + 'kerning' => 10, ); $object->setStyleByArray($attributes); foreach ($attributes as $key => $value) { @@ -130,9 +129,7 @@ class FontTest extends \PHPUnit_Framework_TestCase $section = $phpWord->addSection(); // Test style array - $text = $section->addText('This is a test', array( - 'line-height' => 2.0 - )); + $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); diff --git a/tests/PhpWord/Tests/Style/ImageTest.php b/tests/PhpWord/Tests/Style/ImageTest.php index 1a679da3..08ec9a99 100644 --- a/tests/PhpWord/Tests/Style/ImageTest.php +++ b/tests/PhpWord/Tests/Style/ImageTest.php @@ -35,12 +35,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase $object = new Image(); $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline' + 'width' => 200, + 'height' => 200, + 'align' => 'left', + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -58,16 +58,16 @@ class ImageTest extends \PHPUnit_Framework_TestCase $object = new Image(); $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, - 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, - 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, + 'width' => 200, + 'height' => 200, + 'align' => 'left', + 'marginTop' => 240, + 'marginLeft' => 240, + 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, + 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, + 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN, - 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_IMARGIN + 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_IMARGIN, ); foreach ($properties as $key => $value) { $get = "get{$key}"; diff --git a/tests/PhpWord/Tests/Style/IndentationTest.php b/tests/PhpWord/Tests/Style/IndentationTest.php index d0e88f2c..9c997c38 100644 --- a/tests/PhpWord/Tests/Style/IndentationTest.php +++ b/tests/PhpWord/Tests/Style/IndentationTest.php @@ -33,10 +33,10 @@ class IndentationTest extends \PHPUnit_Framework_TestCase { $object = new Indentation(); $properties = array( - 'left' => array(0, 10), - 'right' => array(0, 10), + 'left' => array(0, 10), + 'right' => array(0, 10), 'firstLine' => array(null, 20), - 'hanging' => array(null, 20), + 'hanging' => array(null, 20), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/LineNumberingTest.php b/tests/PhpWord/Tests/Style/LineNumberingTest.php index bc4dc603..5b8e3f9e 100644 --- a/tests/PhpWord/Tests/Style/LineNumberingTest.php +++ b/tests/PhpWord/Tests/Style/LineNumberingTest.php @@ -33,10 +33,10 @@ class LineNumberingTest extends \PHPUnit_Framework_TestCase { $object = new LineNumbering(); $properties = array( - 'start' => array(1, 2), + 'start' => array(1, 2), 'increment' => array(1, 10), - 'distance' => array(null, 10), - 'restart' => array(null, 'continuous'), + 'distance' => array(null, 10), + 'restart' => array(null, 'continuous'), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/LineTest.php b/tests/PhpWord/Tests/Style/LineTest.php index 02d5ba16..a574120d 100644 --- a/tests/PhpWord/Tests/Style/LineTest.php +++ b/tests/PhpWord/Tests/Style/LineTest.php @@ -36,11 +36,11 @@ class LineTest extends \PHPUnit_Framework_TestCase $properties = array( 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10, - 'color' => 'red' + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, + 'color' => 'red', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -59,11 +59,11 @@ class LineTest extends \PHPUnit_Framework_TestCase $properties = array( 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, - 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, - 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, - 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, - 'weight' => 10, - 'color' => 'red' + 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, + 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, + 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, + 'weight' => 10, + 'color' => 'red', ); foreach ($properties as $key => $value) { $get = "get{$key}"; @@ -71,13 +71,13 @@ class LineTest extends \PHPUnit_Framework_TestCase $this->assertEquals($value, $object->$get()); } } - + /** * Test set/get flip */ public function testSetGetFlip() { - $expected=true; + $expected = true; $object = new Line(); $object->setFlip($expected); $this->assertEquals($expected, $object->isFlip()); @@ -88,18 +88,18 @@ class LineTest extends \PHPUnit_Framework_TestCase */ public function testSetGetConnectorType() { - $expected=\PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT; + $expected = \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT; $object = new Line(); $object->setConnectorType($expected); $this->assertEquals($expected, $object->getConnectorType()); } - + /** * Test set/get weight */ public function testSetGetWeight() { - $expected=10; + $expected = 10; $object = new Line(); $object->setWeight($expected); $this->assertEquals($expected, $object->getWeight()); @@ -110,7 +110,7 @@ class LineTest extends \PHPUnit_Framework_TestCase */ public function testSetGetColor() { - $expected='red'; + $expected = 'red'; $object = new Line(); $object->setColor($expected); $this->assertEquals($expected, $object->getColor()); @@ -121,7 +121,7 @@ class LineTest extends \PHPUnit_Framework_TestCase */ public function testSetGetDash() { - $expected=\PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT; + $expected = \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT; $object = new Line(); $object->setDash($expected); $this->assertEquals($expected, $object->getDash()); @@ -132,7 +132,7 @@ class LineTest extends \PHPUnit_Framework_TestCase */ public function testSetGetBeginArrow() { - $expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK; + $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK; $object = new Line(); $object->setBeginArrow($expected); $this->assertEquals($expected, $object->getBeginArrow()); @@ -143,7 +143,7 @@ class LineTest extends \PHPUnit_Framework_TestCase */ public function testSetGetEndArrow() { - $expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC; + $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC; $object = new Line(); $object->setEndArrow($expected); $this->assertEquals($expected, $object->getEndArrow()); diff --git a/tests/PhpWord/Tests/Style/NumberingLevelTest.php b/tests/PhpWord/Tests/Style/NumberingLevelTest.php index 8959a983..69864bdc 100644 --- a/tests/PhpWord/Tests/Style/NumberingLevelTest.php +++ b/tests/PhpWord/Tests/Style/NumberingLevelTest.php @@ -34,19 +34,19 @@ class NumberingLevelTest extends \PHPUnit_Framework_TestCase $object = new NumberingLevel(); $attributes = array( - 'level' => 1, - 'start' => 1, - 'format' => 'decimal', + 'level' => 1, + 'start' => 1, + 'format' => 'decimal', 'restart' => 1, - 'pStyle' => 'pStyle', - 'suffix' => 'space', - 'text' => '%1.', - 'align' => 'left', - 'left' => 360, + 'pStyle' => 'pStyle', + 'suffix' => 'space', + 'text' => '%1.', + 'align' => 'left', + 'left' => 360, 'hanging' => 360, - 'tabPos' => 360, - 'font' => 'Arial', - 'hint' => 'default', + 'tabPos' => 360, + 'font' => 'Arial', + 'hint' => 'default', ); foreach ($attributes as $key => $value) { $set = "set{$key}"; diff --git a/tests/PhpWord/Tests/Style/NumberingTest.php b/tests/PhpWord/Tests/Style/NumberingTest.php index e1575357..ca7f0cb0 100644 --- a/tests/PhpWord/Tests/Style/NumberingTest.php +++ b/tests/PhpWord/Tests/Style/NumberingTest.php @@ -33,8 +33,8 @@ class NumberingTest extends \PHPUnit_Framework_TestCase { $this->object = new Numbering(); $this->properties = array( - 'numId' => array(null, 1), - 'type' => array(null, 'singleLevel'), + 'numId' => array(null, 1), + 'type' => array(null, 'singleLevel'), ); foreach ($this->properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/ParagraphTest.php b/tests/PhpWord/Tests/Style/ParagraphTest.php index 73540b0c..48d47172 100644 --- a/tests/PhpWord/Tests/Style/ParagraphTest.php +++ b/tests/PhpWord/Tests/Style/ParagraphTest.php @@ -45,16 +45,16 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase $object = new Paragraph(); $attributes = array( - 'widowControl' => true, - 'keepNext' => false, - 'keepLines' => false, + 'widowControl' => true, + 'keepNext' => false, + 'keepLines' => false, 'pageBreakBefore' => false, ); foreach ($attributes as $key => $default) { $get = "get{$key}"; - $object->setStyleValue("$key", null); + $object->setStyleValue($key, null); $this->assertEquals($default, $object->$get()); - $object->setStyleValue("$key", ''); + $object->setStyleValue($key, ''); $this->assertEquals($default, $object->$get()); } } @@ -67,31 +67,31 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase $object = new Paragraph(); $attributes = array( - 'align' => 'justify', - 'spaceAfter' => 240, - 'spaceBefore' => 240, - 'indent' => 1, - 'hanging' => 1, - 'spacing' => 120, - 'basedOn' => 'Normal', - 'next' => 'Normal', - 'numStyle' => 'numStyle', - 'numLevel' => 1, - 'widowControl' => false, - 'keepNext' => true, - 'keepLines' => true, + 'align' => 'justify', + 'spaceAfter' => 240, + 'spaceBefore' => 240, + 'indent' => 1, + 'hanging' => 1, + 'spacing' => 120, + 'basedOn' => 'Normal', + 'next' => 'Normal', + 'numStyle' => 'numStyle', + 'numLevel' => 1, + 'widowControl' => false, + 'keepNext' => true, + 'keepLines' => true, 'pageBreakBefore' => true, ); foreach ($attributes as $key => $value) { $get = "get{$key}"; $object->setStyleValue("$key", $value); - if ($key == 'align') { - if ($value == 'justify') { + if ('align' == $key) { + if ('justify' == $value) { $value = 'both'; } - } elseif ($key == 'indent' || $key == 'hanging') { + } elseif ('indent' == $key || 'hanging' == $key) { $value = $value * 720; - } elseif ($key == 'spacing') { + } elseif ('spacing' == $key) { $value += 240; } $this->assertEquals($value, $object->$get()); @@ -131,9 +131,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase $section = $phpWord->addSection(); // Test style array - $text = $section->addText('This is a test', array(), array( - 'line-height' => 2.0 - )); + $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array(), array('line-height' => 2.0)); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); diff --git a/tests/PhpWord/Tests/Style/RowTest.php b/tests/PhpWord/Tests/Style/RowTest.php index 679e9982..757dbadb 100644 --- a/tests/PhpWord/Tests/Style/RowTest.php +++ b/tests/PhpWord/Tests/Style/RowTest.php @@ -35,8 +35,8 @@ class RowTest extends \PHPUnit_Framework_TestCase $object = new Row(); $properties = array( - 'tblHeader' => true, - 'cantSplit' => false, + 'tblHeader' => true, + 'cantSplit' => false, 'exactHeight' => true, ); foreach ($properties as $key => $value) { @@ -63,8 +63,8 @@ class RowTest extends \PHPUnit_Framework_TestCase $object = new Row(); $properties = array( - 'tblHeader' => 'a', - 'cantSplit' => 'b', + 'tblHeader' => 'a', + 'cantSplit' => 'b', 'exactHeight' => 'c', ); foreach ($properties as $key => $value) { diff --git a/tests/PhpWord/Tests/Style/SectionTest.php b/tests/PhpWord/Tests/Style/SectionTest.php index e5becd72..10e40605 100644 --- a/tests/PhpWord/Tests/Style/SectionTest.php +++ b/tests/PhpWord/Tests/Style/SectionTest.php @@ -64,8 +64,15 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $this->assertEquals($iVal, $oSettings->getHeaderHeight()); $oSettings->setSettingValue('lineNumbering', array()); - $oSettings->setSettingValue('lineNumbering', array('start' => 1, 'increment' => 1, - 'distance' => 240, 'restart' => 'newPage')); + $oSettings->setSettingValue( + 'lineNumbering', + array( + 'start' => 1, + 'increment' => 1, + 'distance' => 240, + 'restart' => 'newPage', + ) + ); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering()); $oSettings->setSettingValue('lineNumbering', null); diff --git a/tests/PhpWord/Tests/Style/SpacingTest.php b/tests/PhpWord/Tests/Style/SpacingTest.php index a4022b74..30b1ccce 100644 --- a/tests/PhpWord/Tests/Style/SpacingTest.php +++ b/tests/PhpWord/Tests/Style/SpacingTest.php @@ -34,9 +34,9 @@ class SpacingTest extends \PHPUnit_Framework_TestCase $object = new Spacing(); $properties = array( 'before' => array(null, 10), - 'after' => array(null, 10), - 'line' => array(null, 10), - 'rule' => array('auto', 'exact'), + 'after' => array(null, 10), + 'line' => array(null, 10), + 'rule' => array('auto', 'exact'), ); foreach ($properties as $property => $value) { list($default, $expected) = $value; diff --git a/tests/PhpWord/Tests/Style/TableTest.php b/tests/PhpWord/Tests/Style/TableTest.php index 2afbab74..e63d8678 100644 --- a/tests/PhpWord/Tests/Style/TableTest.php +++ b/tests/PhpWord/Tests/Style/TableTest.php @@ -57,26 +57,26 @@ class TableTest extends \PHPUnit_Framework_TestCase $object = new Table(); $attributes = array( - 'bgColor' => 'FF0000', - 'borderTopSize' => 4, - 'borderTopColor' => 'FF0000', - 'borderLeftSize' => 4, - 'borderLeftColor' => 'FF0000', - 'borderRightSize' => 4, - 'borderRightColor' => 'FF0000', - 'borderBottomSize' => 4, - 'borderBottomColor' => 'FF0000', - 'borderInsideHSize' => 4, + 'bgColor' => 'FF0000', + 'borderTopSize' => 4, + 'borderTopColor' => 'FF0000', + 'borderLeftSize' => 4, + 'borderLeftColor' => 'FF0000', + 'borderRightSize' => 4, + 'borderRightColor' => 'FF0000', + 'borderBottomSize' => 4, + 'borderBottomColor' => 'FF0000', + 'borderInsideHSize' => 4, 'borderInsideHColor' => 'FF0000', - 'borderInsideVSize' => 4, + 'borderInsideVSize' => 4, 'borderInsideVColor' => 'FF0000', - 'cellMarginTop' => 240, - 'cellMarginLeft' => 240, - 'cellMarginRight' => 240, - 'cellMarginBottom' => 240, - 'align' => 'center', - 'width' => 100, - 'unit' => 'pct', + 'cellMarginTop' => 240, + 'cellMarginLeft' => 240, + 'cellMarginRight' => 240, + 'cellMarginBottom' => 240, + 'align' => 'center', + 'width' => 100, + 'unit' => 'pct', ); foreach ($attributes as $key => $value) { $set = "set{$key}"; @@ -162,14 +162,8 @@ class TableTest extends \PHPUnit_Framework_TestCase $object->setStyleValue('cellMargin', 240); $object->setStyleValue('borderColor', '999999'); - $this->assertEquals( - array(120, 120, 120, 120, 120, 120), - $object->getBorderSize() - ); - $this->assertEquals( - array(240, 240, 240, 240), - $object->getCellMargin() - ); + $this->assertEquals(array(120, 120, 120, 120, 120, 120), $object->getBorderSize()); + $this->assertEquals(array(240, 240, 240, 240), $object->getCellMargin()); $this->assertEquals( array('999999', '999999', '999999', '999999', '999999', '999999'), $object->getBorderColor() diff --git a/tests/PhpWord/Tests/Style/TextBoxTest.php b/tests/PhpWord/Tests/Style/TextBoxTest.php index cd2d8695..eb1a31a4 100644 --- a/tests/PhpWord/Tests/Style/TextBoxTest.php +++ b/tests/PhpWord/Tests/Style/TextBoxTest.php @@ -33,25 +33,25 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase public function testSetGetNormal() { $object = new TextBox(); - + $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'align' => 'left', + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red' + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', ); foreach ($properties as $key => $value) { $set = "set{$key}"; @@ -60,32 +60,32 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase $this->assertEquals($value, $object->$get()); } } - + /** * Test setStyleValue method */ public function testSetStyleValue() { $object = new TextBox(); - + $properties = array( - 'width' => 200, - 'height' => 200, - 'align' => 'left', - 'marginTop' => 240, - 'marginLeft' => 240, - 'wrappingStyle' => 'inline', - 'positioning' => 'absolute', - 'posHorizontal' => 'center', - 'posVertical' => 'top', - 'posHorizontalRel' => 'margin', - 'posVerticalRel' => 'page', - 'innerMarginTop' => '5', - 'innerMarginRight' => '5', + 'width' => 200, + 'height' => 200, + 'align' => 'left', + 'marginTop' => 240, + 'marginLeft' => 240, + 'wrappingStyle' => 'inline', + 'positioning' => 'absolute', + 'posHorizontal' => 'center', + 'posVertical' => 'top', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'page', + 'innerMarginTop' => '5', + 'innerMarginRight' => '5', 'innerMarginBottom' => '5', - 'innerMarginLeft' => '5', - 'borderSize' => '2', - 'borderColor' => 'red' + 'innerMarginLeft' => '5', + 'borderSize' => '2', + 'borderColor' => 'red', ); foreach ($properties as $key => $value) { $get = "get{$key}"; @@ -93,7 +93,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase $this->assertEquals($value, $object->$get()); } } - + /** * Test setWrappingStyle exception * @@ -104,35 +104,35 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase $object = new TextBox(); $object->setWrappingStyle('foo'); } - + /** * Test set/get width */ public function testSetGetWidth() { - $expected=200; + $expected = 200; $object = new TextBox(); $object->setWidth($expected); $this->assertEquals($expected, $object->getWidth()); } - + /** * Test set/get height */ public function testSetGetHeight() { - $expected=200; + $expected = 200; $object = new TextBox(); $object->setHeight($expected); $this->assertEquals($expected, $object->getHeight()); } - + /** * Test set/get height */ public function testSetGetAlign() { - $expected='left'; + $expected = 'left'; $object = new TextBox(); $object->setAlign($expected); $this->assertEquals($expected, $object->getAlign()); @@ -143,28 +143,29 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase */ public function testSetGetMarginTop() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setMarginTop($expected); $this->assertEquals($expected, $object->getMarginTop()); } - + /** * Test set/get marginLeft */ public function testSetGetMarginLeft() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setMarginLeft($expected); $this->assertEquals($expected, $object->getMarginLeft()); } + /** * Test set/get innerMarginTop */ public function testSetGetInnerMarginTop() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginTop($expected); $this->assertEquals($expected, $object->getInnerMarginTop()); @@ -175,96 +176,96 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase */ public function testSetGetWrappingStyle() { - $expected='inline'; + $expected = 'inline'; $object = new TextBox(); $object->setWrappingStyle($expected); $this->assertEquals($expected, $object->getWrappingStyle()); } - + /** * Test set/get positioning */ public function testSetGetPositioning() { - $expected='absolute'; + $expected = 'absolute'; $object = new TextBox(); $object->setPositioning($expected); $this->assertEquals($expected, $object->getPositioning()); } - + /** * Test set/get posHorizontal */ public function testSetGetPosHorizontal() { - $expected='center'; + $expected = 'center'; $object = new TextBox(); $object->setPosHorizontal($expected); $this->assertEquals($expected, $object->getPosHorizontal()); } - + /** * Test set/get posVertical */ public function testSetGetPosVertical() { - $expected='top'; + $expected = 'top'; $object = new TextBox(); $object->setPosVertical($expected); $this->assertEquals($expected, $object->getPosVertical()); } - + /** * Test set/get posHorizontalRel */ public function testSetGetPosHorizontalRel() { - $expected='margin'; + $expected = 'margin'; $object = new TextBox(); $object->setPosHorizontalRel($expected); $this->assertEquals($expected, $object->getPosHorizontalRel()); } - + /** * Test set/get posVerticalRel */ public function testSetGetPosVerticalRel() { - $expected='page'; + $expected = 'page'; $object = new TextBox(); $object->setPosVerticalRel($expected); $this->assertEquals($expected, $object->getPosVerticalRel()); } - - + + /** * Test set/get innerMarginRight */ public function testSetGetInnerMarginRight() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginRight($expected); $this->assertEquals($expected, $object->getInnerMarginRight()); } - + /** * Test set/get innerMarginBottom */ public function testSetGetInnerMarginBottom() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginBottom($expected); $this->assertEquals($expected, $object->getInnerMarginBottom()); } - + /** * Test set/get innerMarginLeft */ public function testSetGetInnerMarginLeft() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMarginLeft($expected); $this->assertEquals($expected, $object->getInnerMarginLeft()); @@ -275,7 +276,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase */ public function testSetGetInnerMargin() { - $expected=5; + $expected = 5; $object = new TextBox(); $object->setInnerMargin($expected); $this->assertEquals(array($expected, $expected, $expected, $expected), $object->getInnerMargin()); @@ -286,18 +287,18 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase */ public function testSetGetBorderSize() { - $expected=2; + $expected = 2; $object = new TextBox(); $object->setBorderSize($expected); $this->assertEquals($expected, $object->getBorderSize()); } - + /** * Test set/get borderColor */ public function testSetGetBorderColor() { - $expected='red'; + $expected = 'red'; $object = new TextBox(); $object->setBorderColor($expected); $this->assertEquals($expected, $object->getBorderColor()); diff --git a/tests/PhpWord/Tests/StyleTest.php b/tests/PhpWord/Tests/StyleTest.php index 6165e4fd..261de31c 100644 --- a/tests/PhpWord/Tests/StyleTest.php +++ b/tests/PhpWord/Tests/StyleTest.php @@ -86,6 +86,6 @@ class StyleTest extends \PHPUnit_Framework_TestCase Style::setDefaultParagraphStyle($paragraph); - $this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\Paragraph", Style::getStyle('Normal')); + $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', Style::getStyle('Normal')); } } diff --git a/tests/PhpWord/Tests/TemplateProcessorTest.php b/tests/PhpWord/Tests/TemplateProcessorTest.php index 04d1e777..69b4f998 100644 --- a/tests/PhpWord/Tests/TemplateProcessorTest.php +++ b/tests/PhpWord/Tests/TemplateProcessorTest.php @@ -51,14 +51,14 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase $templateZip = new \ZipArchive(); $templateZip->open($templateFqfn); $templateXml = $templateZip->getFromName('word/document.xml'); - if ($templateZip->close() === false) { + if (false === $templateZip->close()) { throw new \Exception("Could not close zip file \"{$templateZip}\"."); } $documentZip = new \ZipArchive(); $documentZip->open($documentFqfn); $documentXml = $documentZip->getFromName('word/document.xml'); - if ($documentZip->close() === false) { + if (false === $documentZip->close()) { throw new \Exception("Could not close zip file \"{$documentZip}\"."); } @@ -78,19 +78,19 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase */ final public function testXslStyleSheetCanBeApplied($actualDocumentFqfn) { - $expectedDocumentFqfn = __DIR__ . "/_files/documents/without_table_macros.docx"; + $expectedDocumentFqfn = __DIR__ . '/_files/documents/without_table_macros.docx'; $actualDocumentZip = new \ZipArchive(); $actualDocumentZip->open($actualDocumentFqfn); $actualDocumentXml = $actualDocumentZip->getFromName('word/document.xml'); - if ($actualDocumentZip->close() === false) { + if (false === $actualDocumentZip->close()) { throw new \Exception("Could not close zip file \"{$actualDocumentFqfn}\"."); } $expectedDocumentZip = new \ZipArchive(); $expectedDocumentZip->open($expectedDocumentFqfn); $expectedDocumentXml = $expectedDocumentZip->getFromName('word/document.xml'); - if ($expectedDocumentZip->close() === false) { + if (false === $expectedDocumentZip->close()) { throw new \Exception("Could not close zip file \"{$expectedDocumentFqfn}\"."); } @@ -116,7 +116,7 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure. * This warning fails the test. */ - @$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => 'somevalue')); + @$templateProcessor->applyXslStyleSheet($xslDOMDocument, array(1 => htmlspecialchars('somevalue', ENT_COMPAT, 'UTF-8'))); } /** @@ -157,9 +157,9 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase ); $docName = 'clone-test-result.docx'; - $templateProcessor->setValue('tableHeader', utf8_decode('ééé')); + $templateProcessor->setValue('tableHeader', utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8'))); $templateProcessor->cloneRow('userId', 1); - $templateProcessor->setValue('userId#1', 'Test'); + $templateProcessor->setValue('userId#1', htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $templateProcessor->saveAs($docName); $docFound = file_exists($docName); unlink($docName); @@ -181,9 +181,9 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase ); $docName = 'header-footer-test-result.docx'; - $templateProcessor->setValue('headerValue', 'Header Value'); - $templateProcessor->setValue('documentContent', 'Document text.'); - $templateProcessor->setValue('footerValue', 'Footer Value'); + $templateProcessor->setValue('headerValue', htmlspecialchars('Header Value', ENT_COMPAT, 'UTF-8')); + $templateProcessor->setValue('documentContent', htmlspecialchars('Document text.', ENT_COMPAT, 'UTF-8')); + $templateProcessor->setValue('footerValue', htmlspecialchars('Footer Value', ENT_COMPAT, 'UTF-8')); $templateProcessor->saveAs($docName); $docFound = file_exists($docName); unlink($docName); diff --git a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php b/tests/PhpWord/Tests/Writer/HTML/ElementTest.php index ae136d34..0c8dfa3e 100644 --- a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/HTML/ElementTest.php @@ -17,8 +17,8 @@ namespace PhpOffice\PhpWord\Tests\Writer\HTML; use PhpOffice\PhpWord\Element\Text as TextElement; -use PhpOffice\PhpWord\Writer\HTML; use PhpOffice\PhpWord\Writer\HTML\Element\Text; +use PhpOffice\PhpWord\Writer\HTML; /** * Test class for PhpOffice\PhpWord\Writer\HTML\Element subnamespace @@ -46,11 +46,11 @@ class ElementTest extends \PHPUnit_Framework_TestCase */ public function testWriteTextElement() { - $object = new Text(new HTML(), new TextElement('A')); - $object->setOpeningText('-'); - $object->setClosingText('-'); + $object = new Text(new HTML(), new TextElement(htmlspecialchars('A', ENT_COMPAT, 'UTF-8'))); + $object->setOpeningText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8')); + $object->setClosingText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8')); $object->setWithoutP(true); - $this->assertEquals('-A-', $object->write()); + $this->assertEquals(htmlspecialchars('-A-', ENT_COMPAT, 'UTF-8'), $object->write()); } } diff --git a/tests/PhpWord/Tests/Writer/HTMLTest.php b/tests/PhpWord/Tests/Writer/HTMLTest.php index c3339d1a..7bdfc710 100644 --- a/tests/PhpWord/Tests/Writer/HTMLTest.php +++ b/tests/PhpWord/Tests/Writer/HTMLTest.php @@ -53,29 +53,34 @@ class HTMLTest extends \PHPUnit_Framework_TestCase */ public function testSave() { - $localImage = __DIR__ . "/../_files/images/PhpWord.png"; + $localImage = __DIR__ . '/../_files/images/PhpWord.png'; $archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg'; $gdImage = 'http://php.net/images/logos/php-med-trans-light.gif'; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.html"; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.html'; $phpWord = new PhpWord(); $docProps = $phpWord->getDocInfo(); - $docProps->setTitle('HTML Test'); + $docProps->setTitle(htmlspecialchars('HTML Test', ENT_COMPAT, 'UTF-8')); $phpWord->addTitleStyle(1, array('bold' => true)); - $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, - 'color' => 'FF0000', 'fgColor' => 'FF0000')); + $phpWord->addFontStyle( + 'Font', + array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000') + ); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center', 'spaceAfter' => 20, 'spaceBefore' => 20)); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true)); - $section->addLink('http://test.com'); - $section->addTitle('Test', 1); + $section->addText( + htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), + array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true) + ); + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); - $section->addListItem('Test'); + $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addImage($localImage); $section->addImage($archiveImage); $section->addImage($gdImage); @@ -86,24 +91,27 @@ class HTMLTest extends \PHPUnit_Framework_TestCase $section = $phpWord->addSection(); $textrun = $section->addTextRun(array('align' => 'center')); - $textrun->addText('Test 3'); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $textrun->addTextBreak(); $textrun = $section->addTextRun('Paragraph'); - $textrun->addLink('http://test.com'); + $textrun->addLink('https://github.com/PHPOffice/PHPWord'); $textrun->addImage($localImage); - $textrun->addFootnote()->addText('Footnote'); - $textrun->addEndnote()->addText('Endnote'); + $textrun->addFootnote()->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8')); + $textrun->addEndnote()->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8')); $section = $phpWord->addSection(); $table = $section->addTable(); $cell = $table->addRow()->addCell(); - $cell->addText('Test 1', array('superscript' => true, 'underline' => 'dash', 'strikethrough' => true)); + $cell->addText( + htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), + array('superscript' => true, 'underline' => 'dash', 'strikethrough' => true) + ); $cell->addTextRun(); - $cell->addLink('http://test.com'); + $cell->addLink('https://github.com/PHPOffice/PHPWord'); $cell->addTextBreak(); - $cell->addListItem('Test'); + $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $cell->addImage($localImage); $cell->addObject($objectSrc); $cell->addFootnote(); diff --git a/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php b/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php index 92fab26f..add4a3fb 100644 --- a/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/Part/AbstractPartTest.php @@ -33,26 +33,20 @@ class AbstractPartTest extends \PHPUnit_Framework_TestCase */ public function testSetGetParentWriter() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object->setParentWriter(new ODText()); - $this->assertEquals( - new ODText(), - $object->getParentWriter() - ); + $this->assertEquals(new ODText(), $object->getParentWriter()); } /** * covers ::getParentWriter + * * @expectedException Exception * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'); $object->getParentWriter(); } } diff --git a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php b/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php index 85ddada6..33ffd176 100644 --- a/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/Part/ContentTest.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\ODText\Part\Content; /** * Test class for PhpOffice\PhpWord\Writer\ODText\Part\Content @@ -41,8 +40,8 @@ class ContentTest extends \PHPUnit_Framework_TestCase */ public function testWriteContent() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $expected = 'Expected'; $phpWord = new PhpWord(); @@ -56,41 +55,41 @@ class ContentTest extends \PHPUnit_Framework_TestCase $phpWord->addTableStyle('tblStyle', array('width' => 100)); $section = $phpWord->addSection(array('colsNum' => 2)); - $section->addText($expected); - $section->addText('Test font style', 'Font'); - $section->addText('Test paragraph style', null, 'Paragraph'); - $section->addLink('http://test.com', 'Test link'); - $section->addTitle('Test title', 1); + $section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8')); + $section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font'); + $section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph'); + $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); + $section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1); $section->addTextBreak(); $section->addPageBreak(); - $section->addListItem('Test list item'); + $section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8')); $section->addImage($imageSrc, array('width' => 50)); $section->addObject($objectSrc); $section->addTOC(); $textrun = $section->addTextRun(); - $textrun->addText('Test text run'); + $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8')); $table = $section->addTable(array('width' => 50)); $cell = $table->addRow()->addCell(); $cell = $table->addRow()->addCell(); - $cell->addText('Test'); - $cell->addLink('http://test.com', 'Test link'); + $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); $cell->addTextBreak(); - $cell->addListItem('Test list item'); + $cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8')); $cell->addImage($imageSrc); $cell->addObject($objectSrc); $textrun = $cell->addTextRun(); - $textrun->addText('Test text run'); + $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8')); $footer = $section->addFooter(); - $footer->addPreserveText('{PAGE}'); + $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8')); $table = $section->addTable('tblStyle')->addRow()->addCell(); $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); - $element = "/office:document-content/office:body/office:text/text:section/text:p"; + $element = '/office:document-content/office:body/office:text/text:section/text:p'; $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue); } @@ -104,7 +103,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase $doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); - $element = "/office:document-content/office:automatic-styles/style:style"; + $element = '/office:document-content/office:automatic-styles/style:style'; $this->assertTrue($doc->elementExists($element, 'content.xml')); } } diff --git a/tests/PhpWord/Tests/Writer/ODTextTest.php b/tests/PhpWord/Tests/Writer/ODTextTest.php index 25b8095b..8bf8eb02 100644 --- a/tests/PhpWord/Tests/Writer/ODTextTest.php +++ b/tests/PhpWord/Tests/Writer/ODTextTest.php @@ -65,28 +65,28 @@ class ODTextTest extends \PHPUnit_Framework_TestCase */ public function testSave() { - $imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.odt"; + $imageSrc = __DIR__ . '/../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.odt'; $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font'); $section->addTextBreak(); - $section->addText('Test 2', null, 'Paragraph'); - $section->addLink('http://test.com'); - $section->addTitle('Test', 1); + $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), null, 'Paragraph'); + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); - $section->addTable()->addRow()->addCell()->addText('Test'); - $section->addListItem('Test'); + $section->addTable()->addRow()->addCell()->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addImage($imageSrc); $section->addObject($objectSrc); $section->addTOC(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText('Test 3'); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $writer = new ODText($phpWord); $writer->save($file); @@ -104,7 +104,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase { $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test'); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $writer = new ODText($phpWord); $writer->save('php://output'); } @@ -136,10 +136,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase */ public function testSetUseDiskCachingException() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_BASE_DIR, 'foo') - ); + $dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new ODText(); $object->setUseDiskCaching(true, $dir); diff --git a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php index 476c9011..71d15723 100644 --- a/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php +++ b/tests/PhpWord/Tests/Writer/PDF/DomPDFTest.php @@ -33,11 +33,11 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase public function testConstruct() { define('DOMPDF_ENABLE_AUTOLOAD', false); - $file = __DIR__ . "/../../_files/dompdf.pdf"; + $file = __DIR__ . '/../../_files/dompdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test 1'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); $rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); diff --git a/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php index 4728b7f1..fbf6d1d4 100644 --- a/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php +++ b/tests/PhpWord/Tests/Writer/PDF/MPDFTest.php @@ -32,11 +32,11 @@ class MPDFTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $file = __DIR__ . "/../../_files/mpdf.pdf"; + $file = __DIR__ . '/../../_files/mpdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test 1'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); $rendererName = Settings::PDF_RENDERER_MPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf'); diff --git a/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php b/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php index c73f0043..c6d2a99f 100644 --- a/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php +++ b/tests/PhpWord/Tests/Writer/PDF/TCPDFTest.php @@ -32,11 +32,11 @@ class TCPDFTest extends \PHPUnit_Framework_TestCase */ public function testConstruct() { - $file = __DIR__ . "/../../_files/tcpdf.pdf"; + $file = __DIR__ . '/../../_files/tcpdf.pdf'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test 1'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8')); $rendererName = Settings::PDF_RENDERER_TCPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf'); diff --git a/tests/PhpWord/Tests/Writer/PDFTest.php b/tests/PhpWord/Tests/Writer/PDFTest.php index 87814b41..8e1149cd 100644 --- a/tests/PhpWord/Tests/Writer/PDFTest.php +++ b/tests/PhpWord/Tests/Writer/PDFTest.php @@ -33,7 +33,7 @@ class PDFTest extends \PHPUnit_Framework_TestCase public function testConstruct() { define('DOMPDF_ENABLE_AUTOLOAD', false); - $file = __DIR__ . "/../_files/temp.pdf"; + $file = __DIR__ . '/../_files/temp.pdf'; $rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); diff --git a/tests/PhpWord/Tests/Writer/RTFTest.php b/tests/PhpWord/Tests/Writer/RTFTest.php index 5b983b35..a469e936 100644 --- a/tests/PhpWord/Tests/Writer/RTFTest.php +++ b/tests/PhpWord/Tests/Writer/RTFTest.php @@ -53,20 +53,22 @@ class RTFTest extends \PHPUnit_Framework_TestCase */ public function testSave() { - $imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; - $objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; - $file = __DIR__ . "/../_files/temp.rtf"; + $imageSrc = __DIR__ . '/../_files/images/PhpWord.png'; + $objectSrc = __DIR__ . '/../_files/documents/sheet.xls'; + $file = __DIR__ . '/../_files/temp.rtf'; $phpWord = new PhpWord(); - $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, - 'color' => 'FF0000', 'fgColor' => '00FF00')); + $phpWord->addFontStyle( + 'Font', + array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => '00FF00') + ); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true)); - $section->addLink('http://test.com'); - $section->addTitle('Test', 1); + $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), array('name' => 'Tahoma', 'bold' => true, 'italic' => true)); + $section->addLink('https://github.com/PHPOffice/PHPWord'); + $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $section->addPageBreak(); // Rowspan @@ -78,13 +80,13 @@ class RTFTest extends \PHPUnit_Framework_TestCase $cell = $section->addTable()->addRow()->addCell(); $cell->addTable()->addRow()->addCell(); - $section->addListItem('Test'); + $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $section->addImage($imageSrc); $section->addObject($objectSrc); $section->addTOC(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText('Test 3'); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $textrun->addTextBreak(); $writer = new RTF($phpWord); $writer->save($file); @@ -103,7 +105,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase { $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test'); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $writer = new RTF($phpWord); $writer->save('php://output'); } diff --git a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php b/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php index 92a74c15..da95ee02 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php @@ -41,7 +41,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase $elements = array( 'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC', - 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT' + 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT', ); foreach ($elements as $element) { $objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $element; @@ -65,7 +65,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addLine(array('width' => 1000, 'height' => 1000, 'positioning' => 'absolute', 'flip' => true)); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:r/w:pict/v:shapetype"; + $element = '/w:document/w:body/w:p/w:r/w:pict/v:shapetype'; $this->assertTrue($doc->elementExists($element)); } @@ -81,8 +81,8 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addShape( 'arc', array( - 'points' => '-90 20', - 'frame' => array('width' => 120, 'height' => 120), + 'points' => '-90 20', + 'frame' => array('width' => 120, 'height' => 120), 'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'), ) ); @@ -91,9 +91,14 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addShape( 'curve', array( - 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', - 'outline' => array('color' => '#66cc00', 'weight' => 2, 'dash' => 'dash', - 'startArrow' => 'diamond', 'endArrow' => 'block'), + 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', + 'outline' => array( + 'color' => '#66cc00', + 'weight' => 2, + 'dash' => 'dash', + 'startArrow' => 'diamond', + 'endArrow' => 'block', + ), ) ); @@ -101,9 +106,15 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addShape( 'line', array( - 'points' => '1,1 150,30', - 'outline' => array('color' => '#cc00ff', 'line' => 'thickThin', 'weight' => 3, - 'startArrow' => 'oval', 'endArrow' => 'classic', 'endCap' => 'round'), + 'points' => '1,1 150,30', + 'outline' => array( + 'color' => '#cc00ff', + 'line' => 'thickThin', + 'weight' => 3, + 'startArrow' => 'oval', + 'endArrow' => 'classic', + 'endCap' => 'round', + ), ) ); @@ -111,9 +122,13 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addShape( 'polyline', array( - 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', - 'outline' => array('color' => '#cc6666', 'weight' => 2, - 'startArrow' => 'none', 'endArrow' => 'classic'), + 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', + 'outline' => array( + 'color' => '#cc6666', + 'weight' => 2, + 'startArrow' => 'none', + 'endArrow' => 'classic', + ), ) ); @@ -122,10 +137,10 @@ class ElementTest extends \PHPUnit_Framework_TestCase 'rect', array( 'roundness' => 0.2, - 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#FFCC33'), - 'outline' => array('color' => '#990000', 'weight' => 1), - 'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'), + 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), + 'fill' => array('color' => '#FFCC33'), + 'outline' => array('color' => '#990000', 'weight' => 1), + 'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'), ) ); @@ -133,9 +148,9 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addShape( 'oval', array( - 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), - 'fill' => array('color' => '#33CC99'), - 'outline' => array('color' => '#333333', 'weight' => 2), + 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), + 'fill' => array('color' => '#33CC99'), + 'outline' => array('color' => '#333333', 'weight' => 2), 'extrusion' => array('type' => 'perspective', 'color' => '#EEEEEE'), ) ); @@ -187,11 +202,13 @@ class ElementTest extends \PHPUnit_Framework_TestCase $section->addFormField('textinput')->setName('MyTextBox'); $section->addFormField('checkbox')->setDefault(true)->setValue('Your name'); - $section->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3')); + $section->addFormField('dropdown')->setEntries( + array(htmlspecialchars('Choice 1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 2', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Choice 3', ENT_COMPAT, 'UTF-8')) + ); $doc = TestHelperDOCX::getDocument($phpWord); - $path = "/w:document/w:body/w:p/w:r/w:fldChar/w:ffData"; + $path = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData'; $this->assertTrue($doc->elementExists($path . '/w:textInput')); $this->assertTrue($doc->elementExists($path . '/w:checkBox')); $this->assertTrue($doc->elementExists($path . '/w:ddList')); @@ -211,7 +228,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase $doc = TestHelperDOCX::getDocument($phpWord); - $path = "/w:document/w:body/w:p/w:sdt/w:sdtPr"; + $path = '/w:document/w:body/w:p/w:sdt/w:sdtPr'; $this->assertTrue($doc->elementExists($path . '/w:comboBox')); $this->assertTrue($doc->elementExists($path . '/w:dropDownList')); $this->assertTrue($doc->elementExists($path . '/w:date')); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php index 2ff80ab8..37a5ece6 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/AbstractPartTest.php @@ -34,26 +34,20 @@ class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase */ public function testSetGetParentWriter() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object->setParentWriter(new Word2007()); - $this->assertEquals( - new Word2007(), - $object->getParentWriter() - ); + $this->assertEquals(new Word2007(), $object->getParentWriter()); } /** * covers ::getParentWriter + * * @expectedException Exception * @expectedExceptionMessage No parent WriterInterface assigned. */ public function testSetGetParentWriterNull() { - $object = $this->getMockForAbstractClass( - 'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart' - ); + $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'); $object->getParentWriter(); } } diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php index ef36e0dd..e5c41f09 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php @@ -19,7 +19,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007\Part\Document; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Document @@ -62,42 +61,62 @@ class DocumentTest extends \PHPUnit_Framework_TestCase */ public function testElements() { - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $phpWord = new PhpWord(); - $phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); - $phpWord->addTitleStyle(2, array('color'=>'666666')); + $phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true)); + $phpWord->addTitleStyle(2, array('color' => '666666')); $section = $phpWord->addSection(); $section->addTOC(); $section->addPageBreak(); - $section->addText('After page break.'); - $section->addTitle('Title 1', 1); - $section->addListItem('List Item 1', 0); - $section->addListItem('List Item 2', 0); - $section->addListItem('List Item 3', 0); + $section->addText(htmlspecialchars('After page break.', ENT_COMPAT, 'UTF-8')); + $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1); + $section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0); + $section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0); + $section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 0); $section = $phpWord->addSection(); - $section->addTitle('Title 2', 2); + $section->addTitle(htmlspecialchars('Title 2', ENT_COMPAT, 'UTF-8'), 2); $section->addObject($objectSrc); $section->addTextBox(array()); - $section->addTextBox(array('wrappingStyle' => 'square', 'positioning' => 'relative', - 'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin', - 'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0')); + $section->addTextBox( + array( + 'wrappingStyle' => 'square', + 'positioning' => 'relative', + 'posHorizontalRel' => 'margin', + 'posVerticalRel' => 'margin', + 'innerMargin' => 10, + 'borderSize' => 1, + 'borderColor' => '#FF0', + ) + ); $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center')); - $section->addListItemRun()->addText('List item run 1'); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar')); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'SakaEraCalendar')); - $section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LastUsedFormat')); - $section->addField('PAGE', array('format'=>'ArabicDash')); + $section->addListItemRun()->addText(htmlspecialchars('List item run 1', ENT_COMPAT, 'UTF-8')); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'LunarCalendar') + ); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'SakaEraCalendar') + ); + $section->addField( + 'DATE', + array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), + array('PreserveFormat', 'LastUsedFormat') + ); + $section->addField('PAGE', array('format' => 'ArabicDash')); $section->addLine( array( - 'width' => 10, - 'height' => 10, + 'width' => 10, + 'height' => 10, 'positioning' => 'absolute', - 'beginArrow' => 'block', - 'endArrow' => 'open', - 'dash' => 'rounddot', - 'weight' => 10 + 'beginArrow' => 'block', + 'endArrow' => 'open', + 'dash' => 'rounddot', + 'weight' => 10, ) ); @@ -131,27 +150,39 @@ class DocumentTest extends \PHPUnit_Framework_TestCase */ public function testElementStyles() { - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; $tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)); $phpWord = new PhpWord(); - $phpWord->addParagraphStyle('pStyle', array( - 'align' => 'center', - 'tabs' => $tabs, - 'shading' => array('fill' => 'FFFF99'), - 'borderSize' => 4, - )); // Style #1 - $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true, - 'scale' => 200, 'spacing' => 240, 'kerning' => 10)); // Style #2 + $phpWord->addParagraphStyle( + 'pStyle', + array( + 'align' => 'center', + 'tabs' => $tabs, + 'shading' => array('fill' => 'FFFF99'), + 'borderSize' => 4, + ) + ); // Style #1 + $phpWord->addFontStyle( + 'fStyle', + array( + 'size' => '20', + 'bold' => true, + 'allCaps' => true, + 'scale' => 200, + 'spacing' => 240, + 'kerning' => 10, + ) + ); // Style #2 $phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3 $phpWord->addTableStyle('tStyle', array('borderSize' => 1)); $fontStyle = new Font('text', array('align' => 'center')); $section = $phpWord->addSection(); - $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5 + $section->addListItem(htmlspecialchars('List Item', ENT_COMPAT, 'UTF-8'), 0, null, null, 'pStyle'); // Style #5 $section->addObject($objectSrc, array('align' => 'center')); $section->addTOC($fontStyle); - $section->addTitle('Title 1', 1); + $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1); $section->addTOC('fStyle'); $table = $section->addTable('tStyle'); $table->setWidth(100); @@ -184,12 +215,12 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $phpWord->addFontStyle($rStyle, array('bold' => true)); $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $section = $phpWord->addSection(); - $section->addText('Test', $rStyle, $pStyle); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:r/w:rPr/w:rStyle"; + $element = '/w:document/w:body/w:p/w:r/w:rPr/w:rStyle'; $this->assertEquals($rStyle, $doc->getElementAttribute($element, 'w:val')); - $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $element = '/w:document/w:body/w:p/w:pPr/w:pStyle'; $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val')); } @@ -200,21 +231,21 @@ class DocumentTest extends \PHPUnit_Framework_TestCase { $pStyle = 'pStyle'; $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; $phpWord = new PhpWord(); $phpWord->addParagraphStyle($pStyle, $aStyle); - $section = $phpWord->addSection('Test'); + $section = $phpWord->addSection(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $textrun = $section->addTextRun($pStyle); - $textrun->addText('Test'); + $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $textrun->addTextBreak(); $textrun = $section->addTextRun($aStyle); - $textrun->addLink('http://test.com'); + $textrun->addLink('https://github.com/PHPOffice/PHPWord'); $textrun->addImage($imageSrc, array('align' => 'center')); $textrun->addFootnote(); $doc = TestHelperDOCX::getDocument($phpWord); - $parent = "/w:document/w:body/w:p"; + $parent = '/w:document/w:body/w:p'; $this->assertTrue($doc->elementExists("{$parent}/w:pPr/w:pStyle[@w:val='{$pStyle}']")); } @@ -230,15 +261,25 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $paragraphStyleArray = array('align' => 'center'); $paragraphStyleName = 'Paragraph Style'; - $expected = 'PhpWord'; - $section->addLink('http://github.com/phpoffice/phpword', $expected); - $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray, $paragraphStyleArray); - $section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName, $paragraphStyleName); + $expected = 'PHPWord on GitHub'; + $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars($expected, ENT_COMPAT, 'UTF-8')); + $section->addLink( + 'https://github.com/PHPOffice/PHPWord', + htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), + $fontStyleArray, + $paragraphStyleArray + ); + $section->addLink( + 'https://github.com/PHPOffice/PHPWord', + htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), + $fontStyleName, + $paragraphStyleName + ); $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); - $this->assertEquals($expected, $element->nodeValue); + $this->assertEquals(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'), $element->nodeValue); } /** @@ -254,12 +295,12 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $paragraphStyleArray = array('align' => 'right'); $paragraphStyleName = 'Paragraph'; - $footer->addPreserveText('Page {PAGE}'); - $footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray); - $footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName); + $footer->addPreserveText(htmlspecialchars('Page {PAGE}', ENT_COMPAT, 'UTF-8')); + $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleArray, $paragraphStyleArray); + $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleName, $paragraphStyleName); $doc = TestHelperDOCX::getDocument($phpWord); - $preserve = $doc->getElement("w:p/w:r[2]/w:instrText", 'word/footer1.xml'); + $preserve = $doc->getElement('w:p/w:r[2]/w:instrText', 'word/footer1.xml'); $this->assertEquals('PAGE', $preserve->nodeValue); $this->assertEquals('preserve', $preserve->getAttribute('xml:space')); @@ -301,7 +342,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $section = $phpWord->addSection(); foreach ($wraps as $wrap) { $styles['wrappingStyle'] = $wrap; - $section->addImage(__DIR__ . "/../../../_files/images/earth.jpg", $styles); + $section->addImage(__DIR__ . '/../../../_files/images/earth.jpg', $styles); } $archiveFile = realpath(__DIR__ . '/../../../_files/documents/reader.docx'); @@ -326,7 +367,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase */ public function testWriteWatermark() { - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; $phpWord = new PhpWord(); $section = $phpWord->addSection(); @@ -334,8 +375,8 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $header->addWatermark($imageSrc); $doc = TestHelperDOCX::getDocument($phpWord); - $element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); - $this->assertStringStartsWith("rId", $element->getAttribute('r:id')); + $element = $doc->getElement('/w:document/w:body/w:sectPr/w:headerReference'); + $this->assertStringStartsWith('rId', $element->getAttribute('r:id')); } /** @@ -345,10 +386,10 @@ class DocumentTest extends \PHPUnit_Framework_TestCase { $phpWord = new PhpWord(); $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); - $phpWord->addSection()->addTitle('Test', 1); + $phpWord->addSection()->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1); $doc = TestHelperDOCX::getDocument($phpWord); - $element = "/w:document/w:body/w:p/w:pPr/w:pStyle"; + $element = '/w:document/w:body/w:p/w:pPr/w:pStyle'; $this->assertEquals('Heading1', $doc->getElementAttribute($element, 'w:val')); } @@ -364,11 +405,11 @@ class DocumentTest extends \PHPUnit_Framework_TestCase // $phpWord->addFontStyle($rStyle, array('bold' => true)); // $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $section = $phpWord->addSection(); - $section->addCheckBox('Check1', 'Test', $rStyle, $pStyle); + $section->addCheckBox(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle); $doc = TestHelperDOCX::getDocument($phpWord); $element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name'; - $this->assertEquals('Check1', $doc->getElementAttribute($element, 'w:val')); + $this->assertEquals(htmlspecialchars('Check1', ENT_COMPAT, 'UTF-8'), $doc->getElementAttribute($element, 'w:val')); } /** @@ -380,14 +421,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $phpWord = new PhpWord(); $section = $phpWord->addSection(); $attributes = array( - 'align' => 'right', - 'widowControl' => false, - 'keepNext' => true, - 'keepLines' => true, + 'align' => 'right', + 'widowControl' => false, + 'keepNext' => true, + 'keepLines' => true, 'pageBreakBefore' => true, ); foreach ($attributes as $attribute => $value) { - $section->addText('Test', null, array($attribute => $value)); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), null, array($attribute => $value)); } $doc = TestHelperDOCX::getDocument($phpWord); @@ -397,7 +438,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $attributeCount++; $nodeName = ($key == 'align') ? 'jc' : $key; $path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}"; - if ($key != 'align') { + if ('align' != $key) { $value = $value ? 1 : 0; } $element = $doc->getElement($path); @@ -425,7 +466,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $styles['smallCaps'] = true; $section = $phpWord->addSection(); - $section->addText('Test', $styles); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $styles); $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:p/w:r/w:rPr'; @@ -449,50 +490,46 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $phpWord = new PhpWord(); $rHeight = 120; $cWidth = 120; - $imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; - $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg'; + $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls'; - $tStyles["width"] = 50; - $tStyles["cellMarginTop"] = 120; - $tStyles["cellMarginRight"] = 120; - $tStyles["cellMarginBottom"] = 120; - $tStyles["cellMarginLeft"] = 120; - $rStyles["tblHeader"] = true; - $rStyles["cantSplit"] = true; - $cStyles["valign"] = 'top'; - $cStyles["textDirection"] = 'btLr'; - $cStyles["bgColor"] = 'FF0000'; - $cStyles["borderTopSize"] = 120; - $cStyles["borderBottomSize"] = 120; - $cStyles["borderLeftSize"] = 120; - $cStyles["borderRightSize"] = 120; - $cStyles["borderTopColor"] = 'FF0000'; - $cStyles["borderBottomColor"] = 'FF0000'; - $cStyles["borderLeftColor"] = 'FF0000'; - $cStyles["borderRightColor"] = 'FF0000'; - $cStyles["vMerge"] = 'restart'; + $tStyles['width'] = 50; + $tStyles['cellMarginTop'] = 120; + $tStyles['cellMarginRight'] = 120; + $tStyles['cellMarginBottom'] = 120; + $tStyles['cellMarginLeft'] = 120; + $rStyles['tblHeader'] = true; + $rStyles['cantSplit'] = true; + $cStyles['valign'] = 'top'; + $cStyles['textDirection'] = 'btLr'; + $cStyles['bgColor'] = 'FF0000'; + $cStyles['borderTopSize'] = 120; + $cStyles['borderBottomSize'] = 120; + $cStyles['borderLeftSize'] = 120; + $cStyles['borderRightSize'] = 120; + $cStyles['borderTopColor'] = 'FF0000'; + $cStyles['borderBottomColor'] = 'FF0000'; + $cStyles['borderLeftColor'] = 'FF0000'; + $cStyles['borderRightColor'] = 'FF0000'; + $cStyles['vMerge'] = 'restart'; $section = $phpWord->addSection(); $table = $section->addTable($tStyles); $table->setWidth = 100; $table->addRow($rHeight, $rStyles); $cell = $table->addCell($cWidth, $cStyles); - $cell->addText('Test'); + $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $cell->addTextBreak(); - $cell->addLink('http://google.com'); - $cell->addListItem('Test'); + $cell->addLink('https://github.com/PHPOffice/PHPWord'); + $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $cell->addImage($imageSrc); $cell->addObject($objectSrc); $textrun = $cell->addTextRun(); - $textrun->addText('Test'); + $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $doc = TestHelperDOCX::getDocument($phpWord); $parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar'; - // $this->assertEquals($tStyles['cellMarginTop'], $doc->getElementAttribute("{$parent}/w:top", 'w:w')); - // $this->assertEquals($tStyles['cellMarginRight'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); - // $this->assertEquals($tStyles['cellMarginBottom'], $doc->getElementAttribute("{$parent}/w:bottom", 'w:w')); - // $this->assertEquals($tStyles['cellMarginLeft'], $doc->getElementAttribute("{$parent}/w:right", 'w:w')); $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr'; $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val')); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php index 5c9d2d30..068b2e25 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/FooterTest.php @@ -32,13 +32,13 @@ class FooterTest extends \PHPUnit_Framework_TestCase */ public function testWriteFooter() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Footer(1); - $container->addText(''); - $container->addPreserveText(''); + $container->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); + $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); $container->addTextBreak(); $container->addTextRun(); - $container->addTable()->addRow()->addCell()->addText(''); + $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); $container->addImage($imageSrc); $writer = new Word2007(); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php index d7a3d667..86e87dd1 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/FootnotesTest.php @@ -42,16 +42,16 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase $phpWord = new PhpWord(); $phpWord->addParagraphStyle('pStyle', array('align' => 'left')); $section = $phpWord->addSection(); - $section->addText('Text'); + $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8')); $footnote1 = $section->addFootnote('pStyle'); - $footnote1->addText('Footnote'); + $footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8')); $footnote1->addTextBreak(); - $footnote1->addLink('http://google.com'); + $footnote1->addLink('https://github.com/PHPOffice/PHPWord'); $footnote2 = $section->addEndnote(array('align' => 'left')); - $footnote2->addText('Endnote'); + $footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8')); $doc = TestHelperDOCX::getDocument($phpWord); - $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:footnoteReference")); - $this->assertTrue($doc->elementExists("/w:document/w:body/w:p/w:r/w:endnoteReference")); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:footnoteReference')); + $this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:r/w:endnoteReference')); } } diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php index e8c31ecf..e8f77845 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/HeaderTest.php @@ -31,14 +31,14 @@ class HeaderTest extends \PHPUnit_Framework_TestCase */ public function testWriteHeader() { - $imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; + $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png'; $container = new \PhpOffice\PhpWord\Element\Header(1); - $container->addText('Test'); - $container->addPreserveText(''); + $container->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); + $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); $container->addTextBreak(); $container->addTextRun(); - $container->addTable()->addRow()->addCell()->addText(''); + $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8')); $container->addImage($imageSrc); $container->addWatermark($imageSrc); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php index ebc3aa2e..4f67571b 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/NumberingTest.php @@ -47,20 +47,20 @@ class NumberingTest extends \PHPUnit_Framework_TestCase $phpWord->addNumberingStyle( 'numStyle', array( - 'type' => 'multilevel', + 'type' => 'multilevel', 'levels' => array( array( - 'start' => 1, - 'format' => 'decimal', + 'start' => 1, + 'format' => 'decimal', 'restart' => 1, - 'suffix' => 'space', - 'text' => '%1.', - 'align' => 'left', - 'left' => 360, + 'suffix' => 'space', + 'text' => '%1.', + 'align' => 'left', + 'left' => 360, 'hanging' => 360, - 'tabPos' => 360, - 'font' => 'Arial', - 'hint' => 'default', + 'tabPos' => 360, + 'font' => 'Arial', + 'hint' => 'default', ), ) ) diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php index 103caa81..36d65af6 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/StylesTest.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007\Part\Styles; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Styles @@ -48,13 +47,13 @@ class StylesTest extends \PHPUnit_Framework_TestCase $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal'); $rStyle = array('size' => 20); $tStyle = array( - 'bgColor' => 'FF0000', + 'bgColor' => 'FF0000', 'cellMargin' => 120, 'borderSize' => 120, ); $firstRowStyle = array( - 'bgColor' => '0000FF', - 'borderSize' => 120, + 'bgColor' => '0000FF', + 'borderSize' => 120, 'borderColor' => '00FF00', ); $phpWord->setDefaultParagraphStyle($pStyle); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php b/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php index af11c054..f3f6badb 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Style/FontTest.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; use PhpOffice\PhpWord\Tests\TestHelperDOCX; -use PhpOffice\PhpWord\Writer\Word2007; -use PhpOffice\PhpWord\Writer\Word2007\Style\Font; /** * Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font @@ -44,7 +42,7 @@ class FontTest extends \PHPUnit_Framework_TestCase $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); + $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true)); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $file = 'word/document.xml'; diff --git a/tests/PhpWord/Tests/Writer/Word2007Test.php b/tests/PhpWord/Tests/Writer/Word2007Test.php index db6e5cad..c08f279f 100644 --- a/tests/PhpWord/Tests/Writer/Word2007Test.php +++ b/tests/PhpWord/Tests/Writer/Word2007Test.php @@ -44,17 +44,17 @@ class Word2007Test extends \PHPUnit_Framework_TestCase $writerParts = array( 'ContentTypes' => 'ContentTypes', - 'Rels' => 'Rels', - 'DocPropsApp' => 'DocPropsApp', - 'Document' => 'Document', - 'Styles' => 'Styles', - 'Numbering' => 'Numbering', - 'Settings' => 'Settings', - 'WebSettings' => 'WebSettings', - 'Header' => 'Header', - 'Footer' => 'Footer', - 'Footnotes' => 'Footnotes', - 'Endnotes' => 'Footnotes', + 'Rels' => 'Rels', + 'DocPropsApp' => 'DocPropsApp', + 'Document' => 'Document', + 'Styles' => 'Styles', + 'Numbering' => 'Numbering', + 'Settings' => 'Settings', + 'WebSettings' => 'WebSettings', + 'Header' => 'Header', + 'Footer' => 'Footer', + 'Footnotes' => 'Footnotes', + 'Endnotes' => 'Footnotes', ); foreach ($writerParts as $part => $type) { $this->assertInstanceOf( @@ -79,21 +79,21 @@ class Word2007Test extends \PHPUnit_Framework_TestCase $phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->addSection(); - $section->addText('Test 1', 'Font', 'Paragraph'); + $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph'); $section->addTextBreak(); - $section->addText('Test 2'); + $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8')); $section = $phpWord->addSection(); $textrun = $section->addTextRun(); - $textrun->addText('Test 3'); + $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8')); $footnote = $textrun->addFootnote(); - $footnote->addLink('http://test.com'); + $footnote->addLink('https://github.com/PHPOffice/PHPWord'); $header = $section->addHeader(); $header->addImage($localImage); $footer = $section->addFooter(); $footer->addImage($remoteImage); $writer = new Word2007($phpWord); - $file = __DIR__ . "/../_files/temp.docx"; + $file = __DIR__ . '/../_files/temp.docx'; $writer->save($file); $this->assertTrue(file_exists($file)); @@ -108,13 +108,13 @@ class Word2007Test extends \PHPUnit_Framework_TestCase { $phpWord = new PhpWord(); $section = $phpWord->addSection(); - $section->addText('Test'); + $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $footnote = $section->addFootnote(); - $footnote->addText('Test'); + $footnote->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8')); $writer = new Word2007($phpWord); $writer->setUseDiskCaching(true); - $file = __DIR__ . "/../_files/temp.docx"; + $file = __DIR__ . '/../_files/temp.docx'; $writer->save($file); $this->assertTrue(file_exists($file)); @@ -142,7 +142,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase } $doc = TestHelperDOCX::getDocument($phpWord); - $mediaPath = $doc->getPath() . "/word/media"; + $mediaPath = $doc->getPath() . '/word/media'; foreach ($images as $source => $target) { $this->assertFileEquals( @@ -183,10 +183,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase */ public function testSetUseDiskCachingException() { - $dir = join( - DIRECTORY_SEPARATOR, - array(PHPWORD_TESTS_BASE_DIR, 'foo') - ); + $dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo')); $object = new Word2007(); $object->setUseDiskCaching(true, $dir); diff --git a/tests/PhpWord/Tests/_files/documents/reader.rtf b/tests/PhpWord/Tests/_files/documents/reader.rtf index 400f43a5..4cecadea 100644 --- a/tests/PhpWord/Tests/_files/documents/reader.rtf +++ b/tests/PhpWord/Tests/_files/documents/reader.rtf @@ -16,6 +16,6 @@ \pard\nowidctlpar\qc\sa100{\cf0\f0\fs32\b\i I am styled by both font and paragraph style.}\par \pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par \par -{\field {\*\fldinst {HYPERLINK "http://www.google.com"}}{\fldrslt {Google}}}\par +{\field {\*\fldinst {HYPERLINK "https://github.com/PHPOffice/PHPWord"}}{\fldrslt {PHPWord on GitHub}}}\par \par } \ No newline at end of file diff --git a/tests/PhpWord/Tests/_includes/TestHelperDOCX.php b/tests/PhpWord/Tests/_includes/TestHelperDOCX.php index 2a0043d5..49a7e716 100644 --- a/tests/PhpWord/Tests/_includes/TestHelperDOCX.php +++ b/tests/PhpWord/Tests/_includes/TestHelperDOCX.php @@ -60,7 +60,7 @@ class TestHelperDOCX $zip = new \ZipArchive; $res = $zip->open(self::$file); - if ($res === true) { + if (true === $res) { $zip->extractTo(Settings::getTempDir() . '/PhpWord_Unit_Test/'); $zip->close(); } @@ -89,12 +89,12 @@ class TestHelperDOCX public static function deleteDir($dir) { foreach (scandir($dir) as $file) { - if ($file === '.' || $file === '..') { + if ('.' === $file || '..' === $file) { continue; - } elseif (is_file($dir . "/" . $file)) { - unlink($dir . "/" . $file); - } elseif (is_dir($dir . "/" . $file)) { - self::deleteDir($dir . "/" . $file); + } elseif (is_file($dir . '/' . $file)) { + unlink($dir . '/' . $file); + } elseif (is_dir($dir . '/' . $file)) { + self::deleteDir($dir . '/' . $file); } } diff --git a/tests/PhpWord/Tests/_includes/XmlDocument.php b/tests/PhpWord/Tests/_includes/XmlDocument.php index 2e161bb1..0a70c5f2 100644 --- a/tests/PhpWord/Tests/_includes/XmlDocument.php +++ b/tests/PhpWord/Tests/_includes/XmlDocument.php @@ -90,7 +90,7 @@ class XmlDocument */ public function getNodeList($path, $file = 'word/document.xml') { - if ($this->dom === null || $file !== $this->file) { + if (null === $this->dom || $file !== $this->file) { $this->getFileDom($file); }