PHPWord/tests/PhpWord/Element/FootnoteTest.php

118 lines
3.0 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
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
*/
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
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Element\Footnote.
2014-03-27 23:55:06 +07:00
*
* @runTestsInSeparateProcesses
*/
class FootnoteTest extends \PHPUnit\Framework\TestCase
2014-03-09 15:04:23 -04:00
{
/**
2022-09-16 11:45:45 +02:00
* New instance without parameter.
*/
2022-09-16 11:45:45 +02:00
public function testConstruct(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote();
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Footnote', $oFootnote);
self::assertCount(0, $oFootnote->getElements());
self::assertNull($oFootnote->getParagraphStyle());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* New instance with string parameter.
*/
2022-09-16 11:45:45 +02:00
public function testConstructString(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote('pStyle');
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertEquals('pStyle', $oFootnote->getParagraphStyle());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* New instance with array parameter.
*/
2022-09-16 11:45:45 +02:00
public function testConstructArray(): void
2014-03-09 15:04:23 -04:00
{
2022-09-16 11:45:45 +02:00
$oFootnote = new Footnote(['spacing' => 100]);
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf(
'PhpOffice\\PhpWord\\Style\\Paragraph',
$oFootnote->getParagraphStyle()
);
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* Add text element.
*/
2022-09-16 11:45:45 +02:00
public function testAddText(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote();
2016-06-04 20:06:37 +04:00
$element = $oFootnote->addText('text');
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertCount(1, $oFootnote->getElements());
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* Add text break element.
*/
2022-09-16 11:45:45 +02:00
public function testAddTextBreak(): void
{
$oFootnote = new Footnote();
$oFootnote->addTextBreak(2);
2022-09-16 11:45:45 +02:00
self::assertCount(2, $oFootnote->getElements());
}
/**
2022-09-16 11:45:45 +02:00
* Add link element.
*/
2022-09-16 11:45:45 +02:00
public function testAddLink(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote();
$element = $oFootnote->addLink('https://github.com/PHPOffice/PHPWord');
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
self::assertCount(1, $oFootnote->getElements());
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* Set/get reference Id.
*/
2022-09-16 11:45:45 +02:00
public function testReferenceId(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote();
2014-03-09 19:09:22 +01:00
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-04-03 08:44:41 +07:00
$oFootnote->setRelationId($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oFootnote->getRelationId());
2014-03-09 15:04:23 -04:00
}
2014-03-09 19:09:22 +01:00
/**
2022-09-16 11:45:45 +02:00
* Get elements.
*/
2022-09-16 11:45:45 +02:00
public function testGetElements(): void
2014-03-09 15:04:23 -04:00
{
$oFootnote = new Footnote();
2022-09-16 11:45:45 +02:00
self::assertIsArray($oFootnote->getElements());
2014-03-09 15:04:23 -04:00
}
}