Improve Test Coverage
Coverage for Writer/ODText is now 100%.
This commit is contained in:
parent
4e347b33d7
commit
ba3d616282
|
|
@ -157,6 +157,8 @@ class Section extends AbstractContainer
|
|||
* @deprecated Use the `getFootnoteProperties` method instead
|
||||
*
|
||||
* @return FootnoteProperties
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function getFootnotePropoperties()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ class Text extends AbstractElement
|
|||
|
||||
// @todo Commented for TextRun. Should really checkout this value
|
||||
// $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
|
||||
$fStyleIsObject = false;
|
||||
//$fStyleIsObject = false;
|
||||
|
||||
if ($fStyleIsObject) {
|
||||
//if ($fStyleIsObject) {
|
||||
// Don't never be the case, because I browse all sections for cleaning all styles not declared
|
||||
throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
|
||||
}
|
||||
// throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
|
||||
//}
|
||||
|
||||
if (!$this->withoutP) {
|
||||
$xmlWriter->startElement('text:p'); // text:p
|
||||
|
|
|
|||
|
|
@ -77,10 +77,12 @@ class ImageTest extends AbstractWebServerEmbeddedTest
|
|||
|
||||
foreach ($images as $imageData) {
|
||||
list($source, $type, $extension, $createFunction, $imageFunction) = $imageData;
|
||||
$nam = ucfirst(strtok($source, '.'));
|
||||
$source = __DIR__ . "/../_files/images/{$source}";
|
||||
$image = new Image($source);
|
||||
$image = new Image($source, null, null, $nam);
|
||||
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image);
|
||||
$this->assertEquals($source, $image->getSource());
|
||||
$this->assertEquals($nam, $image->getName());
|
||||
$this->assertEquals(md5($source), $image->getMediaId());
|
||||
$this->assertEquals($type, $image->getImageType());
|
||||
$this->assertEquals($extension, $image->getImageExtension());
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
namespace PhpOffice\PhpWord\Writer\ODText;
|
||||
|
||||
use PhpOffice\Common\XMLWriter;
|
||||
use PhpOffice\PhpWord\Element\TrackChange;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||
|
||||
|
|
@ -187,6 +188,47 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
$this->assertEquals('#333333', $doc->getElementAttribute($element, 'fo:color'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test title specified as text run rather than text
|
||||
*/
|
||||
public function testTextRunTitle()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->addTitleStyle(1, array('name' => 'Times New Roman', 'size' => 18, 'bold' => true));
|
||||
$section = $phpWord->addSection();
|
||||
$section->addTitle('Text Title', 1);
|
||||
$section->addText('Text following Text Title');
|
||||
$textRun = new \PhpOffice\PhpWord\Element\TextRun();
|
||||
$textRun->addText('Text Run');
|
||||
$textRun->addText(' Title');
|
||||
$section->addTitle($textRun, 1);
|
||||
$section->addText('Text following Text Run Title');
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||
|
||||
$p2t = '/office:document-content/office:body/office:text/text:section';
|
||||
|
||||
$element = "$p2t/text:h[1]";
|
||||
$this->assertEquals('HE1', $doc->getElementAttribute($element, 'text:style-name'));
|
||||
$this->assertEquals('1', $doc->getElementAttribute($element, 'text:outline-level'));
|
||||
$span = "$element/text:span";
|
||||
$this->assertEquals('Text Title', $doc->getElement($span)->textContent);
|
||||
$this->assertEquals('Heading_1', $doc->getElementAttribute($span, 'text:style-name'));
|
||||
$element = "$p2t/text:p[2]/text:span";
|
||||
$this->assertEquals('Text following Text Title', $doc->getElement($element)->nodeValue);
|
||||
|
||||
$element = "$p2t/text:h[2]";
|
||||
$this->assertEquals('HD1', $doc->getElementAttribute($element, 'text:style-name'));
|
||||
$this->assertEquals('1', $doc->getElementAttribute($element, 'text:outline-level'));
|
||||
$span = "$element/text:span";
|
||||
$this->assertEquals('Text Run', $doc->getElement("$span/text:span[1]")->textContent);
|
||||
$this->assertTrue($doc->elementExists("$span/text:span[2]/text:s"));
|
||||
$this->assertEquals('Title', $doc->getElement("$span/text:span[2]")->textContent);
|
||||
$this->assertEquals('Heading_1', $doc->getElementAttribute($span, 'text:style-name'));
|
||||
$element = "$p2t/text:p[3]/text:span";
|
||||
$this->assertEquals('Text following Text Run Title', $doc->getElement($element)->nodeValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test correct writing of text with ampersand in it
|
||||
*/
|
||||
|
|
@ -225,4 +267,62 @@ class ElementTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue($doc->elementExists($element, 'content.xml'));
|
||||
self::assertEquals('PB', $doc->getElementAttribute($element, 'text:style-name', 'content.xml'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test tracked changes
|
||||
*/
|
||||
public function testTrackedChanges()
|
||||
{
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// New portrait section
|
||||
$section = $phpWord->addSection();
|
||||
$textRun = $section->addTextRun();
|
||||
|
||||
$text = $textRun->addText('Hello World! Time to ');
|
||||
|
||||
$text = $textRun->addText('wake ', array('bold' => true));
|
||||
$text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800);
|
||||
|
||||
$text = $textRun->addText('up');
|
||||
$text->setTrackChange(new TrackChange(TrackChange::INSERTED, 'Fred'));
|
||||
|
||||
$text = $textRun->addText('go to sleep');
|
||||
$text->setChangeInfo(TrackChange::DELETED, 'Barney', new \DateTime('@' . (time() - 3600)));
|
||||
|
||||
$doc = TestHelperDOCX::getDocument($phpWord, 'ODText');
|
||||
|
||||
$tcs = '/office:document-content/office:body/office:text/text:tracked-changes';
|
||||
$tc1 = "$tcs/text:changed-region[1]";
|
||||
$tc1id = $doc->getElementAttribute($tc1, 'text:id');
|
||||
$element = "$tc1/text:insertion";
|
||||
self::assertTrue($doc->elementExists($element));
|
||||
$element .= '/office:change-info';
|
||||
self::AssertEquals('Fred', $doc->getElement("$element/dc:creator")->nodeValue);
|
||||
self::assertTrue($doc->elementExists("$element/dc:date"));
|
||||
|
||||
$tc2 = "$tcs/text:changed-region[2]";
|
||||
$tc2id = $doc->getElementAttribute($tc2, 'text:id');
|
||||
$element = "$tc2/text:insertion";
|
||||
self::assertTrue($doc->elementExists($element));
|
||||
$element .= '/office:change-info';
|
||||
self::AssertEquals('Fred', $doc->getElement("$element/dc:creator")->nodeValue);
|
||||
//self::assertTrue($doc->elementExists("$element/dc:date"));
|
||||
|
||||
$tc3 = "$tcs/text:changed-region[3]";
|
||||
$tc3id = $doc->getElementAttribute($tc3, 'text:id');
|
||||
$element = "$tc3/text:deletion";
|
||||
self::assertTrue($doc->elementExists($element));
|
||||
$element .= '/office:change-info';
|
||||
self::AssertEquals('Barney', $doc->getElement("$element/dc:creator")->nodeValue);
|
||||
self::assertTrue($doc->elementExists("$element/dc:date"));
|
||||
|
||||
$p2t = '/office:document-content/office:body/office:text/text:section/text:p[2]';
|
||||
$element = "$p2t/text:span[2]/text:change-start";
|
||||
self::AssertEquals($tc1id, $doc->getElementAttribute($element, 'text:change-id'));
|
||||
$element = "$p2t/text:span[3]/text:change-start";
|
||||
self::AssertEquals($tc2id, $doc->getElementAttribute($element, 'text:change-id'));
|
||||
$element = "$p2t/text:change";
|
||||
self::AssertEquals($tc3id, $doc->getElementAttribute($element, 'text:change-id'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue