2014-03-09 19:09:22 +01:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
2017-11-04 22:44:12 +01:00
|
|
|
* @see https://github.com/PHPOffice/PHPWord
|
2018-03-08 23:52:25 +01:00
|
|
|
* @copyright 2010-2018 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-27 23:55:06 +07:00
|
|
|
*/
|
|
|
|
|
|
2015-11-15 13:33:05 +04:00
|
|
|
namespace PhpOffice\PhpWord\Element;
|
2014-03-09 19:09:22 +01:00
|
|
|
|
2018-12-30 14:14:27 +01:00
|
|
|
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
|
|
|
|
|
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2014-04-08 00:23:49 +07:00
|
|
|
* Test class for PhpOffice\PhpWord\Element\Footer
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
|
*/
|
2018-12-30 14:14:27 +01:00
|
|
|
class FooterTest extends AbstractWebServerEmbeddedTest
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* New instance
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testConstruct()
|
|
|
|
|
{
|
|
|
|
|
$iVal = rand(1, 1000);
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer($iVal);
|
2014-03-09 15:04:23 -04:00
|
|
|
|
2014-04-08 00:23:49 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter);
|
2015-02-06 22:28:31 +04:00
|
|
|
$this->assertEquals($iVal, $oFooter->getSectionId());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add text
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddText()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2016-06-04 20:06:37 +04:00
|
|
|
$element = $oFooter->addText('text');
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add text non-UTF8
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddTextNotUTF8()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2016-06-04 20:06:37 +04:00
|
|
|
$element = $oFooter->addText(utf8_decode('ééé'));
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
2016-06-04 20:06:37 +04:00
|
|
|
$this->assertEquals('ééé', $element->getText());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add text break
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddTextBreak()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-03-09 15:04:23 -04:00
|
|
|
$iVal = rand(1, 1000);
|
|
|
|
|
$oFooter->addTextBreak($iVal);
|
|
|
|
|
|
|
|
|
|
$this->assertCount($iVal, $oFooter->getElements());
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add text run
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testCreateTextRun()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-04-02 11:02:56 +07:00
|
|
|
$element = $oFooter->addTextRun();
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add table
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddTable()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-03-09 15:04:23 -04:00
|
|
|
$element = $oFooter->addTable();
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add image
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddImage()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$src = __DIR__ . '/../_files/images/earth.jpg';
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-04-03 11:34:06 +07:00
|
|
|
$element = $oFooter->addImage($src);
|
2014-03-09 15:04:23 -04:00
|
|
|
|
2014-04-03 11:34:06 +07:00
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
|
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add image by URL
|
|
|
|
|
*/
|
2014-03-24 16:24:50 +07:00
|
|
|
public function testAddImageByUrl()
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2018-12-30 14:14:27 +01:00
|
|
|
$element = $oFooter->addImage(self::getRemoteGifImageUrl());
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add preserve text
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddPreserveText()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2016-06-04 20:06:37 +04:00
|
|
|
$element = $oFooter->addPreserveText('text');
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Add preserve text non-UTF8
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testAddPreserveTextNotUTF8()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2016-06-04 20:06:37 +04:00
|
|
|
$element = $oFooter->addPreserveText(utf8_decode('ééé'));
|
2014-03-09 15:04:23 -04:00
|
|
|
|
|
|
|
|
$this->assertCount(1, $oFooter->getElements());
|
2014-03-31 01:13:02 +07:00
|
|
|
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
2016-06-04 20:06:37 +04:00
|
|
|
$this->assertEquals(array('ééé'), $element->getText());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
|
|
|
|
* Get elements
|
|
|
|
|
*/
|
2014-03-09 15:04:23 -04:00
|
|
|
public function testGetElements()
|
|
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-03-09 15:04:23 -04:00
|
|
|
|
2022-09-16 11:27:29 +02:00
|
|
|
$this->assertIsArray($oFooter->getElements());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
2014-03-30 11:09:14 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set/get relation Id
|
|
|
|
|
*/
|
|
|
|
|
public function testRelationID()
|
|
|
|
|
{
|
|
|
|
|
$oFooter = new Footer(0);
|
|
|
|
|
|
|
|
|
|
$iVal = rand(1, 1000);
|
|
|
|
|
$oFooter->setRelationId($iVal);
|
2014-04-06 15:19:09 +07:00
|
|
|
|
2015-02-06 22:28:31 +04:00
|
|
|
$this->assertEquals($iVal, $oFooter->getRelationId());
|
2014-04-06 15:19:09 +07:00
|
|
|
$this->assertEquals(Footer::AUTO, $oFooter->getType());
|
2014-03-30 11:09:14 +07:00
|
|
|
}
|
2014-03-11 21:44:54 +07:00
|
|
|
}
|