#51 (updated tests, refactored a little).

This commit is contained in:
Roman Syroeshko 2015-02-06 22:28:31 +04:00
parent 2b9111f8e9
commit 2a5c66784b
104 changed files with 1169 additions and 1140 deletions

View File

@ -28,7 +28,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
htmlspecialchars( htmlspecialchars(
'"Learn from yesterday, live for today, hope for tomorrow. ' '"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." ' . 'The important thing is not to stop questioning." '
. '(Albert Einstein)' . '(Albert Einstein)',
ENT_COMPAT,
'UTF-8'
) )
); );
@ -44,7 +46,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
htmlspecialchars( htmlspecialchars(
'"Great achievement is usually born of great sacrifice, ' '"Great achievement is usually born of great sacrifice, '
. 'and is never the result of selfishness." ' . 'and is never the result of selfishness." '
. '(Napoleon Hill)' . '(Napoleon Hill)',
ENT_COMPAT,
'UTF-8'
), ),
array('name' => 'Tahoma', 'size' => 10) array('name' => 'Tahoma', 'size' => 10)
); );
@ -59,7 +63,9 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
htmlspecialchars( htmlspecialchars(
'"The greatest accomplishment is not in never falling, ' '"The greatest accomplishment is not in never falling, '
. 'but in rising again after you fall." ' . 'but in rising again after you fall." '
. '(Vince Lombardi)' . '(Vince Lombardi)',
ENT_COMPAT,
'UTF-8'
), ),
$fontStyleName $fontStyleName
); );
@ -70,7 +76,7 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
$fontStyle->setName('Tahoma'); $fontStyle->setName('Tahoma');
$fontStyle->setSize(13); $fontStyle->setSize(13);
$myTextElement = $section->addText( $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); $myTextElement->setFontStyle($fontStyle);

View File

@ -228,7 +228,9 @@ $section->addText(
htmlspecialchars( htmlspecialchars(
'"Learn from yesterday, live for today, hope for tomorrow. ' '"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." ' . 'The important thing is not to stop questioning." '
. '(Albert Einstein)' . '(Albert Einstein)',
ENT_COMPAT,
'UTF-8'
) )
); );
@ -244,7 +246,9 @@ $section->addText(
htmlspecialchars( htmlspecialchars(
'"Great achievement is usually born of great sacrifice, ' '"Great achievement is usually born of great sacrifice, '
. 'and is never the result of selfishness." ' . 'and is never the result of selfishness." '
. '(Napoleon Hill)' . '(Napoleon Hill)',
ENT_COMPAT,
'UTF-8'
), ),
array('name' => 'Tahoma', 'size' => 10) array('name' => 'Tahoma', 'size' => 10)
); );
@ -259,7 +263,9 @@ $section->addText(
htmlspecialchars( htmlspecialchars(
'"The greatest accomplishment is not in never falling, ' '"The greatest accomplishment is not in never falling, '
. 'but in rising again after you fall." ' . 'but in rising again after you fall." '
. '(Vince Lombardi)' . '(Vince Lombardi)',
ENT_COMPAT,
'UTF-8'
), ),
$fontStyleName $fontStyleName
); );
@ -270,7 +276,7 @@ $fontStyle->setBold(true);
$fontStyle->setName('Tahoma'); $fontStyle->setName('Tahoma');
$fontStyle->setSize(13); $fontStyle->setSize(13);
$myTextElement = $section->addText( $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); $myTextElement->setFontStyle($fontStyle);

View File

@ -12,16 +12,16 @@ $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
// Simple text // Simple text
$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1); $section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1);
$section->addText(htmlspecialchars('Hello World!')); $section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8'));
// Two text break // Two text break
$section->addTextBreak(2); $section->addTextBreak(2);
// Defined style // Defined style
$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle'); $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.'), null, 'pStyle'); $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.'), 'rStyle', 'pStyle'); $section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle');
$section->addTextBreak(); $section->addTextBreak();
@ -30,39 +30,39 @@ $fontStyle['name'] = 'Times New Roman';
$fontStyle['size'] = 20; $fontStyle['size'] = 20;
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle); $textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle);
$textrun->addText(htmlspecialchars('with ')); $textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('color'), array('color' => '996699')); $textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699'));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('bold'), array('bold' => true)); $textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('italic'), array('italic' => true)); $textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash')); $textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true)); $textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true)); $textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true)); $textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true)); $textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true)); $textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true)); $textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow')); $textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow'));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('scale'), array('scale' => 200)); $textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120)); $textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10)); $textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10));
$textrun->addText(htmlspecialchars('. ')); $textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8'));
// Link // 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(); $section->addTextBreak();
// Image // Image

View File

@ -29,9 +29,9 @@ $phpWord->addParagraphStyle(
$section = $phpWord->addSection(); $section = $phpWord->addSection();
// Add listitem elements // Add listitem elements
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab'); $section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree", ENT_COMPAT, 'UTF-8'), null, 'multipleTab');
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab'); $section->addText(htmlspecialchars("Left Aligned\tRight Aligned", ENT_COMPAT, 'UTF-8'), null, 'rightTab');
$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab'); $section->addText(htmlspecialchars("\tCenter Aligned", ENT_COMPAT, 'UTF-8'), null, 'centerTab');
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -7,13 +7,15 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section // New portrait section
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12)); $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 // New landscape section
$section = $phpWord->addSection(array('orientation' => 'landscape')); $section = $phpWord->addSection(array('orientation' => 'landscape'));
$section->addText( $section->addText(
htmlspecialchars( 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(); $section->addPageBreak();
@ -23,7 +25,7 @@ $section->addPageBreak();
$section = $phpWord->addSection( $section = $phpWord->addSection(
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) 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 // New portrait section with Header & Footer
$section = $phpWord->addSection( $section = $phpWord->addSection(
@ -36,9 +38,9 @@ $section = $phpWord->addSection(
'footerHeight' => 50, 'footerHeight' => 50,
) )
); );
$section->addText(htmlspecialchars('This section and we play with header/footer height.')); $section->addText(htmlspecialchars('This section and we play with header/footer height.', ENT_COMPAT, 'UTF-8'));
$section->addHeader()->addText(htmlspecialchars('Header')); $section->addHeader()->addText(htmlspecialchars('Header', ENT_COMPAT, 'UTF-8'));
$section->addFooter()->addText(htmlspecialchars('Footer')); $section->addFooter()->addText(htmlspecialchars('Footer', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -20,24 +20,24 @@ $section = $phpWord->addSection();
// Add text run // Add text run
$textrun = $section->addTextRun('pStyle'); $textrun = $section->addTextRun('pStyle');
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.')); $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.'), 'BoldText'); $textrun->addText(htmlspecialchars(' No break is placed after adding an element.', ENT_COMPAT, 'UTF-8'), 'BoldText');
$textrun->addText(htmlspecialchars(' Both ')); $textrun->addText(htmlspecialchars(' Both ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true)); $textrun->addText(htmlspecialchars('superscript', ENT_COMPAT, 'UTF-8'), array('superScript' => true));
$textrun->addText(htmlspecialchars(' and ')); $textrun->addText(htmlspecialchars(' and ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true)); $textrun->addText(htmlspecialchars('subscript', ENT_COMPAT, 'UTF-8'), array('subScript' => true));
$textrun->addText(htmlspecialchars(' are also available.')); $textrun->addText(htmlspecialchars(' are also available.', ENT_COMPAT, 'UTF-8'));
$textrun->addText( $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' 'ColoredText'
); );
$textrun->addText(htmlspecialchars(' Sample Link: ')); $textrun->addText(htmlspecialchars(' Sample Link: ', ENT_COMPAT, 'UTF-8'));
$textrun->addLink('http://www.google.com', null, 'NLink'); $textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
$textrun->addText(htmlspecialchars(' Sample Image: ')); $textrun->addText(htmlspecialchars(' Sample Image: ', ENT_COMPAT, 'UTF-8'));
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); $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->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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -11,7 +11,7 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
// Normal // Normal
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText(htmlspecialchars("Normal paragraph. {$filler}")); $section->addText(htmlspecialchars("Normal paragraph. {$filler}", ENT_COMPAT, 'UTF-8'));
// Two columns // Two columns
$section = $phpWord->addSection( $section = $phpWord->addSection(
@ -21,11 +21,11 @@ $section = $phpWord->addSection(
'breakType' => 'continuous', '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 // Normal
$section = $phpWord->addSection(array('breakType' => 'continuous')); $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 // Three columns
$section = $phpWord->addSection( $section = $phpWord->addSection(
@ -35,11 +35,11 @@ $section = $phpWord->addSection(
'breakType' => 'continuous', '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 // Normal
$section = $phpWord->addSection(array('breakType' => 'continuous')); $section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText(htmlspecialchars('Normal paragraph again.')); $section->addText(htmlspecialchars('Normal paragraph again.', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -20,30 +20,32 @@ $phpWord->addLinkStyle(
// Add text elements // Add text elements
$textrun = $section->addTextRun('pStyle'); $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 = $textrun->addFootnote();
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. ')); $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. '), 'BoldText'); $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. '), 'ColoredText'); $footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. ', ENT_COMPAT, 'UTF-8'), 'ColoredText');
$footnote->addTextBreak(); $footnote->addTextBreak();
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ')); $footnote->addText(htmlspecialchars('But you can insert a manual text break like above, ', ENT_COMPAT, 'UTF-8'));
$footnote->addText(htmlspecialchars('links like ')); $footnote->addText(htmlspecialchars('links like ', ENT_COMPAT, 'UTF-8'));
$footnote->addLink('http://www.google.com', null, 'NLink'); $footnote->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'), 'NLink');
$footnote->addText(htmlspecialchars(', image like ')); $footnote->addText(htmlspecialchars(', image like ', ENT_COMPAT, 'UTF-8'));
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); $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->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( $section->addText(
htmlspecialchars( htmlspecialchars(
'You can also create the footnote directly from the section making it wrap in a paragraph ' '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 = $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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -6,52 +6,52 @@ echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx'); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
// Variables on different parts of document // Variables on different parts of document
$templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content $templateProcessor->setValue('weekday', htmlspecialchars(date('l'), ENT_COMPAT, 'UTF-8')); // On section/content
$templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer $templateProcessor->setValue('time', htmlspecialchars(date('H:i'), ENT_COMPAT, 'UTF-8')); // On footer
$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header $templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__), ENT_COMPAT, 'UTF-8')); // On header
// Simple table // Simple table
$templateProcessor->cloneRow('rowValue', 10); $templateProcessor->cloneRow('rowValue', 10);
$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun')); $templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury')); $templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus')); $templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth')); $templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars')); $templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter')); $templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn')); $templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus')); $templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun')); $templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto')); $templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1')); $templateProcessor->setValue('rowNumber#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2')); $templateProcessor->setValue('rowNumber#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3')); $templateProcessor->setValue('rowNumber#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4')); $templateProcessor->setValue('rowNumber#4', htmlspecialchars('4', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5')); $templateProcessor->setValue('rowNumber#5', htmlspecialchars('5', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6')); $templateProcessor->setValue('rowNumber#6', htmlspecialchars('6', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7')); $templateProcessor->setValue('rowNumber#7', htmlspecialchars('7', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8')); $templateProcessor->setValue('rowNumber#8', htmlspecialchars('8', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9')); $templateProcessor->setValue('rowNumber#9', htmlspecialchars('9', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10')); $templateProcessor->setValue('rowNumber#10', htmlspecialchars('10', ENT_COMPAT, 'UTF-8'));
// Table with a spanned cell // Table with a spanned cell
$templateProcessor->cloneRow('userId', 3); $templateProcessor->cloneRow('userId', 3);
$templateProcessor->setValue('userId#1', htmlspecialchars('1')); $templateProcessor->setValue('userId#1', htmlspecialchars('1', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James')); $templateProcessor->setValue('userFirstName#1', htmlspecialchars('James', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor')); $templateProcessor->setValue('userName#1', htmlspecialchars('Taylor', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773')); $templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userId#2', htmlspecialchars('2')); $templateProcessor->setValue('userId#2', htmlspecialchars('2', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert')); $templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userName#2', htmlspecialchars('Bell')); $templateProcessor->setValue('userName#2', htmlspecialchars('Bell', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774')); $templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userId#3', htmlspecialchars('3')); $templateProcessor->setValue('userId#3', htmlspecialchars('3', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael')); $templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userName#3', htmlspecialchars('Ray')); $templateProcessor->setValue('userName#3', htmlspecialchars('Ray', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775')); $templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775', ENT_COMPAT, 'UTF-8'));
echo date('H:i:s'), ' Saving the result document...', EOL; echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx'); $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');

View File

@ -19,7 +19,9 @@ $section->addText(
htmlspecialchars( htmlspecialchars(
'Below are the samples on how to control your paragraph ' 'Below are the samples on how to control your paragraph '
. 'pagination. See "Line and Page Break" tab on paragraph properties ' . '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('bold' => true),
array('space' => array('before' => 360, 'after' => 480)) 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 ' . '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 ' . '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 ' . '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, null,
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)) array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
@ -42,7 +46,9 @@ $section->addText(
'Paragraph with keepNext = true (default: false). ' 'Paragraph with keepNext = true (default: false). '
. '"Keep with next" is used to prevent Word from inserting automatic page ' . '"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 ' . '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, null,
array('keepNext' => true, 'indentation' => array('firstLine' => 240)) array('keepNext' => true, 'indentation' => array('firstLine' => 240))
@ -53,20 +59,24 @@ $section->addText(
'Paragraph with keepLines = true (default: false). ' 'Paragraph with keepLines = true (default: false). '
. '"Keep lines together" will prevent Word from inserting an automatic page ' . '"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 ' . '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, null,
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)) 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( $section->addText(
htmlspecialchars( htmlspecialchars(
'Paragraph with pageBreakBefore = true (default: false). ' 'Paragraph with pageBreakBefore = true (default: false). '
. 'Different with all other control above, "page break before" separates ' . 'Different with all other control above, "page break before" separates '
. 'your paragraph into the next page. This option is most useful for ' . 'your paragraph into the next page. This option is most useful for '
. 'heading styles.' . 'heading styles.',
ENT_COMPAT,
'UTF-8'
), ),
null, null,
array('pageBreakBefore' => true) array('pageBreakBefore' => true)

View File

@ -11,20 +11,20 @@ $header = array('size' => 16, 'bold' => true);
$rows = 10; $rows = 10;
$cols = 5; $cols = 5;
$section->addText(htmlspecialchars('Basic table'), $header); $section->addText(htmlspecialchars('Basic table', ENT_COMPAT, 'UTF-8'), $header);
$table = $section->addTable(); $table = $section->addTable();
for ($r = 1; $r <= 8; $r++) { for ($r = 1; $r <= 8; $r++) {
$table->addRow(); $table->addRow();
for ($c = 1; $c <= 5; $c++) { 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 // 2. Advanced table
$section->addTextBreak(1); $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); $styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF'); $styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
@ -34,25 +34,25 @@ $fontStyle = array('bold' => true, 'align' => 'center');
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow); $phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
$table = $section->addTable('Fancy Table'); $table = $section->addTable('Fancy Table');
$table->addRow(900); $table->addRow(900);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1'), $fontStyle); $table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1', ENT_COMPAT, 'UTF-8'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2'), $fontStyle); $table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2', ENT_COMPAT, 'UTF-8'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3'), $fontStyle); $table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3', ENT_COMPAT, 'UTF-8'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4'), $fontStyle); $table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4', ENT_COMPAT, 'UTF-8'), $fontStyle);
$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5'), $fontStyle); $table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5', ENT_COMPAT, 'UTF-8'), $fontStyle);
for ($i = 1; $i <= 8; $i++) { for ($i = 1; $i <= 8; $i++) {
$table->addRow(); $table->addRow();
$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}")); $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
$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}")); $table->addCell(2000)->addText(htmlspecialchars("Cell {$i}", ENT_COMPAT, 'UTF-8'));
$text = (0== $i % 2) ? 'X' : ''; $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) // 3. colspan (gridSpan) and rowspan (vMerge)
$section->addPageBreak(); $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'); $styleTable = array('borderSize' => 6, 'borderColor' => '999999');
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00'); $cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
@ -68,32 +68,32 @@ $table->addRow();
$cell1 = $table->addCell(2000, $cellRowSpan); $cell1 = $table->addCell(2000, $cellRowSpan);
$textrun1 = $cell1->addTextRun($cellHCentered); $textrun1 = $cell1->addTextRun($cellHCentered);
$textrun1->addText(htmlspecialchars('A')); $textrun1->addText(htmlspecialchars('A', ENT_COMPAT, 'UTF-8'));
$textrun1->addFootnote()->addText(htmlspecialchars('Row span')); $textrun1->addFootnote()->addText(htmlspecialchars('Row span', ENT_COMPAT, 'UTF-8'));
$cell2 = $table->addCell(4000, $cellColSpan); $cell2 = $table->addCell(4000, $cellColSpan);
$textrun2 = $cell2->addTextRun($cellHCentered); $textrun2 = $cell2->addTextRun($cellHCentered);
$textrun2->addText(htmlspecialchars('B')); $textrun2->addText(htmlspecialchars('B', ENT_COMPAT, 'UTF-8'));
$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span')); $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->addRow();
$table->addCell(null, $cellRowContinue); $table->addCell(null, $cellRowContinue);
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C'), null, $cellHCentered); $table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D'), null, $cellHCentered); $table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D', ENT_COMPAT, 'UTF-8'), null, $cellHCentered);
$table->addCell(null, $cellRowContinue); $table->addCell(null, $cellRowContinue);
// 4. Nested table // 4. Nested table
$section->addTextBreak(2); $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')); $table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center'));
$cell = $table->addRow()->addCell(); $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 = $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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true); $header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle //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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -15,50 +15,47 @@ $table = $header->addTable();
$table->addRow(); $table->addRow();
$cell = $table->addCell(4500); $cell = $table->addCell(4500);
$textrun = $cell->addTextRun(); $textrun = $cell->addTextRun();
$textrun->addText(htmlspecialchars('This is the header with ')); $textrun->addText(htmlspecialchars('This is the header with ', ENT_COMPAT, 'UTF-8'));
$textrun->addLink('http://google.com', htmlspecialchars('link to Google')); $textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$table->addCell(4500)->addImage( $table->addCell(4500)->addImage('resources/PhpWord.png', array('width' => 80, 'height' => 80, 'align' => 'right'));
'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right')
);
// Add header for all other pages // Add header for all other pages
$subsequent = $section->addHeader(); $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)); $subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
// Add footer // Add footer
$footer = $section->addFooter(); $footer = $section->addFooter();
$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.'), array('align' => 'center')); $footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.', ENT_COMPAT, 'UTF-8'), array('align' => 'center'));
$footer->addLink('http://google.com', htmlspecialchars('Direct Google')); $footer->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
// Write some text // Write some text
$section->addTextBreak(); $section->addTextBreak();
$section->addText(htmlspecialchars('Some text...')); $section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
// Create a second page // Create a second page
$section->addPageBreak(); $section->addPageBreak();
// Write some text // Write some text
$section->addTextBreak(); $section->addTextBreak();
$section->addText(htmlspecialchars('Some text...')); $section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
// Create a third page // Create a third page
$section->addPageBreak(); $section->addPageBreak();
// Write some text // Write some text
$section->addTextBreak(); $section->addTextBreak();
$section->addText(htmlspecialchars('Some text...')); $section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
// New portrait section // New portrait section
$section2 = $phpWord->addSection(); $section2 = $phpWord->addSection();
$sec2Header = $section2->addHeader(); $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 // Write some text
$section2->addTextBreak(); $section2->addTextBreak();
$section2->addText(htmlspecialchars('Some text...')); $section2->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -7,17 +7,17 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $phpWord->addSection(); $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->addImage('resources/_mars.jpg');
$section->addTextBreak(2); $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->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
$section->addTextBreak(2); $section->addTextBreak(2);
// Remote image // Remote image
$source = 'http://php.net/images/logos/php-med-trans-light.gif'; $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); $section->addImage($source);
//Wrapping style //Wrapping style
@ -25,7 +25,7 @@ $text = str_repeat('Hello World! ', 15);
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight'); $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
foreach ($wrappingStyles as $wrappingStyle) { foreach ($wrappingStyles as $wrappingStyle) {
$section->addTextBreak(5); $section->addTextBreak(5);
$section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}")); $section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}", ENT_COMPAT, 'UTF-8'));
$section->addImage( $section->addImage(
'resources/_earth.jpg', 'resources/_earth.jpg',
array( array(
@ -37,12 +37,12 @@ foreach ($wrappingStyles as $wrappingStyle) {
'wrappingStyle' => $wrappingStyle, 'wrappingStyle' => $wrappingStyle,
) )
); );
$section->addText(htmlspecialchars($text)); $section->addText(htmlspecialchars($text, ENT_COMPAT, 'UTF-8'));
} }
//Absolute positioning //Absolute positioning
$section->addTextBreak(3); $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( $section->addImage(
'resources/_mars.jpg', 'resources/_mars.jpg',
array( array(
@ -59,8 +59,8 @@ $section->addImage(
//Relative positioning //Relative positioning
$section->addTextBreak(3); $section->addTextBreak(3);
$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,')); $section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,', ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('Vertical position top relative to line')); $section->addText(htmlspecialchars('Vertical position top relative to line', ENT_COMPAT, 'UTF-8'));
$section->addImage( $section->addImage(
'resources/_mars.jpg', 'resources/_mars.jpg',
array( array(

View File

@ -26,46 +26,46 @@ $predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::T
// Lists // Lists
$section->addText(htmlspecialchars('Multilevel list.')); $section->addText(htmlspecialchars('Multilevel list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item I', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item I.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item I.b', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item II', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item II.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item III', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addText(htmlspecialchars('Basic simple bulleted list.')); $section->addText(htmlspecialchars('Basic simple bulleted list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 1')); $section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 2')); $section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 3')); $section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addText(htmlspecialchars('Continue from multilevel list above.')); $section->addText(htmlspecialchars('Continue from multilevel list above.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item IV', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel'); $section->addListItem(htmlspecialchars('List Item IV.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addText(htmlspecialchars('Multilevel predefined list.')); $section->addText(htmlspecialchars('Multilevel predefined list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 2'), 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'), 1, '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'), 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'), 2, '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'), 1, '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'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style'); $section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addTextBreak(2); $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 = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 1')); $listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true)); $listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$listItemRun = $section->addListItemRun(); $listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 2')); $listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true)); $listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
$listItemRun = $section->addListItemRun(); $listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 3')); $listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash')); $listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
$section->addTextBreak(2); $section->addTextBreak(2);
// Numbered heading // 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(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2)); $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
$section->addTitle(htmlspecialchars('Heading 1'), 1); $section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1);
$section->addTitle(htmlspecialchars('Heading 2'), 2); $section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2);
$section->addTitle(htmlspecialchars('Heading 3'), 3); $section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3);
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -10,8 +10,8 @@ $section = $phpWord->addSection();
// Add hyperlink elements // Add hyperlink elements
$section->addLink( $section->addLink(
'http://www.google.com', 'https://github.com/PHPOffice/PHPWord',
htmlspecialchars('Best search engine'), htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'),
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE) array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
); );
$section->addTextBreak(2); $section->addTextBreak(2);

