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
|
2022-09-16 11:45:45 +02:00
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
|
2022-09-16 14:09:17 +02:00
|
|
|
namespace PhpOffice\PhpWordTests\Element;
|
2014-03-09 19:09:22 +01:00
|
|
|
|
2022-09-16 14:09:17 +02:00
|
|
|
use PhpOffice\PhpWord\Element\Footer;
|
|
|
|
|
use PhpOffice\PhpWordTests\AbstractWebServerEmbeddedTest;
|
2018-12-30 14:14:27 +01:00
|
|
|
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02: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
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* New instance.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testConstruct(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2022-09-16 11:45:45 +02:00
|
|
|
$iVal = mt_rand(1, 1000);
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer($iVal);
|
2014-03-09 15:04:23 -04:00
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter);
|
|
|
|
|
self::assertEquals($iVal, $oFooter->getSectionId());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add text.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddText(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add text non-UTF8.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddTextNotUTF8(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
|
|
|
|
|
self::assertEquals('ééé', $element->getText());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add text break.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddTextBreak(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2022-09-16 11:45:45 +02:00
|
|
|
$iVal = mt_rand(1, 1000);
|
2014-03-09 15:04:23 -04:00
|
|
|
$oFooter->addTextBreak($iVal);
|
|
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount($iVal, $oFooter->getElements());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add text run.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testCreateTextRun(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\TextRun', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add table.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddTable(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-03-09 15:04:23 -04:00
|
|
|
$element = $oFooter->addTable();
|
|
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Table', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add image.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddImage(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add image by URL.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddImageByUrl(): void
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add preserve text.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddPreserveText(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Add preserve text non-UTF8.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testAddPreserveTextNotUTF8(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
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
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertCount(1, $oFooter->getElements());
|
|
|
|
|
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\PreserveText', $element);
|
|
|
|
|
self::assertEquals(['ééé'], $element->getText());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-30 11:09:14 +07:00
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Get elements.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testGetElements(): void
|
2014-03-09 15:04:23 -04:00
|
|
|
{
|
2014-03-18 17:26:03 +04:00
|
|
|
$oFooter = new Footer(1);
|
2014-03-09 15:04:23 -04:00
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertIsArray($oFooter->getElements());
|
2014-03-09 15:04:23 -04:00
|
|
|
}
|
2014-03-30 11:09:14 +07:00
|
|
|
|
|
|
|
|
/**
|
2022-09-16 11:45:45 +02:00
|
|
|
* Set/get relation Id.
|
2014-03-30 11:09:14 +07:00
|
|
|
*/
|
2022-09-16 11:45:45 +02:00
|
|
|
public function testRelationID(): void
|
2014-03-30 11:09:14 +07:00
|
|
|
{
|
|
|
|
|
$oFooter = new Footer(0);
|
|
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
$iVal = mt_rand(1, 1000);
|
2014-03-30 11:09:14 +07:00
|
|
|
$oFooter->setRelationId($iVal);
|
2014-04-06 15:19:09 +07:00
|
|
|
|
2022-09-16 11:45:45 +02:00
|
|
|
self::assertEquals($iVal, $oFooter->getRelationId());
|
|
|
|
|
self::assertEquals(Footer::AUTO, $oFooter->getType());
|
2014-03-30 11:09:14 +07:00
|
|
|
}
|
2014-03-11 21:44:54 +07:00
|
|
|
}
|