PHPWord/tests/PhpWord/Element/FooterTest.php

174 lines
4.6 KiB
PHP
Raw Normal View History

2014-03-09 19:09:22 +01:00
<?php
2014-03-27 23:55:06 +07: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
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2017 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
2014-03-27 23:55:06 +07:00
/**
* Test class for PhpOffice\PhpWord\Element\Footer
2014-03-27 23:55:06 +07:00
*
* @runTestsInSeparateProcesses
*/
class FooterTest extends \PHPUnit\Framework\TestCase
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);
$oFooter = new Footer($iVal);
2014-03-09 15:04:23 -04:00
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footer', $oFooter);
$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()
{
$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());
$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()
{
$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());
$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()
{
$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()
{
$oFooter = new Footer(1);
$element = $oFooter->addTextRun();
2014-03-09 15:04:23 -04:00
$this->assertCount(1, $oFooter->getElements());
$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()
{
$oFooter = new Footer(1);
2014-03-09 15:04:23 -04:00
$element = $oFooter->addTable();
$this->assertCount(1, $oFooter->getElements());
$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()
{
$src = __DIR__ . '/../_files/images/earth.jpg';
$oFooter = new Footer(1);
$element = $oFooter->addImage($src);
2014-03-09 15:04:23 -04: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
*/
public function testAddImageByUrl()
2014-03-09 15:04:23 -04:00
{
$oFooter = new Footer(1);
2016-06-04 20:06:37 +04:00
$element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif');
2014-03-09 15:04:23 -04: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 preserve text
*/
2014-03-09 15:04:23 -04:00
public function testAddPreserveText()
{
$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());
$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()
{
$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());
$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()
{
$oFooter = new Footer(1);
2014-03-09 15:04:23 -04:00
$this->assertInternalType('array', $oFooter->getElements());
}
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
$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
}
}