View File

@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code // Begin code
$section = $phpWord->addSection(); $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->addTextBreak(2);
$section->addObject('resources/_sheet.xls'); $section->addObject('resources/_sheet.xls');

View File

@ -19,7 +19,7 @@ $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
$phpWord->addTitleStyle(4, array('size' => 12)); $phpWord->addTitleStyle(4, array('size' => 12));
// Add text elements // Add text elements
$section->addText(htmlspecialchars('Table of contents 1')); $section->addText(htmlspecialchars('Table of contents 1', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
// Add TOC #1 // Add TOC #1
@ -27,11 +27,11 @@ $toc = $section->addTOC($fontStyle);
$section->addTextBreak(2); $section->addTextBreak(2);
// Filler // Filler
$section->addText(htmlspecialchars('Text between TOC')); $section->addText(htmlspecialchars('Text between TOC', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
// Add TOC #1 // Add TOC #1
$section->addText(htmlspecialchars('Table of contents 2')); $section->addText(htmlspecialchars('Table of contents 2', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
$toc2 = $section->addTOC($fontStyle2); $toc2 = $section->addTOC($fontStyle2);
$toc2->setMinDepth(2); $toc2->setMinDepth(2);
@ -40,31 +40,31 @@ $toc2->setMaxDepth(3);
// Add Titles // Add Titles
$section->addPageBreak(); $section->addPageBreak();
$section->addTitle(htmlspecialchars('Foo & Bar'), 1); $section->addTitle(htmlspecialchars('Foo & Bar', ENT_COMPAT, 'UTF-8'), 1);
$section->addText(htmlspecialchars('Some text...')); $section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $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->addTextBreak(2);
$section->addText(htmlspecialchars('Some more text...')); $section->addText(htmlspecialchars('Some more text...', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addTitle(htmlspecialchars('Another Title (Title 2)'), 1); $section->addTitle(htmlspecialchars('Another Title (Title 2)', ENT_COMPAT, 'UTF-8'), 1);
$section->addText(htmlspecialchars('Some text...')); $section->addText(htmlspecialchars('Some text...', ENT_COMPAT, 'UTF-8'));
$section->addPageBreak(); $section->addPageBreak();
$section->addTitle(htmlspecialchars('I am Title 3'), 1); $section->addTitle(htmlspecialchars('I am Title 3', ENT_COMPAT, 'UTF-8'), 1);
$section->addText(htmlspecialchars('And more text...')); $section->addText(htmlspecialchars('And more text...', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2); $section->addTextBreak(2);
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3'), 2); $section->addTitle(htmlspecialchars('I am a Subtitle of Title 3', ENT_COMPAT, 'UTF-8'), 2);
$section->addText(htmlspecialchars('Again and again, more text...')); $section->addText(htmlspecialchars('Again and again, more text...', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Subtitle 3.1.1'), 3); $section->addTitle(htmlspecialchars('Subtitle 3.1.1', ENT_COMPAT, 'UTF-8'), 3);
$section->addText(htmlspecialchars('Text')); $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1'), 4); $section->addTitle(htmlspecialchars('Subtitle 3.1.1.1', ENT_COMPAT, 'UTF-8'), 4);
$section->addText(htmlspecialchars('Text')); $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2'), 4); $section->addTitle(htmlspecialchars('Subtitle 3.1.1.2', ENT_COMPAT, 'UTF-8'), 4);
$section->addText(htmlspecialchars('Text')); $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$section->addTitle(htmlspecialchars('Subtitle 3.1.2'), 3); $section->addTitle(htmlspecialchars('Subtitle 3.1.2', ENT_COMPAT, 'UTF-8'), 3);
$section->addText(htmlspecialchars('Text')); $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL; echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL;

View File

@ -10,7 +10,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$header = $section->addHeader(); $header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55)); $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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -13,17 +13,17 @@ $phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24); $fontStyle = array('size' => 24);
$section = $phpWord->addSection(); $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->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->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->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->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->addTextBreak(1, null, $paragraphStyle);
$section->addText(htmlspecialchars('Done.')); $section->addText(htmlspecialchars('Done.', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -7,14 +7,14 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText( $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) array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW)
); );
$section->addText( $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') 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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -6,14 +6,16 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $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( $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( $section->addText(
htmlspecialchars( htmlspecialchars(
'On the image with the red border, even if we set the row height to the height of the image, ' '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->addTextBreak();
$section->addText( $section->addText(
htmlspecialchars( 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->addTextBreak();
$section->addText( $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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -6,13 +6,13 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText(htmlspecialchars('Check box in section')); $section->addText(htmlspecialchars('Check box in section', ENT_COMPAT, 'UTF-8'));
$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1')); $section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1', ENT_COMPAT, 'UTF-8'));
$section->addText(htmlspecialchars('Check box in table cell')); $section->addText(htmlspecialchars('Check box in table cell', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable(); $table = $section->addTable();
$table->addRow(); $table->addRow();
$cell = $table->addCell(); $cell = $table->addCell();
$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2')); $cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -17,28 +17,28 @@ $textbox = $section->addTextBox(
'borderColor' => '#FF0000', 'borderColor' => '#FF0000',
) )
); );
$textbox->addText(htmlspecialchars('Text box content in section.')); $textbox->addText(htmlspecialchars('Text box content in section.', ENT_COMPAT, 'UTF-8'));
$textbox->addText(htmlspecialchars('Another line.')); $textbox->addText(htmlspecialchars('Another line.', ENT_COMPAT, 'UTF-8'));
$cell = $textbox->addTable()->addRow()->addCell(); $cell = $textbox->addTable()->addRow()->addCell();
$cell->addText(htmlspecialchars('Table inside textbox')); $cell->addText(htmlspecialchars('Table inside textbox', ENT_COMPAT, 'UTF-8'));
// Inside table // Inside table
$section->addTextBreak(2); $section->addTextBreak(2);
$cell = $section->addTable()->addRow()->addCell(300); $cell = $section->addTable()->addRow()->addCell(300);
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100)); $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 // Inside header with textrun
$header = $section->addHeader(); $header = $section->addHeader();
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00')); $textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
$textrun = $textbox->addTextRun(); $textrun = $textbox->addTextRun();
$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ')); $textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('with bold text'), array('bold' => true)); $textrun->addText(htmlspecialchars('with bold text', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$textrun->addText(htmlspecialchars(', ')); $textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addLink('http://www.google.com', htmlspecialchars('link')); $textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars(', and image ')); $textrun->addText(htmlspecialchars(', and image ', ENT_COMPAT, 'UTF-8'));
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18)); $textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$textrun->addText(htmlspecialchars('.')); $textrun->addText(htmlspecialchars('.', ENT_COMPAT, 'UTF-8'));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -10,19 +10,19 @@ $section = $phpWord->addSection();
// Add Field elements // Add Field elements
// See Element/Field.php for all options // 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->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->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')); $section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
$textrun = $section->addTextRun(array('align' => 'center')); $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->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 // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -10,7 +10,7 @@ $section = $phpWord->addSection();
// Add Line elements // Add Line elements
// See Element/Line.php for all options // 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( $section->addLine(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
@ -18,7 +18,7 @@ $section->addLine(
'positioning' => 'absolute', 'positioning' => 'absolute',
) )
); );
$section->addText(htmlspecialchars('Vertical Line (Inline style):')); $section->addText(htmlspecialchars('Vertical Line (Inline style):', ENT_COMPAT, 'UTF-8'));
$section->addLine( $section->addLine(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
@ -29,7 +29,7 @@ $section->addLine(
// Two text break // Two text break
$section->addTextBreak(1); $section->addTextBreak(1);
$section->addText(htmlspecialchars('Positioned Line (red):')); $section->addText(htmlspecialchars('Positioned Line (red):', ENT_COMPAT, 'UTF-8'));
$section->addLine( $section->addLine(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), '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( $section->addLine(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),

View File

@ -10,7 +10,7 @@ $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
// Arc // Arc
$section->addTitle(htmlspecialchars('Arc'), 1); $section->addTitle(htmlspecialchars('Arc', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'arc', 'arc',
array( array(
@ -21,7 +21,7 @@ $section->addShape(
); );
// Curve // Curve
$section->addTitle(htmlspecialchars('Curve'), 1); $section->addTitle(htmlspecialchars('Curve', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'curve', 'curve',
array( array(
@ -38,7 +38,7 @@ $section->addShape(
); );
// Line // Line
$section->addTitle(htmlspecialchars('Line'), 1); $section->addTitle(htmlspecialchars('Line', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'line', 'line',
array( array(
@ -54,7 +54,7 @@ $section->addShape(
); );
// Polyline // Polyline
$section->addTitle(htmlspecialchars('Polyline'), 1); $section->addTitle(htmlspecialchars('Polyline', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'polyline', 'polyline',
array( array(
@ -64,7 +64,7 @@ $section->addShape(
); );
// Rectangle // Rectangle
$section->addTitle(htmlspecialchars('Rectangle'), 1); $section->addTitle(htmlspecialchars('Rectangle', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'rect', 'rect',
array( array(
@ -77,7 +77,7 @@ $section->addShape(
); );
// Oval // Oval
$section->addTitle(htmlspecialchars('Oval'), 1); $section->addTitle(htmlspecialchars('Oval', ENT_COMPAT, 'UTF-8'), 1);
$section->addShape( $section->addShape(
'oval', 'oval',
array( array(

View File

@ -12,7 +12,7 @@ $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext'
// 2D charts // 2D charts
$section = $phpWord->addSection(); $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')); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar'); $chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
@ -38,7 +38,7 @@ foreach ($chartTypes as $chartType) {
// 3D charts // 3D charts
$section = $phpWord->addSection(array('breakType' => 'continuous')); $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')); $section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
$chartTypes = array('pie', 'bar', 'column', 'line', 'area'); $chartTypes = array('pie', 'bar', 'column', 'line', 'area');

View File

@ -9,15 +9,15 @@ $phpWord->getProtection()->setEditing('forms');
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $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->addFormField('textinput')->setName('MyTextBox');
$textrun->addText(htmlspecialchars(', checkbox ')); $textrun->addText(htmlspecialchars(', checkbox ', ENT_COMPAT, 'UTF-8'));
$textrun->addFormField('checkbox')->setDefault(true); $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->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'); $section->addFormField('textinput')->setValue('Your name');
// Save file // Save file

View File

@ -8,15 +8,15 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $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->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText(htmlspecialchars('Date: ')); $textrun->addText(htmlspecialchars('Date: ', ENT_COMPAT, 'UTF-8'));
$textrun->addSDT('date'); $textrun->addSDT('date');
$textrun = $section->addTextRun(); $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')); $textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
// Save file // Save file

View File

@ -6,13 +6,13 @@ echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $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; $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->addPageBreak();
$section->addTitle(htmlspecialchars('This is page 2'), 1); $section->addTitle(htmlspecialchars('This is page 2', ENT_COMPAT, 'UTF-8'), 1);
$section->addPageBreak(); $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'); $section->addBookmark('MyBookmark');
// Save file // Save file

View File

@ -7,10 +7,10 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $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 = $section->addTextRun(array('align' => 'right'));
$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است'), array('rtl' => true)); $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
// Save file // Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers); echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -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\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 \pard\nowidctlpar{\cf1\f1\fs40\b\i\ul\strike\super I am inline styled.}\par
\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 \par
} }

View File

@ -48,15 +48,15 @@ class AutoloaderTest extends \PHPUnit_Framework_TestCase
$this->assertCount( $this->assertCount(
$declaredCount, $declaredCount,
get_declared_classes(), get_declared_classes(),
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load ' . 'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load '
'classes outside of the PhpOffice\\PhpWord namespace' . 'classes outside of the PhpOffice\\PhpWord namespace'
); );
// TODO change this class to the main PhpWord class when it is namespaced // TODO change this class to the main PhpWord class when it is namespaced
Autoloader::autoload('PhpOffice\\PhpWord\\Exception\\InvalidStyleException'); Autoloader::autoload('PhpOffice\\PhpWord\\Exception\\InvalidStyleException');
$this->assertTrue( $this->assertTrue(
in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', get_declared_classes()), in_array('PhpOffice\\PhpWord\\Exception\\InvalidStyleException', get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' . 'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the '
'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class' . 'PhpOffice\\PhpWord\\Exception\\InvalidStyleException class'
); );
} }
} }

View File

@ -30,7 +30,7 @@ class AbstractElementTest extends \PHPUnit_Framework_TestCase
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement'); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
$ival = rand(0, 100); $ival = rand(0, 100);
$stub->setElementIndex($ival); $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 = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Element\AbstractElement');
$stub->setElementId(); $stub->setElementId();
$this->assertEquals(strlen($stub->getElementId()), 6); $this->assertEquals(6, strlen($stub->getElementId()));
} }
} }

View File

@ -34,7 +34,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
$oCell = new Cell(); $oCell = new Cell();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Cell', $oCell); $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')); $oCell = new Cell(null, array('valign' => 'center'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Cell', $oCell->getStyle()); $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() public function testAddText()
{ {
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addText('text'); $element = $oCell->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
@ -66,11 +66,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addText(utf8_decode('ééé')); $element = $oCell->addText(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $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() public function testAddLink()
{ {
$oCell = new Cell(); $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->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
@ -102,11 +102,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
public function testAddListItem() public function testAddListItem()
{ {
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addListItem('text'); $element = $oCell->addListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); $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() public function testAddListItemNotUTF8()
{ {
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addListItem(utf8_decode('ééé')); $element = $oCell->addListItem(utf8_decode(htmlspecialchars('ééé', ENT_COMPAT, 'UTF-8')));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItem', $element); $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() public function testAddImageSection()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -140,7 +140,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddImageHeader() public function testAddImageHeader()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oCell = new Cell('header', 1); $oCell = new Cell('header', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -153,7 +153,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddImageFooter() public function testAddImageFooter()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oCell = new Cell('footer', 1); $oCell = new Cell('footer', 1);
$element = $oCell->addImage($src); $element = $oCell->addImage($src);
@ -180,7 +180,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddObjectXLS() public function testAddObjectXLS()
{ {
$src = __DIR__ . "/../_files/documents/sheet.xls"; $src = __DIR__ . '/../_files/documents/sheet.xls';
$oCell = new Cell(); $oCell = new Cell();
$element = $oCell->addObject($src); $element = $oCell->addObject($src);
@ -195,7 +195,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddObjectException() public function testAddObjectException()
{ {
$src = __DIR__ . "/../_files/xsl/passthrough.xsl"; $src = __DIR__ . '/../_files/xsl/passthrough.xsl';
$oCell = new Cell(); $oCell = new Cell();
$oCell->addObject($src); $oCell->addObject($src);
} }
@ -207,7 +207,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{ {
$oCell = new Cell(); $oCell = new Cell();
$oCell->setDocPart('Header', 1); $oCell->setDocPart('Header', 1);
$element = $oCell->addPreserveText('text'); $element = $oCell->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oCell->getElements()); $this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
@ -220,11 +220,11 @@ class CellTest extends \PHPUnit_Framework_TestCase
{ {
$oCell = new Cell(); $oCell = new Cell();
$oCell->setDocPart('Header', 1); $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->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $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 = new Cell();
$oCell->setDocPart('Section', 1); $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() public function testAddCheckBox()
{ {
$oCell = new Cell(); $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->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $element);

View File

@ -35,7 +35,7 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
$oCheckBox = new CheckBox(); $oCheckBox = new CheckBox();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\CheckBox', $oCheckBox); $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\\Font', $oCheckBox->getFontStyle());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle());
} }
@ -45,10 +45,10 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCheckBox() 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(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getName());
$this->assertEquals($oCheckBox->getText(), 'CheckBox'); $this->assertEquals(htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $oCheckBox->getText());
} }
/** /**
@ -56,8 +56,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testFont() public function testFont()
{ {
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle'); $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle');
$this->assertEquals($oCheckBox->getFontStyle(), 'fontStyle'); $this->assertEquals('fontStyle', $oCheckBox->getFontStyle());
$oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $oCheckBox->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oCheckBox->getFontStyle());
@ -69,8 +69,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
public function testFontObject() public function testFontObject()
{ {
$font = new Font(); $font = new Font();
$oCheckBox = new CheckBox('chkBox', 'CheckBox', $font); $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), $font);
$this->assertEquals($oCheckBox->getFontStyle(), $font); $this->assertEquals($font, $oCheckBox->getFontStyle());
} }
/** /**
@ -78,8 +78,8 @@ class CheckBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testParagraph() public function testParagraph()
{ {
$oCheckBox = new CheckBox('chkBox', 'CheckBox', 'fontStyle', 'paragraphStyle'); $oCheckBox = new CheckBox(htmlspecialchars('chkBox', ENT_COMPAT, 'UTF-8'), htmlspecialchars('CheckBox', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle');
$this->assertEquals($oCheckBox->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oCheckBox->getParagraphStyle());
$oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $oCheckBox->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oCheckBox->getParagraphStyle());

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Tests\Element; namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Element\Field; use PhpOffice\PhpWord\Element\Field;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Test class for PhpOffice\PhpWord\Element\Field * Test class for PhpOffice\PhpWord\Element\Field
@ -45,7 +44,7 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$oField = new Field('DATE'); $oField = new Field('DATE');
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField); $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() 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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField);
$this->assertEquals($oField->getType(), 'DATE'); $this->assertEquals('DATE', $oField->getType());
$this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties());
} }
/** /**
@ -65,12 +64,12 @@ class FieldTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithTypePropertiesOptions() 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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Field', $oField);
$this->assertEquals($oField->getType(), 'DATE'); $this->assertEquals('DATE', $oField->getType());
$this->assertEquals($oField->getProperties(), array('dateformat'=>'d-M-yyyy')); $this->assertEquals(array('dateformat' => 'd-M-yyyy'), $oField->getProperties());
$this->assertEquals($oField->getOptions(), array('SakaEraCalendar', 'PreserveFormat')); $this->assertEquals(array('SakaEraCalendar', 'PreserveFormat'), $oField->getOptions());
} }
/** /**

View File

@ -35,7 +35,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$oFooter = new Footer($iVal); $oFooter = new Footer($iVal);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter); $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() public function testAddText()
{ {
$oFooter = new Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addText('text'); $element = $oFooter->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
@ -56,11 +56,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddTextNotUTF8() public function testAddTextNotUTF8()
{ {
$oFooter = new Footer(1); $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->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $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() public function testAddImage()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oFooter = new Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addImage($src); $element = $oFooter->addImage($src);
@ -132,7 +132,7 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddPreserveText() public function testAddPreserveText()
{ {
$oFooter = new Footer(1); $oFooter = new Footer(1);
$element = $oFooter->addPreserveText('text'); $element = $oFooter->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oFooter->getElements()); $this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
@ -144,11 +144,11 @@ class FooterTest extends \PHPUnit_Framework_TestCase
public function testAddPreserveTextNotUTF8() public function testAddPreserveTextNotUTF8()
{ {
$oFooter = new Footer(1); $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->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $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); $iVal = rand(1, 1000);
$oFooter->setRelationId($iVal); $oFooter->setRelationId($iVal);
$this->assertEquals($oFooter->getRelationId(), $iVal); $this->assertEquals($iVal, $oFooter->getRelationId());
$this->assertEquals(Footer::AUTO, $oFooter->getType()); $this->assertEquals(Footer::AUTO, $oFooter->getType());
} }
} }

View File

@ -35,7 +35,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote);
$this->assertCount(0, $oFootnote->getElements()); $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'); $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() public function testAddText()
{ {
$oFootnote = new Footnote(); $oFootnote = new Footnote();
$element = $oFootnote->addText('text'); $element = $oFootnote->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oFootnote->getElements()); $this->assertCount(1, $oFootnote->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
@ -90,7 +90,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
public function testAddLink() public function testAddLink()
{ {
$oFootnote = new Footnote(); $oFootnote = new Footnote();
$element = $oFootnote->addLink('http://www.google.fr'); $element = $oFootnote->addLink('https://github.com/PHPOffice/PHPWord');
$this->assertCount(1, $oFootnote->getElements()); $this->assertCount(1, $oFootnote->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
@ -105,7 +105,7 @@ class FootnoteTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oFootnote->setRelationId($iVal); $oFootnote->setRelationId($iVal);
$this->assertEquals($oFootnote->getRelationId(), $iVal); $this->assertEquals($iVal, $oFootnote->getRelationId());
} }
/** /**

View File

@ -35,8 +35,8 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$oHeader = new Header($iVal); $oHeader = new Header($iVal);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Header', $oHeader);
$this->assertEquals($oHeader->getSectionId(), $iVal); $this->assertEquals($iVal, $oHeader->getSectionId());
$this->assertEquals($oHeader->getType(), Header::AUTO); $this->assertEquals(Header::AUTO, $oHeader->getType());
} }
/** /**
@ -45,11 +45,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddText() public function testAddText()
{ {
$oHeader = new Header(1); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oHeader->getElements()); $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() public function testAddTextNotUTF8()
{ {
$oHeader = new Header(1); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oHeader->getElements()); $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() public function testAddImage()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oHeader = new Header(1); $oHeader = new Header(1);
$element = $oHeader->addImage($src); $element = $oHeader->addImage($src);
@ -141,7 +141,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddPreserveText() public function testAddPreserveText()
{ {
$oHeader = new Header(1); $oHeader = new Header(1);
$element = $oHeader->addPreserveText('text'); $element = $oHeader->addPreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertCount(1, $oHeader->getElements()); $this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
@ -153,11 +153,11 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
public function testAddPreserveTextNotUTF8() public function testAddPreserveTextNotUTF8()
{ {
$oHeader = new Header(1); $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->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element); $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() public function testAddWatermark()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oHeader = new Header(1); $oHeader = new Header(1);
$element = $oHeader->addWatermark($src); $element = $oHeader->addWatermark($src);
@ -192,7 +192,7 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oHeader->setRelationId($iVal); $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->firstPage();
$oHeader->resetType(); $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 = new Header(1);
$oHeader->firstPage(); $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 = new Header(1);
$oHeader->evenPage(); $oHeader->evenPage();
$this->assertEquals($oHeader->getType(), Header::EVEN); $this->assertEquals(Header::EVEN, $oHeader->getType());
} }
/** /**

View File

@ -31,14 +31,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$src = __DIR__ . "/../_files/images/firefox.png"; $src = __DIR__ . '/../_files/images/firefox.png';
$oImage = new Image($src); $oImage = new Image($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src); $this->assertEquals($src, $oImage->getSource());
$this->assertEquals($oImage->getMediaId(), md5($src)); $this->assertEquals(md5($src), $oImage->getMediaId());
$this->assertEquals($oImage->isWatermark(), false); // todo: change to assertNotTrue when got upgraded to PHPUnit 4.x
$this->assertEquals($oImage->getSourceType(), Image::SOURCE_LOCAL); $this->assertEquals(false, $oImage->isWatermark());
$this->assertEquals(Image::SOURCE_LOCAL, $oImage->getSourceType());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
@ -47,11 +48,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithStyle() public function testConstructWithStyle()
{ {
$src = __DIR__ . "/../_files/images/firefox.png"; $src = __DIR__ . '/../_files/images/firefox.png';
$oImage = new Image( $oImage = new Image(
$src, $src,
array('width' => 210, 'height' => 210, 'align' => 'center', array(
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND) 'width' => 210,
'height' => 210,
'align' => 'center',
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_BEHIND,
)
); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
@ -72,15 +77,15 @@ class ImageTest extends \PHPUnit_Framework_TestCase
foreach ($images as $imageData) { foreach ($images as $imageData) {
list($source, $type, $extension, $createFunction, $imageFunction) = $imageData; list($source, $type, $extension, $createFunction, $imageFunction) = $imageData;
$source = __DIR__ . "/../_files/images/" . $source; $source = __DIR__ . "/../_files/images/{$source}";
$image = new Image($source); $image = new Image($source);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image);
$this->assertEquals($image->getSource(), $source); $this->assertEquals($source, $image->getSource());
$this->assertEquals($image->getMediaId(), md5($source)); $this->assertEquals(md5($source), $image->getMediaId());
$this->assertEquals($image->getImageType(), $type); $this->assertEquals($type, $image->getImageType());
$this->assertEquals($image->getImageExtension(), $extension); $this->assertEquals($extension, $image->getImageExtension());
$this->assertEquals($image->getImageCreateFunction(), $createFunction); $this->assertEquals($createFunction, $image->getImageCreateFunction());
$this->assertEquals($image->getImageFunction(), $imageFunction); $this->assertEquals($imageFunction, $image->getImageFunction());
$this->assertFalse($image->isMemImage()); $this->assertFalse($image->isMemImage());
} }
} }
@ -91,7 +96,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testStyle() public function testStyle()
{ {
$oImage = new Image( $oImage = new Image(
__DIR__ . "/../_files/images/earth.jpg", __DIR__ . '/../_files/images/earth.jpg',
array('height' => 210, 'align' => 'center') array('height' => 210, 'align' => 'center')
); );
@ -105,7 +110,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInvalidImageLocal() 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() 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); $iVal = rand(1, 1000);
$oImage->setRelationId($iVal); $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() public function testArchivedImage()
{ {
$archiveFile = __DIR__ . "/../_files/documents/reader.docx"; $archiveFile = __DIR__ . '/../_files/documents/reader.docx';
$imageFile = 'word/media/image1.jpeg'; $imageFile = 'word/media/image1.jpeg';
$image = new Image("zip://{$archiveFile}#{$imageFile}"); $image = new Image("zip://{$archiveFile}#{$imageFile}");
$this->assertEquals('image/jpeg', $image->getImageType()); $this->assertEquals('image/jpeg', $image->getImageType());

View File

@ -35,7 +35,7 @@ class LineTest extends \PHPUnit_Framework_TestCase
$oLine = new Line(); $oLine = new Line();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Line', $oLine); $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'); $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( $oLine = new Line(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(14),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
'positioning' => 'absolute', 'positioning' => 'absolute',
'posHorizontalRel' => 'page', 'posHorizontalRel' => 'page',
'posVerticalRel' => 'page', 'posVerticalRel' => 'page',
'flip' => true, 'flip' => true,
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5), 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(5),
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3), 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10 'weight' => 10,
) )
); );

View File

@ -33,13 +33,13 @@ class LinkTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructDefault() 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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
$this->assertEquals($oLink->getSource(), 'http://www.google.com'); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource());
$this->assertEquals($oLink->getText(), $oLink->getSource()); $this->assertEquals($oLink->getSource(), $oLink->getText());
$this->assertEquals($oLink->getFontStyle(), null); $this->assertNull($oLink->getFontStyle());
$this->assertEquals($oLink->getParagraphStyle(), null); $this->assertNull($oLink->getParagraphStyle());
} }
/** /**
@ -48,15 +48,15 @@ class LinkTest extends \PHPUnit_Framework_TestCase
public function testConstructWithParamsArray() public function testConstructWithParamsArray()
{ {
$oLink = new Link( $oLink = new Link(
'http://www.google.com', 'https://github.com/PHPOffice/PHPWord',
'Search Engine', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'),
array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE), array('color' => '0000FF', 'underline' => Font::UNDERLINE_SINGLE),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $oLink);
$this->assertEquals($oLink->getSource(), 'http://www.google.com'); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $oLink->getSource());
$this->assertEquals($oLink->getText(), 'Search Engine'); $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\\Font', $oLink->getFontStyle());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oLink->getParagraphStyle());
} }
@ -66,10 +66,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithParamsString() 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('fontStyle', $oLink->getFontStyle());
$this->assertEquals($oLink->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oLink->getParagraphStyle());
} }
/** /**
@ -77,10 +77,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
*/ */
public function testRelationId() public function testRelationId()
{ {
$oLink = new Link('http://www.google.com'); $oLink = new Link('https://github.com/PHPOffice/PHPWord');
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oLink->setRelationId($iVal); $oLink->setRelationId($iVal);
$this->assertEquals($oLink->getRelationId(), $iVal); $this->assertEquals($iVal, $oLink->getRelationId());
} }
} }

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Tests\Element; namespace PhpOffice\PhpWord\Tests\Element;
use PhpOffice\PhpWord\Element\ListItemRun; use PhpOffice\PhpWord\Element\ListItemRun;
use PhpOffice\PhpWord\PhpWord;
/** /**
* Test class for PhpOffice\PhpWord\Element\ListItemRun * 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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
$this->assertCount(0, $oListItemRun->getElements()); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
$this->assertCount(0, $oListItemRun->getElements()); $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)); $oListItemRun = new ListItemRun(1, array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItemRun->getStyle()); $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 * getDepth
*/ */
@ -92,7 +92,7 @@ class ListItemRunTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oListItemRun = new ListItemRun($iVal); $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() public function testAddText()
{ {
$oListItemRun = new ListItemRun(); $oListItemRun = new ListItemRun();
$element = $oListItemRun->addText('text'); $element = $oListItemRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oListItemRun->getElements()); $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() public function testAddTextNotUTF8()
{ {
$oListItemRun = new ListItemRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oListItemRun->getElements()); $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() public function testAddLink()
{ {
$oListItemRun = new ListItemRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oListItemRun->getElements()); $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() public function testAddLinkWithName()
{ {
$oListItemRun = new ListItemRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oListItemRun->getElements()); $this->assertCount(1, $oListItemRun->getElements());
$this->assertEquals($element->getSource(), 'http://www.google.fr'); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
$this->assertEquals($element->getText(), 'ééé'); $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() public function testAddImage()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oListItemRun = new ListItemRun(); $oListItemRun = new ListItemRun();
$element = $oListItemRun->addImage($src); $element = $oListItemRun->addImage($src);

View File

@ -32,7 +32,7 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
*/ */
public function testText() public function testText()
{ {
$oListItem = new ListItem('text'); $oListItem = new ListItem(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oListItem->getTextObject());
} }
@ -43,17 +43,14 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
public function testStyle() public function testStyle()
{ {
$oListItem = new ListItem( $oListItem = new ListItem(
'text', htmlspecialchars('text', ENT_COMPAT, 'UTF-8'),
1, 1,
null, null,
array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER) array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER)
); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItem->getStyle());
$this->assertEquals( $this->assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItem->getStyle()->getListType());
$oListItem->getStyle()->getListType(),
\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER
);
} }
/** /**
@ -62,8 +59,8 @@ class ListItemTest extends \PHPUnit_Framework_TestCase
public function testDepth() public function testDepth()
{ {
$iVal = rand(1, 1000); $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());
} }
} }

View File

@ -32,12 +32,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithSupportedFiles() public function testConstructWithSupportedFiles()
{ {
$src = __DIR__ . "/../_files/documents/sheet.xls"; $src = __DIR__ . '/../_files/documents/sheet.xls';
$oObject = new Object($src); $oObject = new Object($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); $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() public function testConstructWithNotSupportedFiles()
{ {
$src = __DIR__ . "/../_files/xsl/passthrough.xsl"; $src = __DIR__ . '/../_files/xsl/passthrough.xsl';
$oObject = new Object($src); $oObject = new Object($src);
$oObject->getSource(); $oObject->getSource();
} }
@ -57,12 +57,12 @@ class ObjectTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithSupportedFilesAndStyle() public function testConstructWithSupportedFilesAndStyle()
{ {
$src = __DIR__ . "/../_files/documents/sheet.xls"; $src = __DIR__ . '/../_files/documents/sheet.xls';
$oObject = new Object($src, array('width' => '230px')); $oObject = new Object($src, array('width' => '230px'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Object', $oObject);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oObject->getStyle()); $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() public function testRelationId()
{ {
$src = __DIR__ . "/../_files/documents/sheet.xls"; $src = __DIR__ . '/../_files/documents/sheet.xls';
$oObject = new Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oObject->setRelationId($iVal); $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() public function testImageRelationId()
{ {
$src = __DIR__ . "/../_files/documents/sheet.xls"; $src = __DIR__ . '/../_files/documents/sheet.xls';
$oObject = new Object($src); $oObject = new Object($src);
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oObject->setImageRelationId($iVal); $oObject->setImageRelationId($iVal);
$this->assertEquals($oObject->getImageRelationId(), $iVal); $this->assertEquals($iVal, $oObject->getImageRelationId());
} }
} }

View File

@ -34,9 +34,9 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
$oPreserveText = new PreserveText(); $oPreserveText = new PreserveText();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $oPreserveText); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $oPreserveText);
$this->assertEquals($oPreserveText->getText(), null); $this->assertNull($oPreserveText->getText());
$this->assertEquals($oPreserveText->getFontStyle(), null); $this->assertNull($oPreserveText->getFontStyle());
$this->assertEquals($oPreserveText->getParagraphStyle(), null); $this->assertNull($oPreserveText->getParagraphStyle());
} }
/** /**
@ -44,10 +44,10 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstructWithString() public function testConstructWithString()
{ {
$oPreserveText = new PreserveText('text', 'styleFont', 'styleParagraph'); $oPreserveText = new PreserveText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'styleFont', 'styleParagraph');
$this->assertEquals($oPreserveText->getText(), array('text')); $this->assertEquals(array(htmlspecialchars('text', ENT_COMPAT, 'UTF-8')), $oPreserveText->getText());
$this->assertEquals($oPreserveText->getFontStyle(), 'styleFont'); $this->assertEquals('styleFont', $oPreserveText->getFontStyle());
$this->assertEquals($oPreserveText->getParagraphStyle(), 'styleParagraph'); $this->assertEquals('styleParagraph', $oPreserveText->getParagraphStyle());
} }
/** /**
@ -56,14 +56,11 @@ class PreserveTextTest extends \PHPUnit_Framework_TestCase
public function testConstructWithArray() public function testConstructWithArray()
{ {
$oPreserveText = new PreserveText( $oPreserveText = new PreserveText(
'text', htmlspecialchars('text', ENT_COMPAT, 'UTF-8'),
array('align' => 'center'), array('align' => 'center'),
array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
); );
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oPreserveText->getFontStyle());
$this->assertInstanceOf( $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oPreserveText->getParagraphStyle());
'PhpOffice\\PhpWord\\Style\\Paragraph',
$oPreserveText->getParagraphStyle()
);
} }
} }

View File

@ -35,7 +35,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
$oRow = new Row(); $oRow = new Row();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $oRow);
$this->assertEquals($oRow->getHeight(), null); $this->assertNull($oRow->getHeight());
$this->assertInternalType('array', $oRow->getCells()); $this->assertInternalType('array', $oRow->getCells());
$this->assertCount(0, $oRow->getCells()); $this->assertCount(0, $oRow->getCells());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
@ -49,7 +49,7 @@ class RowTest extends \PHPUnit_Framework_TestCase
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oRow = new Row($iVal, array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF')); $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()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Row', $oRow->getStyle());
} }

View File

@ -36,7 +36,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
public function testGetStyle() public function testGetStyle()
{ {
$oSection = new Section(0); $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() public function testGetElements()
{ {
$oSection = new Section(0); $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() public function testGetFooters()
{ {
$oSection = new Section(0); $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() public function testGetHeaders()
{ {
$oSection = new Section(0); $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() public function testAddElements()
{ {
$objectSource = __DIR__ . "/../_files/documents/reader.docx"; $objectSource = __DIR__ . '/../_files/documents/reader.docx';
$imageSource = __DIR__ . "/../_files/images/PhpWord.png"; $imageSource = __DIR__ . '/../_files/images/PhpWord.png';
// $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif'; // $imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new Section(0); $section = new Section(0);
$section->setPhpWord(new PhpWord()); $section->setPhpWord(new PhpWord());
$section->addText(utf8_decode('ä')); $section->addText(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä')); $section->addLink(utf8_decode('http://äää.com'), utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
$section->addTextBreak(); $section->addTextBreak();
$section->addPageBreak(); $section->addPageBreak();
$section->addTable(); $section->addTable();
$section->addListItem(utf8_decode('ä')); $section->addListItem(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')));
$section->addObject($objectSource); $section->addObject($objectSource);
$section->addImage($imageSource); $section->addImage($imageSource);
$section->addTitle(utf8_decode('ä'), 1); $section->addTitle(utf8_decode(htmlspecialchars('ä', ENT_COMPAT, 'UTF-8')), 1);
$section->addTextRun(); $section->addTextRun();
$section->addFootnote(); $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(); $section->addTOC();
$elementCollection = $section->getElements(); $elementCollection = $section->getElements();
$elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak', $elementTypes = array(
'Table', 'ListItem', 'Object', 'Image', 'Text',
'Title', 'TextRun', 'Footnote', 'CheckBox', 'TOC'); 'Link',
'TextBreak',
'PageBreak',
'Table',
'ListItem',
'Object',
'Image',
'Title',
'TextRun',
'Footnote',
'CheckBox',
'TOC',
);
$elmCount = 0; $elmCount = 0;
foreach ($elementTypes as $elementType) { foreach ($elementTypes as $elementType) {
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]); $this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\{$elementType}", $elementCollection[$elmCount]);
@ -120,7 +132,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
*/ */
public function testAddObjectException() public function testAddObjectException()
{ {
$source = __DIR__ . "/_files/xsl/passthrough.xsl"; $source = __DIR__ . '/_files/xsl/passthrough.xsl';
$section = new Section(0); $section = new Section(0);
$section->addObject($source); $section->addObject($source);
} }
@ -133,10 +145,10 @@ class SectionTest extends \PHPUnit_Framework_TestCase
Style::addTitleStyle(1, array('size' => 14)); Style::addTitleStyle(1, array('size' => 14));
$section = new Section(0); $section = new Section(0);
$section->setPhpWord(new PhpWord()); $section->setPhpWord(new PhpWord());
$section->addTitle('Test', 1); $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
$elementCollection = $section->getElements(); $elementCollection = $section->getElements();
$this->assertInstanceOf("PhpOffice\\PhpWord\\Element\\Title", $elementCollection[0]); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $elementCollection[0]);
} }
/** /**

View File

@ -34,9 +34,9 @@ class TOCTest extends \PHPUnit_Framework_TestCase
public function testConstructWithStyleArray() public function testConstructWithStyleArray()
{ {
$expected = array( $expected = array(
'position' => 9062, 'position' => 9062,
'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT, 'leader' => \PhpOffice\PhpWord\Style\Tab::TAB_LEADER_DOT,
'indent' => 200, 'indent' => 200,
); );
$object = new TOC(array('size' => 11), array('position' => $expected['position'])); $object = new TOC(array('size' => 11), array('position' => $expected['position']));
$tocStyle = $object->getStyleTOC(); $tocStyle = $object->getStyleTOC();
@ -86,7 +86,7 @@ class TOCTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
foreach ($titles as $text => $depth) { 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 = new TOC();
$toc->setPhpWord($phpWord); $toc->setPhpWord($phpWord);

View File

@ -35,9 +35,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
$oTable = new Table(); $oTable = new Table();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $oTable); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $oTable);
$this->assertEquals($oTable->getStyle(), null); $this->assertNull($oTable->getStyle());
$this->assertEquals($oTable->getWidth(), null); $this->assertNull($oTable->getWidth());
$this->assertEquals($oTable->getRows(), array()); $this->assertEquals(array(), $oTable->getRows());
$this->assertCount(0, $oTable->getRows()); $this->assertCount(0, $oTable->getRows());
} }
@ -48,7 +48,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
{ {
$oTable = new Table('tableStyle'); $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() public function testStyleArray()
{ {
$oTable = new Table(array( $oTable = new Table(array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80));
'borderSize' => 6,
'borderColor' => '006699',
'cellMargin' => 80
));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $oTable->getStyle());
} }
@ -71,9 +67,9 @@ class TableTest extends \PHPUnit_Framework_TestCase
public function testWidth() public function testWidth()
{ {
$oTable = new Table(); $oTable = new Table();
$iVal = rand(1, 1000); $iVal = rand(1, 1000);
$oTable->setWidth($iVal); $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() public function testRow()
{ {
$oTable = new Table(); $oTable = new Table();
$element = $oTable->addRow(); $element = $oTable->addRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Row', $element);
$this->assertCount(1, $oTable->getRows()); $this->assertCount(1, $oTable->getRows());

View File

@ -35,7 +35,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
$oTextBox = new TextBox(); $oTextBox = new TextBox();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextBox', $oTextBox); $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'); $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( $oTextBox = new TextBox(
array( array(
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5), 'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4.5),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(17.5),
'positioning' => 'absolute', 'positioning' => 'absolute',
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4), 'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.4),
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9), 'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.9),
'stroke' => 0, 'stroke' => 0,
'innerMargin' => 0, 'innerMargin' => 0,
'borderSize' => 1, 'borderSize' => 1,
'borderColor' => '' 'borderColor' => '',
) )
); );

View File

@ -36,7 +36,7 @@ class TextRunTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $oTextRun);
$this->assertCount(0, $oTextRun->getElements()); $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() public function testAddText()
{ {
$oTextRun = new TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addText('text'); $element = $oTextRun->addText(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $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() public function testAddTextNotUTF8()
{ {
$oTextRun = new TextRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
$this->assertCount(1, $oTextRun->getElements()); $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() public function testAddLink()
{ {
$oTextRun = new TextRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oTextRun->getElements()); $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() public function testAddLinkWithName()
{ {
$oTextRun = new TextRun(); $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->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
$this->assertCount(1, $oTextRun->getElements()); $this->assertCount(1, $oTextRun->getElements());
$this->assertEquals($element->getSource(), 'http://www.google.fr'); $this->assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
$this->assertEquals($element->getText(), 'ééé'); $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() public function testAddImage()
{ {
$src = __DIR__ . "/../_files/images/earth.jpg"; $src = __DIR__ . '/../_files/images/earth.jpg';
$oTextRun = new TextRun(); $oTextRun = new TextRun();
$element = $oTextRun->addImage($src); $element = $oTextRun->addImage($src);

View File

@ -35,7 +35,7 @@ class TextTest extends \PHPUnit_Framework_TestCase
$oText = new Text(); $oText = new Text();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $oText); $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\\Font', $oText->getFontStyle());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());
} }
@ -45,9 +45,9 @@ class TextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testText() 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() public function testFont()
{ {
$oText = new Text('text', 'fontStyle'); $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle');
$this->assertEquals($oText->getFontStyle(), 'fontStyle'); $this->assertEquals('fontStyle', $oText->getFontStyle());
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16)); $oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Font', $oText->getFontStyle());
@ -68,8 +68,8 @@ class TextTest extends \PHPUnit_Framework_TestCase
public function testFontObject() public function testFontObject()
{ {
$font = new Font(); $font = new Font();
$oText = new Text('text', $font); $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), $font);
$this->assertEquals($oText->getFontStyle(), $font); $this->assertEquals($font, $oText->getFontStyle());
} }
/** /**
@ -77,8 +77,8 @@ class TextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testParagraph() public function testParagraph()
{ {
$oText = new Text('text', 'fontStyle', 'paragraphStyle'); $oText = new Text(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'), 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle'); $this->assertEquals('paragraphStyle', $oText->getParagraphStyle());
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100)); $oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oText->getParagraphStyle());

View File

@ -32,10 +32,10 @@ class TitleTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$oTitle = new Title('text'); $oTitle = new Title(htmlspecialchars('text', ENT_COMPAT, 'UTF-8'));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Title', $oTitle); $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() 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());
} }
} }

View File

@ -74,7 +74,7 @@ class IOFactoryTest extends \PHPUnit_Framework_TestCase
*/ */
public function testLoad() public function testLoad()
{ {
$file = __DIR__ . "/_files/templates/blank.docx"; $file = __DIR__ . '/_files/templates/blank.docx';
$this->assertInstanceOf( $this->assertInstanceOf(
'PhpOffice\\PhpWord\\PhpWord', 'PhpOffice\\PhpWord\\PhpWord',
IOFactory::load($file) IOFactory::load($file)

View File

@ -32,7 +32,7 @@ class MediaTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetSectionMediaElementsWithNull() 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() public function testAddSectionMediaElement()
{ {
$local = __DIR__ . "/_files/images/mars.jpg"; $local = __DIR__ . '/_files/images/mars.jpg';
$object = __DIR__ . "/_files/documents/sheet.xls"; $object = __DIR__ . '/_files/documents/sheet.xls';
$remote = 'http://php.net/images/logos/php-med-trans-light.gif'; $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));
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() 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'; $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));
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() 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'; $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));
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() public function testAddElementImageException()
{ {
Media::addElement('section', 'image', __DIR__ . "/_files/images/mars.jpg"); Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg');
} }
} }

View File

@ -182,42 +182,22 @@ class DocInfoTest extends \PHPUnit_Framework_TestCase
$oProperties->setCustomProperty('key3', 3); $oProperties->setCustomProperty('key3', 3);
$oProperties->setCustomProperty('key4', 4.4); $oProperties->setCustomProperty('key4', 4.4);
$oProperties->setCustomProperty('key5', 'value5'); $oProperties->setCustomProperty('key5', 'value5');
$this->assertEquals( $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key1'));
DocInfo::PROPERTY_TYPE_STRING, $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, $oProperties->getCustomPropertyType('key2'));
$oProperties->getCustomPropertyType('key1') $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, $oProperties->getCustomPropertyType('key3'));
); $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, $oProperties->getCustomPropertyType('key4'));
$this->assertEquals( $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, $oProperties->getCustomPropertyType('key5'));
DocInfo::PROPERTY_TYPE_BOOLEAN, $this->assertNull($oProperties->getCustomPropertyType('key6'));
$oProperties->getCustomPropertyType('key2') $this->assertNull($oProperties->getCustomPropertyValue('key1'));
); $this->assertTrue($oProperties->getCustomPropertyValue('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(3, $oProperties->getCustomPropertyValue('key3')); $this->assertEquals(3, $oProperties->getCustomPropertyValue('key3'));
$this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4')); $this->assertEquals(4.4, $oProperties->getCustomPropertyValue('key4'));
$this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5')); $this->assertEquals('value5', $oProperties->getCustomPropertyValue('key5'));
$this->assertEquals(null, $oProperties->getCustomPropertyValue('key6')); $this->assertNull($oProperties->getCustomPropertyValue('key6'));
$this->assertEquals(true, $oProperties->isCustomPropertySet('key5')); $this->assertTrue($oProperties->isCustomPropertySet('key5'));
// todo: change to assertNotTrue when got upgraded to PHPUnit 4.x
$this->assertEquals(false, $oProperties->isCustomPropertySet('key6')); $this->assertEquals(false, $oProperties->isCustomPropertySet('key6'));
$this->assertEquals(array( $this->assertEquals(array('key1', 'key2', 'key3', 'key4', 'key5'), $oProperties->getCustomProperties());
'key1',
'key2',
'key3',
'key4',
'key5'
), $oProperties->getCustomProperties());
} }
/** /**
@ -226,49 +206,25 @@ class DocInfoTest extends \PHPUnit_Framework_TestCase
public function testConvertProperty() public function testConvertProperty()
{ {
$this->assertEquals('', DocInfo::convertProperty('a', 'empty')); $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', 'int'));
$this->assertEquals(8, DocInfo::convertProperty('8.3', 'uint')); $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', 'decimal'));
$this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr')); $this->assertEquals('8.3', DocInfo::convertProperty('8.3', 'lpstr'));
$this->assertEquals(strtotime('10/11/2013'), DocInfo::convertProperty('10/11/2013', 'date')); $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(false, DocInfo::convertProperty('1', 'bool'));
$this->assertEquals('1', DocInfo::convertProperty('1', 'array')); $this->assertEquals('1', DocInfo::convertProperty('1', 'array'));
$this->assertEquals('1', DocInfo::convertProperty('1', '')); $this->assertEquals('1', DocInfo::convertProperty('1', ''));
$this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('int'));
$this->assertEquals( $this->assertEquals(DocInfo::PROPERTY_TYPE_INTEGER, DocInfo::convertPropertyType('uint'));
DocInfo::PROPERTY_TYPE_INTEGER, $this->assertEquals(DocInfo::PROPERTY_TYPE_FLOAT, DocInfo::convertPropertyType('decimal'));
DocInfo::convertPropertyType('int') $this->assertEquals(DocInfo::PROPERTY_TYPE_STRING, DocInfo::convertPropertyType('lpstr'));
); $this->assertEquals(DocInfo::PROPERTY_TYPE_DATE, DocInfo::convertPropertyType('date'));
$this->assertEquals( $this->assertEquals(DocInfo::PROPERTY_TYPE_BOOLEAN, DocInfo::convertPropertyType('bool'));
DocInfo::PROPERTY_TYPE_INTEGER, $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType('array'));
DocInfo::convertPropertyType('uint') $this->assertEquals(DocInfo::PROPERTY_TYPE_UNKNOWN, DocInfo::convertPropertyType(''));
);
$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('')
);
} }
} }

View File

@ -124,7 +124,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
*/ */
public function testLoadTemplate() public function testLoadTemplate()
{ {
$templateFqfn = __DIR__ . "/_files/templates/blank.docx"; $templateFqfn = __DIR__ . '/_files/templates/blank.docx';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$this->assertInstanceOf( $this->assertInstanceOf(

View File

@ -122,8 +122,8 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testLoadConfig() public function testLoadConfig()
{ {
$expected = array( $expected = array(
'compatibility' => true, 'compatibility' => true,
'zipClass' => 'ZipArchive', 'zipClass' => 'ZipArchive',
'pdfRendererName' => 'DomPDF', 'pdfRendererName' => 'DomPDF',
'pdfRendererPath' => '', 'pdfRendererPath' => '',
'defaultFontName' => 'Arial', 'defaultFontName' => 'Arial',

View File

@ -43,8 +43,8 @@ class HtmlTest extends \PHPUnit_Framework_TestCase
} }
// Styles // Styles
$content .= '<p style="text-decoration: underline; text-decoration: line-through; ' . $content .= '<p style="text-decoration: underline; text-decoration: line-through; '
'text-align: center; color: #999; background-color: #000;">'; . 'text-align: center; color: #999; background-color: #000;">';
foreach ($styles as $style) { foreach ($styles as $style) {
$content .= "<{$style}>{$style}</{$style}>"; $content .= "<{$style}>{$style}</{$style}>";
} }

View File

@ -35,7 +35,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetDomFromZipException() public function testGetDomFromZipException()
{ {
$filename = __DIR__ . "/../_files/documents/foo.zip"; $filename = __DIR__ . '/../_files/documents/foo.zip';
$object = new XMLReader(); $object = new XMLReader();
$object->getDomFromZip($filename, 'yadayadaya'); $object->getDomFromZip($filename, 'yadayadaya');
} }
@ -45,7 +45,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetDomFromZipReturnsFalse() public function testGetDomFromZipReturnsFalse()
{ {
$filename = __DIR__ . "/../_files/documents/reader.docx.zip"; $filename = __DIR__ . '/../_files/documents/reader.docx.zip';
$object = new XMLReader(); $object = new XMLReader();
$this->assertFalse($object->getDomFromZip($filename, 'yadayadaya')); $this->assertFalse($object->getDomFromZip($filename, 'yadayadaya'));
} }
@ -64,7 +64,7 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetElementReturnsNull() public function testGetElementReturnsNull()
{ {
$filename = __DIR__ . "/../_files/documents/reader.docx.zip"; $filename = __DIR__ . '/../_files/documents/reader.docx.zip';
$object = new XMLReader(); $object = new XMLReader();
$object->getDomFromZip($filename, '[Content_Types].xml'); $object->getDomFromZip($filename, '[Content_Types].xml');

View File

@ -67,10 +67,10 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
public function testZipArchive($zipClass = 'ZipArchive') public function testZipArchive($zipClass = 'ZipArchive')
{ {
// Preparation // Preparation
$existingFile = __DIR__ . "/../_files/documents/sheet.xls"; $existingFile = __DIR__ . '/../_files/documents/sheet.xls';
$zipFile = __DIR__ . "/../_files/documents/ziptest.zip"; $zipFile = __DIR__ . '/../_files/documents/ziptest.zip';
$destination1 = __DIR__ . "/../_files/documents/extract1"; $destination1 = __DIR__ . '/../_files/documents/extract1';
$destination2 = __DIR__ . "/../_files/documents/extract2"; $destination2 = __DIR__ . '/../_files/documents/extract2';
@mkdir($destination1); @mkdir($destination1);
@mkdir($destination2); @mkdir($destination2);
@ -122,12 +122,12 @@ class ZipArchiveTest extends \PHPUnit_Framework_TestCase
private function deleteDir($dir) private function deleteDir($dir)
{ {
foreach (scandir($dir) as $file) { foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') { if ('.' === $file || '..' === $file) {
continue; continue;
} elseif (is_file($dir . "/" . $file)) { } elseif (is_file($dir . '/' . $file)) {
unlink($dir . "/" . $file); unlink($dir . '/' . $file);
} elseif (is_dir($dir . "/" . $file)) { } elseif (is_dir($dir . '/' . $file)) {
$this->deleteDir($dir . "/" . $file); $this->deleteDir($dir . '/' . $file);
} }
} }

View File

@ -42,7 +42,7 @@ class AbstractStyleTest extends \PHPUnit_Framework_TestCase
{ {
$stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); $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(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)));
$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'); $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(false, self::callProtectedMethod($stub, 'setBoolVal', array('a', false)));
$this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200))); $this->assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', array('foo', 200)));
$this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1))); $this->assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', array('foo', 2.1)));

View File

@ -35,19 +35,19 @@ class CellTest extends \PHPUnit_Framework_TestCase
$object = new Cell(); $object = new Cell();
$attributes = array( $attributes = array(
'valign' => Cell::VALIGN_TOP, 'valign' => Cell::VALIGN_TOP,
'textDirection' => Cell::TEXT_DIR_BTLR, 'textDirection' => Cell::TEXT_DIR_BTLR,
'bgColor' => 'FFFF00', 'bgColor' => 'FFFF00',
'borderTopSize' => 120, 'borderTopSize' => 120,
'borderTopColor' => 'FFFF00', 'borderTopColor' => 'FFFF00',
'borderLeftSize' => 120, 'borderLeftSize' => 120,
'borderLeftColor' => 'FFFF00', 'borderLeftColor' => 'FFFF00',
'borderRightSize' => 120, 'borderRightSize' => 120,
'borderRightColor' => 'FFFF00', 'borderRightColor' => 'FFFF00',
'borderBottomSize' => 120, 'borderBottomSize' => 120,
'borderBottomColor' => 'FFFF00', 'borderBottomColor' => 'FFFF00',
'gridSpan' => 2, 'gridSpan' => 2,
'vMerge' => Cell::VMERGE_RESTART, 'vMerge' => Cell::VMERGE_RESTART,
); );
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";

View File

@ -18,7 +18,6 @@
namespace PhpOffice\PhpWord\Tests\Style; namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
@ -42,9 +41,9 @@ class FontTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInitiation() 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->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $object->getParagraphStyle());
$this->assertTrue(is_array($object->getStyleValues())); $this->assertTrue(is_array($object->getStyleValues()));
} }
@ -57,31 +56,31 @@ class FontTest extends \PHPUnit_Framework_TestCase
$object = new Font(); $object = new Font();
$attributes = array( $attributes = array(
'name' => null, 'name' => null,
'size' => null, 'size' => null,
'hint' => null, 'hint' => null,
'color' => null, 'color' => null,
'bold' => false, 'bold' => false,
'italic' => false, 'italic' => false,
'underline' => Font::UNDERLINE_NONE, 'underline' => Font::UNDERLINE_NONE,
'superScript' => false, 'superScript' => false,
'subScript' => false, 'subScript' => false,
'strikethrough' => false, 'strikethrough' => false,
'doubleStrikethrough' => false, 'doubleStrikethrough' => false,
'smallCaps' => false, 'smallCaps' => false,
'allCaps' => false, 'allCaps' => false,
'fgColor' => null, 'fgColor' => null,
'bgColor' => null, 'bgColor' => null,
'scale' => null, 'scale' => null,
'spacing' => null, 'spacing' => null,
'kerning' => null, 'kerning' => null,
); );
foreach ($attributes as $key => $default) { foreach ($attributes as $key => $default) {
$get = is_bool($default) ? "is{$key}" : "get{$key}"; $get = is_bool($default) ? "is{$key}" : "get{$key}";
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
$object->setStyleValue("$key", null); $object->setStyleValue($key, null);
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
$object->setStyleValue("$key", ''); $object->setStyleValue($key, '');
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
} }
} }
@ -94,25 +93,25 @@ class FontTest extends \PHPUnit_Framework_TestCase
$object = new Font(); $object = new Font();
$attributes = array( $attributes = array(
'name' => 'Times New Roman', 'name' => 'Times New Roman',
'size' => 9, 'size' => 9,
'color' => '999999', 'color' => '999999',
'hint' => 'eastAsia', 'hint' => 'eastAsia',
'bold' => true, 'bold' => true,
'italic' => true, 'italic' => true,
'underline' => Font::UNDERLINE_HEAVY, 'underline' => Font::UNDERLINE_HEAVY,
'superScript' => true, 'superScript' => true,
'subScript' => false, 'subScript' => false,
'strikethrough' => true, 'strikethrough' => true,
'doubleStrikethrough' => false, 'doubleStrikethrough' => false,
'smallCaps' => true, 'smallCaps' => true,
'allCaps' => false, 'allCaps' => false,
'fgColor' => Font::FGCOLOR_YELLOW, 'fgColor' => Font::FGCOLOR_YELLOW,
'bgColor' => 'FFFF00', 'bgColor' => 'FFFF00',
'lineHeight' => 2, 'lineHeight' => 2,
'scale' => 150, 'scale' => 150,
'spacing' => 240, 'spacing' => 240,
'kerning' => 10, 'kerning' => 10,
); );
$object->setStyleByArray($attributes); $object->setStyleByArray($attributes);
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
@ -130,9 +129,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
$section = $phpWord->addSection(); $section = $phpWord->addSection();
// Test style array // Test style array
$text = $section->addText('This is a test', array( $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array('line-height' => 2.0));
'line-height' => 2.0
));
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');

View File

@ -35,12 +35,12 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$object = new Image(); $object = new Image();
$properties = array( $properties = array(
'width' => 200, 'width' => 200,
'height' => 200, 'height' => 200,
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240,
'wrappingStyle' => 'inline' 'wrappingStyle' => 'inline',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";
@ -58,16 +58,16 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$object = new Image(); $object = new Image();
$properties = array( $properties = array(
'width' => 200, 'width' => 200,
'height' => 200, 'height' => 200,
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240,
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN, '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) { foreach ($properties as $key => $value) {
$get = "get{$key}"; $get = "get{$key}";

View File

@ -33,10 +33,10 @@ class IndentationTest extends \PHPUnit_Framework_TestCase
{ {
$object = new Indentation(); $object = new Indentation();
$properties = array( $properties = array(
'left' => array(0, 10), 'left' => array(0, 10),
'right' => array(0, 10), 'right' => array(0, 10),
'firstLine' => array(null, 20), 'firstLine' => array(null, 20),
'hanging' => array(null, 20), 'hanging' => array(null, 20),
); );
foreach ($properties as $property => $value) { foreach ($properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;

View File

@ -33,10 +33,10 @@ class LineNumberingTest extends \PHPUnit_Framework_TestCase
{ {
$object = new LineNumbering(); $object = new LineNumbering();
$properties = array( $properties = array(
'start' => array(1, 2), 'start' => array(1, 2),
'increment' => array(1, 10), 'increment' => array(1, 10),
'distance' => array(null, 10), 'distance' => array(null, 10),
'restart' => array(null, 'continuous'), 'restart' => array(null, 'continuous'),
); );
foreach ($properties as $property => $value) { foreach ($properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;

View File

@ -36,11 +36,11 @@ class LineTest extends \PHPUnit_Framework_TestCase
$properties = array( $properties = array(
'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10, 'weight' => 10,
'color' => 'red' 'color' => 'red',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";
@ -59,11 +59,11 @@ class LineTest extends \PHPUnit_Framework_TestCase
$properties = array( $properties = array(
'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT, 'connectorType' => \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT,
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10, 'weight' => 10,
'color' => 'red' 'color' => 'red',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$get = "get{$key}"; $get = "get{$key}";
@ -71,13 +71,13 @@ class LineTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
} }
} }
/** /**
* Test set/get flip * Test set/get flip
*/ */
public function testSetGetFlip() public function testSetGetFlip()
{ {
$expected=true; $expected = true;
$object = new Line(); $object = new Line();
$object->setFlip($expected); $object->setFlip($expected);
$this->assertEquals($expected, $object->isFlip()); $this->assertEquals($expected, $object->isFlip());
@ -88,18 +88,18 @@ class LineTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetConnectorType() public function testSetGetConnectorType()
{ {
$expected=\PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT; $expected = \PhpOffice\PhpWord\Style\Line::CONNECTOR_TYPE_STRAIGHT;
$object = new Line(); $object = new Line();
$object->setConnectorType($expected); $object->setConnectorType($expected);
$this->assertEquals($expected, $object->getConnectorType()); $this->assertEquals($expected, $object->getConnectorType());
} }
/** /**
* Test set/get weight * Test set/get weight
*/ */
public function testSetGetWeight() public function testSetGetWeight()
{ {
$expected=10; $expected = 10;
$object = new Line(); $object = new Line();
$object->setWeight($expected); $object->setWeight($expected);
$this->assertEquals($expected, $object->getWeight()); $this->assertEquals($expected, $object->getWeight());
@ -110,7 +110,7 @@ class LineTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetColor() public function testSetGetColor()
{ {
$expected='red'; $expected = 'red';
$object = new Line(); $object = new Line();
$object->setColor($expected); $object->setColor($expected);
$this->assertEquals($expected, $object->getColor()); $this->assertEquals($expected, $object->getColor());
@ -121,7 +121,7 @@ class LineTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetDash() 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 = new Line();
$object->setDash($expected); $object->setDash($expected);
$this->assertEquals($expected, $object->getDash()); $this->assertEquals($expected, $object->getDash());
@ -132,7 +132,7 @@ class LineTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetBeginArrow() public function testSetGetBeginArrow()
{ {
$expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK; $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK;
$object = new Line(); $object = new Line();
$object->setBeginArrow($expected); $object->setBeginArrow($expected);
$this->assertEquals($expected, $object->getBeginArrow()); $this->assertEquals($expected, $object->getBeginArrow());
@ -143,7 +143,7 @@ class LineTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetEndArrow() public function testSetGetEndArrow()
{ {
$expected=\PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC; $expected = \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_CLASSIC;
$object = new Line(); $object = new Line();
$object->setEndArrow($expected); $object->setEndArrow($expected);
$this->assertEquals($expected, $object->getEndArrow()); $this->assertEquals($expected, $object->getEndArrow());

View File

@ -34,19 +34,19 @@ class NumberingLevelTest extends \PHPUnit_Framework_TestCase
$object = new NumberingLevel(); $object = new NumberingLevel();
$attributes = array( $attributes = array(
'level' => 1, 'level' => 1,
'start' => 1, 'start' => 1,
'format' => 'decimal', 'format' => 'decimal',
'restart' => 1, 'restart' => 1,
'pStyle' => 'pStyle', 'pStyle' => 'pStyle',
'suffix' => 'space', 'suffix' => 'space',
'text' => '%1.', 'text' => '%1.',
'align' => 'left', 'align' => 'left',
'left' => 360, 'left' => 360,
'hanging' => 360, 'hanging' => 360,
'tabPos' => 360, 'tabPos' => 360,
'font' => 'Arial', 'font' => 'Arial',
'hint' => 'default', 'hint' => 'default',
); );
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";

View File

@ -33,8 +33,8 @@ class NumberingTest extends \PHPUnit_Framework_TestCase
{ {
$this->object = new Numbering(); $this->object = new Numbering();
$this->properties = array( $this->properties = array(
'numId' => array(null, 1), 'numId' => array(null, 1),
'type' => array(null, 'singleLevel'), 'type' => array(null, 'singleLevel'),
); );
foreach ($this->properties as $property => $value) { foreach ($this->properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;

View File

@ -45,16 +45,16 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$object = new Paragraph(); $object = new Paragraph();
$attributes = array( $attributes = array(
'widowControl' => true, 'widowControl' => true,
'keepNext' => false, 'keepNext' => false,
'keepLines' => false, 'keepLines' => false,
'pageBreakBefore' => false, 'pageBreakBefore' => false,
); );
foreach ($attributes as $key => $default) { foreach ($attributes as $key => $default) {
$get = "get{$key}"; $get = "get{$key}";
$object->setStyleValue("$key", null); $object->setStyleValue($key, null);
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
$object->setStyleValue("$key", ''); $object->setStyleValue($key, '');
$this->assertEquals($default, $object->$get()); $this->assertEquals($default, $object->$get());
} }
} }
@ -67,31 +67,31 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$object = new Paragraph(); $object = new Paragraph();
$attributes = array( $attributes = array(
'align' => 'justify', 'align' => 'justify',
'spaceAfter' => 240, 'spaceAfter' => 240,
'spaceBefore' => 240, 'spaceBefore' => 240,
'indent' => 1, 'indent' => 1,
'hanging' => 1, 'hanging' => 1,
'spacing' => 120, 'spacing' => 120,
'basedOn' => 'Normal', 'basedOn' => 'Normal',
'next' => 'Normal', 'next' => 'Normal',
'numStyle' => 'numStyle', 'numStyle' => 'numStyle',
'numLevel' => 1, 'numLevel' => 1,
'widowControl' => false, 'widowControl' => false,
'keepNext' => true, 'keepNext' => true,
'keepLines' => true, 'keepLines' => true,
'pageBreakBefore' => true, 'pageBreakBefore' => true,
); );
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$get = "get{$key}"; $get = "get{$key}";
$object->setStyleValue("$key", $value); $object->setStyleValue("$key", $value);
if ($key == 'align') { if ('align' == $key) {
if ($value == 'justify') { if ('justify' == $value) {
$value = 'both'; $value = 'both';
} }
} elseif ($key == 'indent' || $key == 'hanging') { } elseif ('indent' == $key || 'hanging' == $key) {
$value = $value * 720; $value = $value * 720;
} elseif ($key == 'spacing') { } elseif ('spacing' == $key) {
$value += 240; $value += 240;
} }
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
@ -131,9 +131,7 @@ class ParagraphTest extends \PHPUnit_Framework_TestCase
$section = $phpWord->addSection(); $section = $phpWord->addSection();
// Test style array // Test style array
$text = $section->addText('This is a test', array(), array( $text = $section->addText(htmlspecialchars('This is a test', ENT_COMPAT, 'UTF-8'), array(), array('line-height' => 2.0));
'line-height' => 2.0
));
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing'); $element = $doc->getElement('/w:document/w:body/w:p/w:pPr/w:spacing');

View File

@ -35,8 +35,8 @@ class RowTest extends \PHPUnit_Framework_TestCase
$object = new Row(); $object = new Row();
$properties = array( $properties = array(
'tblHeader' => true, 'tblHeader' => true,
'cantSplit' => false, 'cantSplit' => false,
'exactHeight' => true, 'exactHeight' => true,
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
@ -63,8 +63,8 @@ class RowTest extends \PHPUnit_Framework_TestCase
$object = new Row(); $object = new Row();
$properties = array( $properties = array(
'tblHeader' => 'a', 'tblHeader' => 'a',
'cantSplit' => 'b', 'cantSplit' => 'b',
'exactHeight' => 'c', 'exactHeight' => 'c',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {

View File

@ -64,8 +64,15 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($iVal, $oSettings->getHeaderHeight()); $this->assertEquals($iVal, $oSettings->getHeaderHeight());
$oSettings->setSettingValue('lineNumbering', array()); $oSettings->setSettingValue('lineNumbering', array());
$oSettings->setSettingValue('lineNumbering', array('start' => 1, 'increment' => 1, $oSettings->setSettingValue(
'distance' => 240, 'restart' => 'newPage')); 'lineNumbering',
array(
'start' => 1,
'increment' => 1,
'distance' => 240,
'restart' => 'newPage',
)
);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering());
$oSettings->setSettingValue('lineNumbering', null); $oSettings->setSettingValue('lineNumbering', null);

View File

@ -34,9 +34,9 @@ class SpacingTest extends \PHPUnit_Framework_TestCase
$object = new Spacing(); $object = new Spacing();
$properties = array( $properties = array(
'before' => array(null, 10), 'before' => array(null, 10),
'after' => array(null, 10), 'after' => array(null, 10),
'line' => array(null, 10), 'line' => array(null, 10),
'rule' => array('auto', 'exact'), 'rule' => array('auto', 'exact'),
); );
foreach ($properties as $property => $value) { foreach ($properties as $property => $value) {
list($default, $expected) = $value; list($default, $expected) = $value;

View File

@ -57,26 +57,26 @@ class TableTest extends \PHPUnit_Framework_TestCase
$object = new Table(); $object = new Table();
$attributes = array( $attributes = array(
'bgColor' => 'FF0000', 'bgColor' => 'FF0000',
'borderTopSize' => 4, 'borderTopSize' => 4,
'borderTopColor' => 'FF0000', 'borderTopColor' => 'FF0000',
'borderLeftSize' => 4, 'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000', 'borderLeftColor' => 'FF0000',
'borderRightSize' => 4, 'borderRightSize' => 4,
'borderRightColor' => 'FF0000', 'borderRightColor' => 'FF0000',
'borderBottomSize' => 4, 'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000', 'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4, 'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000', 'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4, 'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000', 'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240, 'cellMarginTop' => 240,
'cellMarginLeft' => 240, 'cellMarginLeft' => 240,
'cellMarginRight' => 240, 'cellMarginRight' => 240,
'cellMarginBottom' => 240, 'cellMarginBottom' => 240,
'align' => 'center', 'align' => 'center',
'width' => 100, 'width' => 100,
'unit' => 'pct', 'unit' => 'pct',
); );
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";
@ -162,14 +162,8 @@ class TableTest extends \PHPUnit_Framework_TestCase
$object->setStyleValue('cellMargin', 240); $object->setStyleValue('cellMargin', 240);
$object->setStyleValue('borderColor', '999999'); $object->setStyleValue('borderColor', '999999');
$this->assertEquals( $this->assertEquals(array(120, 120, 120, 120, 120, 120), $object->getBorderSize());
array(120, 120, 120, 120, 120, 120), $this->assertEquals(array(240, 240, 240, 240), $object->getCellMargin());
$object->getBorderSize()
);
$this->assertEquals(
array(240, 240, 240, 240),
$object->getCellMargin()
);
$this->assertEquals( $this->assertEquals(
array('999999', '999999', '999999', '999999', '999999', '999999'), array('999999', '999999', '999999', '999999', '999999', '999999'),
$object->getBorderColor() $object->getBorderColor()

View File

@ -33,25 +33,25 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
public function testSetGetNormal() public function testSetGetNormal()
{ {
$object = new TextBox(); $object = new TextBox();
$properties = array( $properties = array(
'width' => 200, 'width' => 200,
'height' => 200, 'height' => 200,
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240,
'wrappingStyle' => 'inline', 'wrappingStyle' => 'inline',
'positioning' => 'absolute', 'positioning' => 'absolute',
'posHorizontal' => 'center', 'posHorizontal' => 'center',
'posVertical' => 'top', 'posVertical' => 'top',
'posHorizontalRel' => 'margin', 'posHorizontalRel' => 'margin',
'posVerticalRel' => 'page', 'posVerticalRel' => 'page',
'innerMarginTop' => '5', 'innerMarginTop' => '5',
'innerMarginRight' => '5', 'innerMarginRight' => '5',
'innerMarginBottom' => '5', 'innerMarginBottom' => '5',
'innerMarginLeft' => '5', 'innerMarginLeft' => '5',
'borderSize' => '2', 'borderSize' => '2',
'borderColor' => 'red' 'borderColor' => 'red',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$set = "set{$key}"; $set = "set{$key}";
@ -60,32 +60,32 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
} }
} }
/** /**
* Test setStyleValue method * Test setStyleValue method
*/ */
public function testSetStyleValue() public function testSetStyleValue()
{ {
$object = new TextBox(); $object = new TextBox();
$properties = array( $properties = array(
'width' => 200, 'width' => 200,
'height' => 200, 'height' => 200,
'align' => 'left', 'align' => 'left',
'marginTop' => 240, 'marginTop' => 240,
'marginLeft' => 240, 'marginLeft' => 240,
'wrappingStyle' => 'inline', 'wrappingStyle' => 'inline',
'positioning' => 'absolute', 'positioning' => 'absolute',
'posHorizontal' => 'center', 'posHorizontal' => 'center',
'posVertical' => 'top', 'posVertical' => 'top',
'posHorizontalRel' => 'margin', 'posHorizontalRel' => 'margin',
'posVerticalRel' => 'page', 'posVerticalRel' => 'page',
'innerMarginTop' => '5', 'innerMarginTop' => '5',
'innerMarginRight' => '5', 'innerMarginRight' => '5',
'innerMarginBottom' => '5', 'innerMarginBottom' => '5',
'innerMarginLeft' => '5', 'innerMarginLeft' => '5',
'borderSize' => '2', 'borderSize' => '2',
'borderColor' => 'red' 'borderColor' => 'red',
); );
foreach ($properties as $key => $value) { foreach ($properties as $key => $value) {
$get = "get{$key}"; $get = "get{$key}";
@ -93,7 +93,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($value, $object->$get()); $this->assertEquals($value, $object->$get());
} }
} }
/** /**
* Test setWrappingStyle exception * Test setWrappingStyle exception
* *
@ -104,35 +104,35 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
$object = new TextBox(); $object = new TextBox();
$object->setWrappingStyle('foo'); $object->setWrappingStyle('foo');
} }
/** /**
* Test set/get width * Test set/get width
*/ */
public function testSetGetWidth() public function testSetGetWidth()
{ {
$expected=200; $expected = 200;
$object = new TextBox(); $object = new TextBox();
$object->setWidth($expected); $object->setWidth($expected);
$this->assertEquals($expected, $object->getWidth()); $this->assertEquals($expected, $object->getWidth());
} }
/** /**
* Test set/get height * Test set/get height
*/ */
public function testSetGetHeight() public function testSetGetHeight()
{ {
$expected=200; $expected = 200;
$object = new TextBox(); $object = new TextBox();
$object->setHeight($expected); $object->setHeight($expected);
$this->assertEquals($expected, $object->getHeight()); $this->assertEquals($expected, $object->getHeight());
} }
/** /**
* Test set/get height * Test set/get height
*/ */
public function testSetGetAlign() public function testSetGetAlign()
{ {
$expected='left'; $expected = 'left';
$object = new TextBox(); $object = new TextBox();
$object->setAlign($expected); $object->setAlign($expected);
$this->assertEquals($expected, $object->getAlign()); $this->assertEquals($expected, $object->getAlign());
@ -143,28 +143,29 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetMarginTop() public function testSetGetMarginTop()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setMarginTop($expected); $object->setMarginTop($expected);
$this->assertEquals($expected, $object->getMarginTop()); $this->assertEquals($expected, $object->getMarginTop());
} }
/** /**
* Test set/get marginLeft * Test set/get marginLeft
*/ */
public function testSetGetMarginLeft() public function testSetGetMarginLeft()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setMarginLeft($expected); $object->setMarginLeft($expected);
$this->assertEquals($expected, $object->getMarginLeft()); $this->assertEquals($expected, $object->getMarginLeft());
} }
/** /**
* Test set/get innerMarginTop * Test set/get innerMarginTop
*/ */
public function testSetGetInnerMarginTop() public function testSetGetInnerMarginTop()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setInnerMarginTop($expected); $object->setInnerMarginTop($expected);
$this->assertEquals($expected, $object->getInnerMarginTop()); $this->assertEquals($expected, $object->getInnerMarginTop());
@ -175,96 +176,96 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetWrappingStyle() public function testSetGetWrappingStyle()
{ {
$expected='inline'; $expected = 'inline';
$object = new TextBox(); $object = new TextBox();
$object->setWrappingStyle($expected); $object->setWrappingStyle($expected);
$this->assertEquals($expected, $object->getWrappingStyle()); $this->assertEquals($expected, $object->getWrappingStyle());
} }
/** /**
* Test set/get positioning * Test set/get positioning
*/ */
public function testSetGetPositioning() public function testSetGetPositioning()
{ {
$expected='absolute'; $expected = 'absolute';
$object = new TextBox(); $object = new TextBox();
$object->setPositioning($expected); $object->setPositioning($expected);
$this->assertEquals($expected, $object->getPositioning()); $this->assertEquals($expected, $object->getPositioning());
} }
/** /**
* Test set/get posHorizontal * Test set/get posHorizontal
*/ */
public function testSetGetPosHorizontal() public function testSetGetPosHorizontal()
{ {
$expected='center'; $expected = 'center';
$object = new TextBox(); $object = new TextBox();
$object->setPosHorizontal($expected); $object->setPosHorizontal($expected);
$this->assertEquals($expected, $object->getPosHorizontal()); $this->assertEquals($expected, $object->getPosHorizontal());
} }
/** /**
* Test set/get posVertical * Test set/get posVertical
*/ */
public function testSetGetPosVertical() public function testSetGetPosVertical()
{ {
$expected='top'; $expected = 'top';
$object = new TextBox(); $object = new TextBox();
$object->setPosVertical($expected); $object->setPosVertical($expected);
$this->assertEquals($expected, $object->getPosVertical()); $this->assertEquals($expected, $object->getPosVertical());
} }
/** /**
* Test set/get posHorizontalRel * Test set/get posHorizontalRel
*/ */
public function testSetGetPosHorizontalRel() public function testSetGetPosHorizontalRel()
{ {
$expected='margin'; $expected = 'margin';
$object = new TextBox(); $object = new TextBox();
$object->setPosHorizontalRel($expected); $object->setPosHorizontalRel($expected);
$this->assertEquals($expected, $object->getPosHorizontalRel()); $this->assertEquals($expected, $object->getPosHorizontalRel());
} }
/** /**
* Test set/get posVerticalRel * Test set/get posVerticalRel
*/ */
public function testSetGetPosVerticalRel() public function testSetGetPosVerticalRel()
{ {
$expected='page'; $expected = 'page';
$object = new TextBox(); $object = new TextBox();
$object->setPosVerticalRel($expected); $object->setPosVerticalRel($expected);
$this->assertEquals($expected, $object->getPosVerticalRel()); $this->assertEquals($expected, $object->getPosVerticalRel());
} }
/** /**
* Test set/get innerMarginRight * Test set/get innerMarginRight
*/ */
public function testSetGetInnerMarginRight() public function testSetGetInnerMarginRight()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setInnerMarginRight($expected); $object->setInnerMarginRight($expected);
$this->assertEquals($expected, $object->getInnerMarginRight()); $this->assertEquals($expected, $object->getInnerMarginRight());
} }
/** /**
* Test set/get innerMarginBottom * Test set/get innerMarginBottom
*/ */
public function testSetGetInnerMarginBottom() public function testSetGetInnerMarginBottom()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setInnerMarginBottom($expected); $object->setInnerMarginBottom($expected);
$this->assertEquals($expected, $object->getInnerMarginBottom()); $this->assertEquals($expected, $object->getInnerMarginBottom());
} }
/** /**
* Test set/get innerMarginLeft * Test set/get innerMarginLeft
*/ */
public function testSetGetInnerMarginLeft() public function testSetGetInnerMarginLeft()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setInnerMarginLeft($expected); $object->setInnerMarginLeft($expected);
$this->assertEquals($expected, $object->getInnerMarginLeft()); $this->assertEquals($expected, $object->getInnerMarginLeft());
@ -275,7 +276,7 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetInnerMargin() public function testSetGetInnerMargin()
{ {
$expected=5; $expected = 5;
$object = new TextBox(); $object = new TextBox();
$object->setInnerMargin($expected); $object->setInnerMargin($expected);
$this->assertEquals(array($expected, $expected, $expected, $expected), $object->getInnerMargin()); $this->assertEquals(array($expected, $expected, $expected, $expected), $object->getInnerMargin());
@ -286,18 +287,18 @@ class TextBoxTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetBorderSize() public function testSetGetBorderSize()
{ {
$expected=2; $expected = 2;
$object = new TextBox(); $object = new TextBox();
$object->setBorderSize($expected); $object->setBorderSize($expected);
$this->assertEquals($expected, $object->getBorderSize()); $this->assertEquals($expected, $object->getBorderSize());
} }
/** /**
* Test set/get borderColor * Test set/get borderColor
*/ */
public function testSetGetBorderColor() public function testSetGetBorderColor()
{ {
$expected='red'; $expected = 'red';
$object = new TextBox(); $object = new TextBox();
$object->setBorderColor($expected); $object->setBorderColor($expected);
$this->assertEquals($expected, $object->getBorderColor()); $this->assertEquals($expected, $object->getBorderColor());

View File

@ -86,6 +86,6 @@ class StyleTest extends \PHPUnit_Framework_TestCase
Style::setDefaultParagraphStyle($paragraph); Style::setDefaultParagraphStyle($paragraph);
$this->assertInstanceOf("PhpOffice\\PhpWord\\Style\\Paragraph", Style::getStyle('Normal')); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', Style::getStyle('Normal'));
} }
} }

View File

@ -51,14 +51,14 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase
$templateZip = new \ZipArchive(); $templateZip = new \ZipArchive();
$templateZip->open($templateFqfn); $templateZip->open($templateFqfn);
$templateXml = $templateZip->getFromName('word/document.xml'); $templateXml = $templateZip->getFromName('word/document.xml');
if ($templateZip->close() === false) { if (false === $templateZip->close()) {
throw new \Exception("Could not close zip file \"{$templateZip}\"."); throw new \Exception("Could not close zip file \"{$templateZip}\".");
} }
$documentZip = new \ZipArchive(); $documentZip = new \ZipArchive();
$documentZip->open($documentFqfn); $documentZip->open($documentFqfn);
$documentXml = $documentZip->getFromName('word/document.xml'); $documentXml = $documentZip->getFromName('word/document.xml');
if ($documentZip->close() === false) { if (false === $documentZip->close()) {
throw new \Exception("Could not close zip file \"{$documentZip}\"."); 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) 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 = new \ZipArchive();
$actualDocumentZip->open($actualDocumentFqfn); $actualDocumentZip->open($actualDocumentFqfn);
$actualDocumentXml = $actualDocumentZip->getFromName('word/document.xml'); $actualDocumentXml = $actualDocumentZip->getFromName('word/document.xml');
if ($actualDocumentZip->close() === false) { if (false === $actualDocumentZip->close()) {
throw new \Exception("Could not close zip file \"{$actualDocumentFqfn}\"."); throw new \Exception("Could not close zip file \"{$actualDocumentFqfn}\".");
} }
$expectedDocumentZip = new \ZipArchive(); $expectedDocumentZip = new \ZipArchive();
$expectedDocumentZip->open($expectedDocumentFqfn); $expectedDocumentZip->open($expectedDocumentFqfn);
$expectedDocumentXml = $expectedDocumentZip->getFromName('word/document.xml'); $expectedDocumentXml = $expectedDocumentZip->getFromName('word/document.xml');
if ($expectedDocumentZip->close() === false) { if (false === $expectedDocumentZip->close()) {
throw new \Exception("Could not close zip file \"{$expectedDocumentFqfn}\"."); 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. * We have to use error control below, because \XSLTProcessor::setParameter omits warning on failure.
* This warning fails the test. * 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'; $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->cloneRow('userId', 1);
$templateProcessor->setValue('userId#1', 'Test'); $templateProcessor->setValue('userId#1', htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$templateProcessor->saveAs($docName); $templateProcessor->saveAs($docName);
$docFound = file_exists($docName); $docFound = file_exists($docName);
unlink($docName); unlink($docName);
@ -181,9 +181,9 @@ final class TemplateProcessorTest extends \PHPUnit_Framework_TestCase
); );
$docName = 'header-footer-test-result.docx'; $docName = 'header-footer-test-result.docx';
$templateProcessor->setValue('headerValue', 'Header Value'); $templateProcessor->setValue('headerValue', htmlspecialchars('Header Value', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('documentContent', 'Document text.'); $templateProcessor->setValue('documentContent', htmlspecialchars('Document text.', ENT_COMPAT, 'UTF-8'));
$templateProcessor->setValue('footerValue', 'Footer Value'); $templateProcessor->setValue('footerValue', htmlspecialchars('Footer Value', ENT_COMPAT, 'UTF-8'));
$templateProcessor->saveAs($docName); $templateProcessor->saveAs($docName);
$docFound = file_exists($docName); $docFound = file_exists($docName);
unlink($docName); unlink($docName);

View File

@ -17,8 +17,8 @@
namespace PhpOffice\PhpWord\Tests\Writer\HTML; namespace PhpOffice\PhpWord\Tests\Writer\HTML;
use PhpOffice\PhpWord\Element\Text as TextElement; use PhpOffice\PhpWord\Element\Text as TextElement;
use PhpOffice\PhpWord\Writer\HTML;
use PhpOffice\PhpWord\Writer\HTML\Element\Text; use PhpOffice\PhpWord\Writer\HTML\Element\Text;
use PhpOffice\PhpWord\Writer\HTML;
/** /**
* Test class for PhpOffice\PhpWord\Writer\HTML\Element subnamespace * Test class for PhpOffice\PhpWord\Writer\HTML\Element subnamespace
@ -46,11 +46,11 @@ class ElementTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteTextElement() public function testWriteTextElement()
{ {
$object = new Text(new HTML(), new TextElement('A')); $object = new Text(new HTML(), new TextElement(htmlspecialchars('A', ENT_COMPAT, 'UTF-8')));
$object->setOpeningText('-'); $object->setOpeningText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8'));
$object->setClosingText('-'); $object->setClosingText(htmlspecialchars('-', ENT_COMPAT, 'UTF-8'));
$object->setWithoutP(true); $object->setWithoutP(true);
$this->assertEquals('-A-', $object->write()); $this->assertEquals(htmlspecialchars('-A-', ENT_COMPAT, 'UTF-8'), $object->write());
} }
} }

View File

@ -53,29 +53,34 @@ class HTMLTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSave() 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'; $archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg';
$gdImage = 'http://php.net/images/logos/php-med-trans-light.gif'; $gdImage = 'http://php.net/images/logos/php-med-trans-light.gif';
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . "/../_files/temp.html"; $file = __DIR__ . '/../_files/temp.html';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$docProps = $phpWord->getDocInfo(); $docProps = $phpWord->getDocInfo();
$docProps->setTitle('HTML Test'); $docProps->setTitle(htmlspecialchars('HTML Test', ENT_COMPAT, 'UTF-8'));
$phpWord->addTitleStyle(1, array('bold' => true)); $phpWord->addTitleStyle(1, array('bold' => true));
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, $phpWord->addFontStyle(
'color' => 'FF0000', 'fgColor' => 'FF0000')); 'Font',
array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000')
);
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center', 'spaceAfter' => 20, 'spaceBefore' => 20)); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center', 'spaceAfter' => 20, 'spaceBefore' => 20));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
$section->addTextBreak(); $section->addTextBreak();
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true, 'subscript' => true)); $section->addText(
$section->addLink('http://test.com'); htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'),
$section->addTitle('Test', 1); 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->addPageBreak();
$section->addListItem('Test'); $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addImage($localImage); $section->addImage($localImage);
$section->addImage($archiveImage); $section->addImage($archiveImage);
$section->addImage($gdImage); $section->addImage($gdImage);
@ -86,24 +91,27 @@ class HTMLTest extends \PHPUnit_Framework_TestCase
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(array('align' => 'center')); $textrun = $section->addTextRun(array('align' => 'center'));
$textrun->addText('Test 3'); $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$textrun->addTextBreak(); $textrun->addTextBreak();
$textrun = $section->addTextRun('Paragraph'); $textrun = $section->addTextRun('Paragraph');
$textrun->addLink('http://test.com'); $textrun->addLink('https://github.com/PHPOffice/PHPWord');
$textrun->addImage($localImage); $textrun->addImage($localImage);
$textrun->addFootnote()->addText('Footnote'); $textrun->addFootnote()->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
$textrun->addEndnote()->addText('Endnote'); $textrun->addEndnote()->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$table = $section->addTable(); $table = $section->addTable();
$cell = $table->addRow()->addCell(); $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->addTextRun();
$cell->addLink('http://test.com'); $cell->addLink('https://github.com/PHPOffice/PHPWord');
$cell->addTextBreak(); $cell->addTextBreak();
$cell->addListItem('Test'); $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addImage($localImage); $cell->addImage($localImage);
$cell->addObject($objectSrc); $cell->addObject($objectSrc);
$cell->addFootnote(); $cell->addFootnote();

View File

@ -33,26 +33,20 @@ class AbstractPartTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetParentWriter() public function testSetGetParentWriter()
{ {
$object = $this->getMockForAbstractClass( $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart');
'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'
);
$object->setParentWriter(new ODText()); $object->setParentWriter(new ODText());
$this->assertEquals( $this->assertEquals(new ODText(), $object->getParentWriter());
new ODText(),
$object->getParentWriter()
);
} }
/** /**
* covers ::getParentWriter * covers ::getParentWriter
*
* @expectedException Exception * @expectedException Exception
* @expectedExceptionMessage No parent WriterInterface assigned. * @expectedExceptionMessage No parent WriterInterface assigned.
*/ */
public function testSetGetParentWriterNull() public function testSetGetParentWriterNull()
{ {
$object = $this->getMockForAbstractClass( $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart');
'PhpOffice\\PhpWord\\Writer\\ODText\\Part\\AbstractPart'
);
$object->getParentWriter(); $object->getParentWriter();
} }
} }

View File

@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\ODText\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
use PhpOffice\PhpWord\Writer\ODText\Part\Content;
/** /**
* Test class for 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() public function testWriteContent()
{ {
$imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
$expected = 'Expected'; $expected = 'Expected';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
@ -56,41 +55,41 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$phpWord->addTableStyle('tblStyle', array('width' => 100)); $phpWord->addTableStyle('tblStyle', array('width' => 100));
$section = $phpWord->addSection(array('colsNum' => 2)); $section = $phpWord->addSection(array('colsNum' => 2));
$section->addText($expected); $section->addText(htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
$section->addText('Test font style', 'Font'); $section->addText(htmlspecialchars('Test font style', ENT_COMPAT, 'UTF-8'), 'Font');
$section->addText('Test paragraph style', null, 'Paragraph'); $section->addText(htmlspecialchars('Test paragraph style', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
$section->addLink('http://test.com', 'Test link'); $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$section->addTitle('Test title', 1); $section->addTitle(htmlspecialchars('Test title', ENT_COMPAT, 'UTF-8'), 1);
$section->addTextBreak(); $section->addTextBreak();
$section->addPageBreak(); $section->addPageBreak();
$section->addListItem('Test list item'); $section->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc, array('width' => 50)); $section->addImage($imageSrc, array('width' => 50));
$section->addObject($objectSrc); $section->addObject($objectSrc);
$section->addTOC(); $section->addTOC();
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText('Test text run'); $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable(array('width' => 50)); $table = $section->addTable(array('width' => 50));
$cell = $table->addRow()->addCell(); $cell = $table->addRow()->addCell();
$cell = $table->addRow()->addCell(); $cell = $table->addRow()->addCell();
$cell->addText('Test'); $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addLink('http://test.com', 'Test link'); $cell->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$cell->addTextBreak(); $cell->addTextBreak();
$cell->addListItem('Test list item'); $cell->addListItem(htmlspecialchars('Test list item', ENT_COMPAT, 'UTF-8'));
$cell->addImage($imageSrc); $cell->addImage($imageSrc);
$cell->addObject($objectSrc); $cell->addObject($objectSrc);
$textrun = $cell->addTextRun(); $textrun = $cell->addTextRun();
$textrun->addText('Test text run'); $textrun->addText(htmlspecialchars('Test text run', ENT_COMPAT, 'UTF-8'));
$footer = $section->addFooter(); $footer = $section->addFooter();
$footer->addPreserveText('{PAGE}'); $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'));
$table = $section->addTable('tblStyle')->addRow()->addCell(); $table = $section->addTable('tblStyle')->addRow()->addCell();
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); $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); $this->assertEquals($expected, $doc->getElement($element, 'content.xml')->nodeValue);
} }
@ -104,7 +103,7 @@ class ContentTest extends \PHPUnit_Framework_TestCase
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText'); $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')); $this->assertTrue($doc->elementExists($element, 'content.xml'));
} }
} }

View File

@ -65,28 +65,28 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSave() public function testSave()
{ {
$imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; $imageSrc = __DIR__ . '/../_files/images/PhpWord.png';
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . "/../_files/temp.odt"; $file = __DIR__ . '/../_files/temp.odt';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11)); $phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1', 'Font'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font');
$section->addTextBreak(); $section->addTextBreak();
$section->addText('Test 2', null, 'Paragraph'); $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), null, 'Paragraph');
$section->addLink('http://test.com'); $section->addLink('https://github.com/PHPOffice/PHPWord');
$section->addTitle('Test', 1); $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
$section->addPageBreak(); $section->addPageBreak();
$section->addTable()->addRow()->addCell()->addText('Test'); $section->addTable()->addRow()->addCell()->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addListItem('Test'); $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc); $section->addImage($imageSrc);
$section->addObject($objectSrc); $section->addObject($objectSrc);
$section->addTOC(); $section->addTOC();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText('Test 3'); $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$writer = new ODText($phpWord); $writer = new ODText($phpWord);
$writer->save($file); $writer->save($file);
@ -104,7 +104,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test'); $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$writer = new ODText($phpWord); $writer = new ODText($phpWord);
$writer->save('php://output'); $writer->save('php://output');
} }
@ -136,10 +136,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetUseDiskCachingException() public function testSetUseDiskCachingException()
{ {
$dir = join( $dir = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'foo'));
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_BASE_DIR, 'foo')
);
$object = new ODText(); $object = new ODText();
$object->setUseDiskCaching(true, $dir); $object->setUseDiskCaching(true, $dir);

View File

@ -33,11 +33,11 @@ class DomPDFTest extends \PHPUnit_Framework_TestCase
public function testConstruct() public function testConstruct()
{ {
define('DOMPDF_ENABLE_AUTOLOAD', false); define('DOMPDF_ENABLE_AUTOLOAD', false);
$file = __DIR__ . "/../../_files/dompdf.pdf"; $file = __DIR__ . '/../../_files/dompdf.pdf';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
$rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');

View File

@ -32,11 +32,11 @@ class MPDFTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$file = __DIR__ . "/../../_files/mpdf.pdf"; $file = __DIR__ . '/../../_files/mpdf.pdf';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
$rendererName = Settings::PDF_RENDERER_MPDF; $rendererName = Settings::PDF_RENDERER_MPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf'); $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/mpdf/mpdf');

View File

@ -32,11 +32,11 @@ class TCPDFTest extends \PHPUnit_Framework_TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$file = __DIR__ . "/../../_files/tcpdf.pdf"; $file = __DIR__ . '/../../_files/tcpdf.pdf';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'));
$rendererName = Settings::PDF_RENDERER_TCPDF; $rendererName = Settings::PDF_RENDERER_TCPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf'); $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/tecnick.com/tcpdf');

View File

@ -33,7 +33,7 @@ class PDFTest extends \PHPUnit_Framework_TestCase
public function testConstruct() public function testConstruct()
{ {
define('DOMPDF_ENABLE_AUTOLOAD', false); define('DOMPDF_ENABLE_AUTOLOAD', false);
$file = __DIR__ . "/../_files/temp.pdf"; $file = __DIR__ . '/../_files/temp.pdf';
$rendererName = Settings::PDF_RENDERER_DOMPDF; $rendererName = Settings::PDF_RENDERER_DOMPDF;
$rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf'); $rendererLibraryPath = realpath(PHPWORD_TESTS_BASE_DIR . '/../vendor/dompdf/dompdf');

View File

@ -53,20 +53,22 @@ class RTFTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSave() public function testSave()
{ {
$imageSrc = __DIR__ . "/../_files/images/PhpWord.png"; $imageSrc = __DIR__ . '/../_files/images/PhpWord.png';
$objectSrc = __DIR__ . "/../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . "/../_files/temp.rtf"; $file = __DIR__ . '/../_files/temp.rtf';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, $phpWord->addFontStyle(
'color' => 'FF0000', 'fgColor' => '00FF00')); 'Font',
array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => '00FF00')
);
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test 1', 'Font', 'Paragraph'); $section->addText(htmlspecialchars('Test 1', ENT_COMPAT, 'UTF-8'), 'Font', 'Paragraph');
$section->addTextBreak(); $section->addTextBreak();
$section->addText('Test 2', array('name' => 'Tahoma', 'bold' => true, 'italic' => true)); $section->addText(htmlspecialchars('Test 2', ENT_COMPAT, 'UTF-8'), array('name' => 'Tahoma', 'bold' => true, 'italic' => true));
$section->addLink('http://test.com'); $section->addLink('https://github.com/PHPOffice/PHPWord');
$section->addTitle('Test', 1); $section->addTitle(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), 1);
$section->addPageBreak(); $section->addPageBreak();
// Rowspan // Rowspan
@ -78,13 +80,13 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$cell = $section->addTable()->addRow()->addCell(); $cell = $section->addTable()->addRow()->addCell();
$cell->addTable()->addRow()->addCell(); $cell->addTable()->addRow()->addCell();
$section->addListItem('Test'); $section->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$section->addImage($imageSrc); $section->addImage($imageSrc);
$section->addObject($objectSrc); $section->addObject($objectSrc);
$section->addTOC(); $section->addTOC();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText('Test 3'); $textrun->addText(htmlspecialchars('Test 3', ENT_COMPAT, 'UTF-8'));
$textrun->addTextBreak(); $textrun->addTextBreak();
$writer = new RTF($phpWord); $writer = new RTF($phpWord);
$writer->save($file); $writer->save($file);
@ -103,7 +105,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test'); $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$writer = new RTF($phpWord); $writer = new RTF($phpWord);
$writer->save('php://output'); $writer->save('php://output');
} }

View File

@ -41,7 +41,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$elements = array( $elements = array(
'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun',
'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC', 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC',
'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT' 'Field', 'Line', 'Shape', 'Chart', 'FormField', 'SDT',
); );
foreach ($elements as $element) { foreach ($elements as $element) {
$objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $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)); $section->addLine(array('width' => 1000, 'height' => 1000, 'positioning' => 'absolute', 'flip' => true));
$doc = TestHelperDOCX::getDocument($phpWord); $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)); $this->assertTrue($doc->elementExists($element));
} }
@ -81,8 +81,8 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addShape( $section->addShape(
'arc', 'arc',
array( array(
'points' => '-90 20', 'points' => '-90 20',
'frame' => array('width' => 120, 'height' => 120), 'frame' => array('width' => 120, 'height' => 120),
'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'), 'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'),
) )
); );
@ -91,9 +91,14 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addShape( $section->addShape(
'curve', 'curve',
array( array(
'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow', 'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow',
'outline' => array('color' => '#66cc00', 'weight' => 2, 'dash' => 'dash', 'outline' => array(
'startArrow' => 'diamond', 'endArrow' => 'block'), 'color' => '#66cc00',
'weight' => 2,
'dash' => 'dash',
'startArrow' => 'diamond',
'endArrow' => 'block',
),
) )
); );
@ -101,9 +106,15 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addShape( $section->addShape(
'line', 'line',
array( array(
'points' => '1,1 150,30', 'points' => '1,1 150,30',
'outline' => array('color' => '#cc00ff', 'line' => 'thickThin', 'weight' => 3, 'outline' => array(
'startArrow' => 'oval', 'endArrow' => 'classic', 'endCap' => 'round'), 'color' => '#cc00ff',
'line' => 'thickThin',
'weight' => 3,
'startArrow' => 'oval',
'endArrow' => 'classic',
'endCap' => 'round',
),
) )
); );
@ -111,9 +122,13 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addShape( $section->addShape(
'polyline', 'polyline',
array( array(
'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50', 'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50',
'outline' => array('color' => '#cc6666', 'weight' => 2, 'outline' => array(
'startArrow' => 'none', 'endArrow' => 'classic'), 'color' => '#cc6666',
'weight' => 2,
'startArrow' => 'none',
'endArrow' => 'classic',
),
) )
); );
@ -122,10 +137,10 @@ class ElementTest extends \PHPUnit_Framework_TestCase
'rect', 'rect',
array( array(
'roundness' => 0.2, 'roundness' => 0.2,
'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1), 'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1),
'fill' => array('color' => '#FFCC33'), 'fill' => array('color' => '#FFCC33'),
'outline' => array('color' => '#990000', 'weight' => 1), 'outline' => array('color' => '#990000', 'weight' => 1),
'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'), 'shadow' => array('color' => '#EEEEEE', 'offset' => '3pt,3pt'),
) )
); );
@ -133,9 +148,9 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addShape( $section->addShape(
'oval', 'oval',
array( array(
'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1), 'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1),
'fill' => array('color' => '#33CC99'), 'fill' => array('color' => '#33CC99'),
'outline' => array('color' => '#333333', 'weight' => 2), 'outline' => array('color' => '#333333', 'weight' => 2),
'extrusion' => array('type' => 'perspective', 'color' => '#EEEEEE'), 'extrusion' => array('type' => 'perspective', 'color' => '#EEEEEE'),
) )
); );
@ -187,11 +202,13 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$section->addFormField('textinput')->setName('MyTextBox'); $section->addFormField('textinput')->setName('MyTextBox');
$section->addFormField('checkbox')->setDefault(true)->setValue('Your name'); $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); $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:textInput'));
$this->assertTrue($doc->elementExists($path . '/w:checkBox')); $this->assertTrue($doc->elementExists($path . '/w:checkBox'));
$this->assertTrue($doc->elementExists($path . '/w:ddList')); $this->assertTrue($doc->elementExists($path . '/w:ddList'));
@ -211,7 +228,7 @@ class ElementTest extends \PHPUnit_Framework_TestCase
$doc = TestHelperDOCX::getDocument($phpWord); $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:comboBox'));
$this->assertTrue($doc->elementExists($path . '/w:dropDownList')); $this->assertTrue($doc->elementExists($path . '/w:dropDownList'));
$this->assertTrue($doc->elementExists($path . '/w:date')); $this->assertTrue($doc->elementExists($path . '/w:date'));

View File

@ -34,26 +34,20 @@ class AbstractWriterPartTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetParentWriter() public function testSetGetParentWriter()
{ {
$object = $this->getMockForAbstractClass( $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart');
'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'
);
$object->setParentWriter(new Word2007()); $object->setParentWriter(new Word2007());
$this->assertEquals( $this->assertEquals(new Word2007(), $object->getParentWriter());
new Word2007(),
$object->getParentWriter()
);
} }
/** /**
* covers ::getParentWriter * covers ::getParentWriter
*
* @expectedException Exception * @expectedException Exception
* @expectedExceptionMessage No parent WriterInterface assigned. * @expectedExceptionMessage No parent WriterInterface assigned.
*/ */
public function testSetGetParentWriterNull() public function testSetGetParentWriterNull()
{ {
$object = $this->getMockForAbstractClass( $object = $this->getMockForAbstractClass('PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart');
'PhpOffice\\PhpWord\\Writer\\Word2007\\Part\\AbstractPart'
);
$object->getParentWriter(); $object->getParentWriter();
} }
} }

View File

@ -19,7 +19,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
use PhpOffice\PhpWord\Writer\Word2007\Part\Document;
/** /**
* Test class for 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() public function testElements()
{ {
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addTitleStyle(1, array('color' => '333333', 'bold'=>true)); $phpWord->addTitleStyle(1, array('color' => '333333', 'bold' => true));
$phpWord->addTitleStyle(2, array('color'=>'666666')); $phpWord->addTitleStyle(2, array('color' => '666666'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addTOC(); $section->addTOC();
$section->addPageBreak(); $section->addPageBreak();
$section->addText('After page break.'); $section->addText(htmlspecialchars('After page break.', ENT_COMPAT, 'UTF-8'));
$section->addTitle('Title 1', 1); $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1);
$section->addListItem('List Item 1', 0); $section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0);
$section->addListItem('List Item 2', 0); $section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0);
$section->addListItem('List Item 3', 0); $section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 0);
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addTitle('Title 2', 2); $section->addTitle(htmlspecialchars('Title 2', ENT_COMPAT, 'UTF-8'), 2);
$section->addObject($objectSrc); $section->addObject($objectSrc);
$section->addTextBox(array()); $section->addTextBox(array());
$section->addTextBox(array('wrappingStyle' => 'square', 'positioning' => 'relative', $section->addTextBox(
'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin', array(
'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0')); 'wrappingStyle' => 'square',
'positioning' => 'relative',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'margin',
'innerMargin' => 10,
'borderSize' => 1,
'borderColor' => '#FF0',
)
);
$section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center')); $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center'));
$section->addListItemRun()->addText('List item run 1'); $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(
$section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'SakaEraCalendar')); 'DATE',
$section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat', 'LastUsedFormat')); array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'),
$section->addField('PAGE', array('format'=>'ArabicDash')); 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( $section->addLine(
array( array(
'width' => 10, 'width' => 10,
'height' => 10, 'height' => 10,
'positioning' => 'absolute', 'positioning' => 'absolute',
'beginArrow' => 'block', 'beginArrow' => 'block',
'endArrow' => 'open', 'endArrow' => 'open',
'dash' => 'rounddot', 'dash' => 'rounddot',
'weight' => 10 'weight' => 10,
) )
); );
@ -131,27 +150,39 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
*/ */
public function testElementStyles() public function testElementStyles()
{ {
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
$tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)); $tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090));
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array( $phpWord->addParagraphStyle(
'align' => 'center', 'pStyle',
'tabs' => $tabs, array(
'shading' => array('fill' => 'FFFF99'), 'align' => 'center',
'borderSize' => 4, 'tabs' => $tabs,
)); // Style #1 'shading' => array('fill' => 'FFFF99'),
$phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true, 'borderSize' => 4,
'scale' => 200, 'spacing' => 240, 'kerning' => 10)); // Style #2 )
); // 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->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3
$phpWord->addTableStyle('tStyle', array('borderSize' => 1)); $phpWord->addTableStyle('tStyle', array('borderSize' => 1));
$fontStyle = new Font('text', array('align' => 'center')); $fontStyle = new Font('text', array('align' => 'center'));
$section = $phpWord->addSection(); $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->addObject($objectSrc, array('align' => 'center'));
$section->addTOC($fontStyle); $section->addTOC($fontStyle);
$section->addTitle('Title 1', 1); $section->addTitle(htmlspecialchars('Title 1', ENT_COMPAT, 'UTF-8'), 1);
$section->addTOC('fStyle'); $section->addTOC('fStyle');
$table = $section->addTable('tStyle'); $table = $section->addTable('tStyle');
$table->setWidth(100); $table->setWidth(100);
@ -184,12 +215,12 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$phpWord->addFontStyle($rStyle, array('bold' => true)); $phpWord->addFontStyle($rStyle, array('bold' => true));
$phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test', $rStyle, $pStyle); $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $rStyle, $pStyle);
$doc = TestHelperDOCX::getDocument($phpWord); $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')); $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')); $this->assertEquals($pStyle, $doc->getElementAttribute($element, 'w:val'));
} }
@ -200,21 +231,21 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{ {
$pStyle = 'pStyle'; $pStyle = 'pStyle';
$aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120); $aStyle = array('align' => 'justify', 'spaceBefore' => 120, 'spaceAfter' => 120);
$imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addParagraphStyle($pStyle, $aStyle); $phpWord->addParagraphStyle($pStyle, $aStyle);
$section = $phpWord->addSection('Test'); $section = $phpWord->addSection(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$textrun = $section->addTextRun($pStyle); $textrun = $section->addTextRun($pStyle);
$textrun->addText('Test'); $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$textrun->addTextBreak(); $textrun->addTextBreak();
$textrun = $section->addTextRun($aStyle); $textrun = $section->addTextRun($aStyle);
$textrun->addLink('http://test.com'); $textrun->addLink('https://github.com/PHPOffice/PHPWord');
$textrun->addImage($imageSrc, array('align' => 'center')); $textrun->addImage($imageSrc, array('align' => 'center'));
$textrun->addFootnote(); $textrun->addFootnote();
$doc = TestHelperDOCX::getDocument($phpWord); $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}']")); $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'); $paragraphStyleArray = array('align' => 'center');
$paragraphStyleName = 'Paragraph Style'; $paragraphStyleName = 'Paragraph Style';
$expected = 'PhpWord'; $expected = 'PHPWord on GitHub';
$section->addLink('http://github.com/phpoffice/phpword', $expected); $section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars($expected, ENT_COMPAT, 'UTF-8'));
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleArray, $paragraphStyleArray); $section->addLink(
$section->addLink('http://github.com/phpoffice/phpword', 'Test', $fontStyleName, $paragraphStyleName); '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); $doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t'); $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'); $paragraphStyleArray = array('align' => 'right');
$paragraphStyleName = 'Paragraph'; $paragraphStyleName = 'Paragraph';
$footer->addPreserveText('Page {PAGE}'); $footer->addPreserveText(htmlspecialchars('Page {PAGE}', ENT_COMPAT, 'UTF-8'));
$footer->addPreserveText('{PAGE}', $fontStyleArray, $paragraphStyleArray); $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleArray, $paragraphStyleArray);
$footer->addPreserveText('{PAGE}', $fontStyleName, $paragraphStyleName); $footer->addPreserveText(htmlspecialchars('{PAGE}', ENT_COMPAT, 'UTF-8'), $fontStyleName, $paragraphStyleName);
$doc = TestHelperDOCX::getDocument($phpWord); $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('PAGE', $preserve->nodeValue);
$this->assertEquals('preserve', $preserve->getAttribute('xml:space')); $this->assertEquals('preserve', $preserve->getAttribute('xml:space'));
@ -301,7 +342,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$section = $phpWord->addSection(); $section = $phpWord->addSection();
foreach ($wraps as $wrap) { foreach ($wraps as $wrap) {
$styles['wrappingStyle'] = $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'); $archiveFile = realpath(__DIR__ . '/../../../_files/documents/reader.docx');
@ -326,7 +367,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteWatermark() public function testWriteWatermark()
{ {
$imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg';
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
@ -334,8 +375,8 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$header->addWatermark($imageSrc); $header->addWatermark($imageSrc);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$element = $doc->getElement("/w:document/w:body/w:sectPr/w:headerReference"); $element = $doc->getElement('/w:document/w:body/w:sectPr/w:headerReference');
$this->assertStringStartsWith("rId", $element->getAttribute('r:id')); $this->assertStringStartsWith('rId', $element->getAttribute('r:id'));
} }
/** /**
@ -345,10 +386,10 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{ {
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240)); $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); $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')); $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->addFontStyle($rStyle, array('bold' => true));
// $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120)); // $phpWord->addParagraphStyle($pStyle, array('hanging' => 120, 'indent' => 120));
$section = $phpWord->addSection(); $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); $doc = TestHelperDOCX::getDocument($phpWord);
$element = '/w:document/w:body/w:p/w:r/w:fldChar/w:ffData/w:name'; $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(); $phpWord = new PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$attributes = array( $attributes = array(
'align' => 'right', 'align' => 'right',
'widowControl' => false, 'widowControl' => false,
'keepNext' => true, 'keepNext' => true,
'keepLines' => true, 'keepLines' => true,
'pageBreakBefore' => true, 'pageBreakBefore' => true,
); );
foreach ($attributes as $attribute => $value) { 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); $doc = TestHelperDOCX::getDocument($phpWord);
@ -397,7 +438,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$attributeCount++; $attributeCount++;
$nodeName = ($key == 'align') ? 'jc' : $key; $nodeName = ($key == 'align') ? 'jc' : $key;
$path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}"; $path = "/w:document/w:body/w:p[{$attributeCount}]/w:pPr/w:{$nodeName}";
if ($key != 'align') { if ('align' != $key) {
$value = $value ? 1 : 0; $value = $value ? 1 : 0;
} }
$element = $doc->getElement($path); $element = $doc->getElement($path);
@ -425,7 +466,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$styles['smallCaps'] = true; $styles['smallCaps'] = true;
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Test', $styles); $section->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'), $styles);
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$parent = '/w:document/w:body/w:p/w:r/w:rPr'; $parent = '/w:document/w:body/w:p/w:r/w:rPr';
@ -449,50 +490,46 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$rHeight = 120; $rHeight = 120;
$cWidth = 120; $cWidth = 120;
$imageSrc = __DIR__ . "/../../../_files/images/earth.jpg"; $imageSrc = __DIR__ . '/../../../_files/images/earth.jpg';
$objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; $objectSrc = __DIR__ . '/../../../_files/documents/sheet.xls';
$tStyles["width"] = 50; $tStyles['width'] = 50;
$tStyles["cellMarginTop"] = 120; $tStyles['cellMarginTop'] = 120;
$tStyles["cellMarginRight"] = 120; $tStyles['cellMarginRight'] = 120;
$tStyles["cellMarginBottom"] = 120; $tStyles['cellMarginBottom'] = 120;
$tStyles["cellMarginLeft"] = 120; $tStyles['cellMarginLeft'] = 120;
$rStyles["tblHeader"] = true; $rStyles['tblHeader'] = true;
$rStyles["cantSplit"] = true; $rStyles['cantSplit'] = true;
$cStyles["valign"] = 'top'; $cStyles['valign'] = 'top';
$cStyles["textDirection"] = 'btLr'; $cStyles['textDirection'] = 'btLr';
$cStyles["bgColor"] = 'FF0000'; $cStyles['bgColor'] = 'FF0000';
$cStyles["borderTopSize"] = 120; $cStyles['borderTopSize'] = 120;
$cStyles["borderBottomSize"] = 120; $cStyles['borderBottomSize'] = 120;
$cStyles["borderLeftSize"] = 120; $cStyles['borderLeftSize'] = 120;
$cStyles["borderRightSize"] = 120; $cStyles['borderRightSize'] = 120;
$cStyles["borderTopColor"] = 'FF0000'; $cStyles['borderTopColor'] = 'FF0000';
$cStyles["borderBottomColor"] = 'FF0000'; $cStyles['borderBottomColor'] = 'FF0000';
$cStyles["borderLeftColor"] = 'FF0000'; $cStyles['borderLeftColor'] = 'FF0000';
$cStyles["borderRightColor"] = 'FF0000'; $cStyles['borderRightColor'] = 'FF0000';
$cStyles["vMerge"] = 'restart'; $cStyles['vMerge'] = 'restart';
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$table = $section->addTable($tStyles); $table = $section->addTable($tStyles);
$table->setWidth = 100; $table->setWidth = 100;
$table->addRow($rHeight, $rStyles); $table->addRow($rHeight, $rStyles);
$cell = $table->addCell($cWidth, $cStyles); $cell = $table->addCell($cWidth, $cStyles);
$cell->addText('Test'); $cell->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addTextBreak(); $cell->addTextBreak();
$cell->addLink('http://google.com'); $cell->addLink('https://github.com/PHPOffice/PHPWord');
$cell->addListItem('Test'); $cell->addListItem(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$cell->addImage($imageSrc); $cell->addImage($imageSrc);
$cell->addObject($objectSrc); $cell->addObject($objectSrc);
$textrun = $cell->addTextRun(); $textrun = $cell->addTextRun();
$textrun->addText('Test'); $textrun->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
$parent = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellMar'; $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'; $parent = '/w:document/w:body/w:tbl/w:tr/w:trPr';
$this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val')); $this->assertEquals($rHeight, $doc->getElementAttribute("{$parent}/w:trHeight", 'w:val'));

View File

@ -32,13 +32,13 @@ class FooterTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteFooter() public function testWriteFooter()
{ {
$imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
$container = new \PhpOffice\PhpWord\Element\Footer(1); $container = new \PhpOffice\PhpWord\Element\Footer(1);
$container->addText(''); $container->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
$container->addPreserveText(''); $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
$container->addTextBreak(); $container->addTextBreak();
$container->addTextRun(); $container->addTextRun();
$container->addTable()->addRow()->addCell()->addText(''); $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
$container->addImage($imageSrc); $container->addImage($imageSrc);
$writer = new Word2007(); $writer = new Word2007();

View File

@ -42,16 +42,16 @@ class FootnotesTest extends \PHPUnit_Framework_TestCase
$phpWord = new PhpWord(); $phpWord = new PhpWord();
$phpWord->addParagraphStyle('pStyle', array('align' => 'left')); $phpWord->addParagraphStyle('pStyle', array('align' => 'left'));
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$section->addText('Text'); $section->addText(htmlspecialchars('Text', ENT_COMPAT, 'UTF-8'));
$footnote1 = $section->addFootnote('pStyle'); $footnote1 = $section->addFootnote('pStyle');
$footnote1->addText('Footnote'); $footnote1->addText(htmlspecialchars('Footnote', ENT_COMPAT, 'UTF-8'));
$footnote1->addTextBreak(); $footnote1->addTextBreak();
$footnote1->addLink('http://google.com'); $footnote1->addLink('https://github.com/PHPOffice/PHPWord');
$footnote2 = $section->addEndnote(array('align' => 'left')); $footnote2 = $section->addEndnote(array('align' => 'left'));
$footnote2->addText('Endnote'); $footnote2->addText(htmlspecialchars('Endnote', ENT_COMPAT, 'UTF-8'));
$doc = TestHelperDOCX::getDocument($phpWord); $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: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:endnoteReference'));
} }
} }

View File

@ -31,14 +31,14 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
*/ */
public function testWriteHeader() public function testWriteHeader()
{ {
$imageSrc = __DIR__ . "/../../../_files/images/PhpWord.png"; $imageSrc = __DIR__ . '/../../../_files/images/PhpWord.png';
$container = new \PhpOffice\PhpWord\Element\Header(1); $container = new \PhpOffice\PhpWord\Element\Header(1);
$container->addText('Test'); $container->addText(htmlspecialchars('Test', ENT_COMPAT, 'UTF-8'));
$container->addPreserveText(''); $container->addPreserveText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
$container->addTextBreak(); $container->addTextBreak();
$container->addTextRun(); $container->addTextRun();
$container->addTable()->addRow()->addCell()->addText(''); $container->addTable()->addRow()->addCell()->addText(htmlspecialchars('', ENT_COMPAT, 'UTF-8'));
$container->addImage($imageSrc); $container->addImage($imageSrc);
$container->addWatermark($imageSrc); $container->addWatermark($imageSrc);

View File

@ -47,20 +47,20 @@ class NumberingTest extends \PHPUnit_Framework_TestCase
$phpWord->addNumberingStyle( $phpWord->addNumberingStyle(
'numStyle', 'numStyle',
array( array(
'type' => 'multilevel', 'type' => 'multilevel',
'levels' => array( 'levels' => array(
array( array(
'start' => 1, 'start' => 1,
'format' => 'decimal', 'format' => 'decimal',
'restart' => 1, 'restart' => 1,
'suffix' => 'space', 'suffix' => 'space',
'text' => '%1.', 'text' => '%1.',
'align' => 'left', 'align' => 'left',
'left' => 360, 'left' => 360,
'hanging' => 360, 'hanging' => 360,
'tabPos' => 360, 'tabPos' => 360,
'font' => 'Arial', 'font' => 'Arial',
'hint' => 'default', 'hint' => 'default',
), ),
) )
) )

View File

@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; use PhpOffice\PhpWord\Tests\TestHelperDOCX;
use PhpOffice\PhpWord\Writer\Word2007\Part\Styles;
/** /**
* Test class for 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'); $pNew = array('basedOn' => 'Base Style', 'next' => 'Normal');
$rStyle = array('size' => 20); $rStyle = array('size' => 20);
$tStyle = array( $tStyle = array(
'bgColor' => 'FF0000', 'bgColor' => 'FF0000',
'cellMargin' => 120, 'cellMargin' => 120,
'borderSize' => 120, 'borderSize' => 120,
); );
$firstRowStyle = array( $firstRowStyle = array(
'bgColor' => '0000FF', 'bgColor' => '0000FF',
'borderSize' => 120, 'borderSize' => 120,
'borderColor' => '00FF00', 'borderColor' => '00FF00',
); );
$phpWord->setDefaultParagraphStyle($pStyle); $phpWord->setDefaultParagraphStyle($pStyle);

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part; namespace PhpOffice\PhpWord\Tests\Writer\Word2007\Part;
use PhpOffice\PhpWord\Tests\TestHelperDOCX; 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 * Test class for PhpOffice\PhpWord\Writer\Word2007\Style\Font
@ -44,7 +42,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection(); $section = $phpWord->addSection();
$textrun = $section->addTextRun(); $textrun = $section->addTextRun();
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true)); $textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است', ENT_COMPAT, 'UTF-8'), array('rtl' => true));
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007'); $doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
$file = 'word/document.xml'; $file = 'word/document.xml';

Some files were not shown because too many files have changed in this diff Show More