PHPWord/tests/PhpWordTests/Element/ListItemRunTest.php

176 lines
5.4 KiB
PHP
Raw Normal View History

2014-05-11 11:08:39 +02:00
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
2022-09-16 11:45:45 +02:00
*
2014-05-11 11:08:39 +02:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
2022-09-16 14:09:17 +02:00
namespace PhpOffice\PhpWordTests\Element;
use PhpOffice\PhpWord\Element\ListItemRun;
2014-05-11 11:08:39 +02:00
/**
2022-09-16 11:45:45 +02:00
* Test class for PhpOffice\PhpWord\Element\ListItemRun.
2014-05-11 11:08:39 +02:00
*
* @runTestsInSeparateProcesses
*/
class ListItemRunTest extends \PHPUnit\Framework\TestCase
2014-05-11 11:08:39 +02:00
{
/**
2022-09-16 11:45:45 +02:00
* New instance.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testConstruct(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
self::assertCount(0, $oListItemRun->getElements());
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oListItemRun->getParagraphStyle());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* New instance with string.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testConstructString(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun(0, null, 'pStyle');
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
self::assertCount(0, $oListItemRun->getElements());
self::assertEquals('pStyle', $oListItemRun->getParagraphStyle());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* New instance with string.
*/
2022-09-16 11:45:45 +02:00
public function testConstructListString(): void
{
$oListItemRun = new ListItemRun(0, 'numberingStyle');
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
self::assertCount(0, $oListItemRun->getElements());
}
2014-05-11 11:08:39 +02:00
/**
2022-09-16 11:45:45 +02:00
* New instance with array.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testConstructArray(): void
2014-05-11 11:08:39 +02:00
{
2022-09-16 11:45:45 +02:00
$oListItemRun = new ListItemRun(0, null, ['spacing' => 100]);
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\ListItemRun', $oListItemRun);
self::assertCount(0, $oListItemRun->getElements());
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Paragraph', $oListItemRun->getParagraphStyle());
2014-05-11 11:08:39 +02:00
}
2014-05-11 11:08:39 +02:00
/**
2022-09-16 11:45:45 +02:00
* Get style.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testStyle(): void
2014-05-11 11:08:39 +02:00
{
2022-09-16 11:45:45 +02:00
$oListItemRun = new ListItemRun(1, ['listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER]);
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\ListItem', $oListItemRun->getStyle());
self::assertEquals(\PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER, $oListItemRun->getStyle()->getListType());
2014-05-11 11:08:39 +02:00
}
2014-05-11 11:08:39 +02:00
/**
2022-09-16 11:45:45 +02:00
* getDepth.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testDepth(): void
2014-05-11 11:08:39 +02:00
{
2022-09-16 11:45:45 +02:00
$iVal = mt_rand(1, 1000);
2014-05-11 11:08:39 +02:00
$oListItemRun = new ListItemRun($iVal);
2022-09-16 11:45:45 +02:00
self::assertEquals($iVal, $oListItemRun->getDepth());
2014-05-11 11:08:39 +02:00
}
2014-05-11 11:08:39 +02:00
/**
2022-09-16 11:45:45 +02:00
* Add text.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddText(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
2016-06-04 20:06:37 +04:00
$element = $oListItemRun->addText('text');
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
self::assertCount(1, $oListItemRun->getElements());
self::assertEquals('text', $element->getText());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* Add text non-UTF8.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddTextNotUTF8(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
2016-06-04 20:06:37 +04:00
$element = $oListItemRun->addText(utf8_decode('ééé'));
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Text', $element);
self::assertCount(1, $oListItemRun->getElements());
self::assertEquals('ééé', $element->getText());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* Add link.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddLink(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
$element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord');
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
self::assertCount(1, $oListItemRun->getElements());
self::assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* Add link with name.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddLinkWithName(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
2016-06-04 20:06:37 +04:00
$element = $oListItemRun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
2014-05-11 11:08:39 +02:00
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Link', $element);
self::assertCount(1, $oListItemRun->getElements());
self::assertEquals('https://github.com/PHPOffice/PHPWord', $element->getSource());
self::assertEquals('PHPWord on GitHub', $element->getText());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* Add text break.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddTextBreak(): void
2014-05-11 11:08:39 +02:00
{
$oListItemRun = new ListItemRun();
$oListItemRun->addTextBreak(2);
2022-09-16 11:45:45 +02:00
self::assertCount(2, $oListItemRun->getElements());
2014-05-11 11:08:39 +02:00
}
/**
2022-09-16 11:45:45 +02:00
* Add image.
2014-05-11 11:08:39 +02:00
*/
2022-09-16 11:45:45 +02:00
public function testAddImage(): void
2014-05-11 11:08:39 +02:00
{
$src = __DIR__ . '/../_files/images/earth.jpg';
2014-05-11 11:08:39 +02:00
$oListItemRun = new ListItemRun();
$element = $oListItemRun->addImage($src);
2022-09-16 11:45:45 +02:00
self::assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
self::assertCount(1, $oListItemRun->getElements());
2014-05-11 11:08:39 +02:00
}
}