|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of PHPPowerPoint - A pure PHP library for reading and writing |
| 4 | + * presentations documents. |
| 5 | + * |
| 6 | + * PHPPowerPoint is free software distributed under the terms of the GNU Lesser |
| 7 | + * General Public License version 3 as published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * For the full copyright and license information, please read the LICENSE |
| 10 | + * file that was distributed with this source code. For the full list of |
| 11 | + * contributors, visit https://github.com/PHPOffice/PHPPowerPoint/contributors. |
| 12 | + * |
| 13 | + * @copyright 2009-2014 PHPPowerPoint contributors |
| 14 | + * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 15 | + * @link https://github.com/PHPOffice/PHPPowerPoint |
| 16 | + */ |
| 17 | + |
| 18 | +namespace PhpOffice\PhpPowerpoint\Tests\Shape\RichText; |
| 19 | + |
| 20 | +use PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph; |
| 21 | +use PhpOffice\PhpPowerpoint\Shape\RichText\TextElement; |
| 22 | +use PhpOffice\PhpPowerpoint\Style\Alignment; |
| 23 | +use PhpOffice\PhpPowerpoint\Style\Bullet; |
| 24 | +use PhpOffice\PhpPowerpoint\Style\Font; |
| 25 | + |
| 26 | +/** |
| 27 | + * Test class for Paragraph element |
| 28 | + * |
| 29 | + * @coversDefaultClass PhpOffice\PhpPowerpoint\Shape\RichText\Paragraph |
| 30 | + */ |
| 31 | +class ParagraphTest extends \PHPUnit_Framework_TestCase |
| 32 | +{ |
| 33 | + /** |
| 34 | + * Test can read |
| 35 | + */ |
| 36 | + public function testConstruct() |
| 37 | + { |
| 38 | + $object = new Paragraph(); |
| 39 | + $this->assertEmpty($object->getRichTextElements()); |
| 40 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->getAlignment()); |
| 41 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont()); |
| 42 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle()); |
| 43 | + } |
| 44 | + |
| 45 | + public function testAlignment () |
| 46 | + { |
| 47 | + $object = new Paragraph(); |
| 48 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Alignment', $object->getAlignment()); |
| 49 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setAlignment(new Alignment())); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Test get/set bullet style |
| 54 | + */ |
| 55 | + public function testBulletStyle () |
| 56 | + { |
| 57 | + $object = new Paragraph(); |
| 58 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle()); |
| 59 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setBulletStyle()); |
| 60 | + $this->assertNull($object->getBulletStyle()); |
| 61 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setBulletStyle(new Bullet())); |
| 62 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Bullet', $object->getBulletStyle()); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Test get/set font |
| 67 | + */ |
| 68 | + public function testFont () |
| 69 | + { |
| 70 | + $object = new Paragraph(); |
| 71 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont()); |
| 72 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setFont()); |
| 73 | + $this->assertNull($object->getFont()); |
| 74 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setFont(new Font())); |
| 75 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Style\\Font', $object->getFont()); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Test get/set hashCode |
| 80 | + */ |
| 81 | + public function testHashCode () |
| 82 | + { |
| 83 | + $object = new Paragraph(); |
| 84 | + $oElement = new TextElement(); |
| 85 | + $object->addText($oElement); |
| 86 | + $this->assertEquals(md5($oElement->getHashCode().$object->getFont()->getHashCode().get_class($object)), $object->getHashCode()); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Test get/set hashIndex |
| 91 | + */ |
| 92 | + public function testHashIndex () |
| 93 | + { |
| 94 | + $object = new Paragraph(); |
| 95 | + $value = rand(1, 100); |
| 96 | + $object->setHashIndex($value); |
| 97 | + $this->assertEquals($value, $object->getHashIndex()); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Test get/set richTextElements |
| 102 | + */ |
| 103 | + public function testRichTextElements () |
| 104 | + { |
| 105 | + $object = new Paragraph(); |
| 106 | + $this->assertInternalType('array', $object->getRichTextElements()); |
| 107 | + $this->assertEmpty($object->getRichTextElements()); |
| 108 | + $object->createBreak(); |
| 109 | + $this->assertCount(1, $object->getRichTextElements()); |
| 110 | + |
| 111 | + $array = array( |
| 112 | + new TextElement(), |
| 113 | + new TextElement(), |
| 114 | + new TextElement(), |
| 115 | + ); |
| 116 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->setRichTextElements($array)); |
| 117 | + $this->assertCount(3, $object->getRichTextElements()); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @expectedException \Exception |
| 122 | + * expectedExceptionMessage Invalid \PhpOffice\PhpPowerpoint\Shape\RichText\TextElementInterface[] array passed. |
| 123 | + */ |
| 124 | + public function testRichTextElementsException () |
| 125 | + { |
| 126 | + $object = new Paragraph(); |
| 127 | + $object->setRichTextElements(1); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Test text methods |
| 132 | + */ |
| 133 | + public function testText () |
| 134 | + { |
| 135 | + $object = new Paragraph(); |
| 136 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Paragraph', $object->addText(new TextElement())); |
| 137 | + $this->assertcount(1, $object->getRichTextElements()); |
| 138 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\TextElement', $object->createText()); |
| 139 | + $this->assertcount(2, $object->getRichTextElements()); |
| 140 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\TextElement', $object->createText('AAA')); |
| 141 | + $this->assertcount(3, $object->getRichTextElements()); |
| 142 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\BreakElement', $object->createBreak()); |
| 143 | + $this->assertcount(4, $object->getRichTextElements()); |
| 144 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->createTextRun()); |
| 145 | + $this->assertcount(5, $object->getRichTextElements()); |
| 146 | + $this->assertInstanceOf('PhpOffice\\PhpPowerpoint\\Shape\\RichText\\Run', $object->createTextRun('BBB')); |
| 147 | + $this->assertcount(6, $object->getRichTextElements()); |
| 148 | + $this->assertEquals('AAA'."\r\n".'BBB', $object->getPlainText()); |
| 149 | + $this->assertEquals('AAA'."\r\n".'BBB', (string)$object); |
| 150 | + } |
| 151 | +} |
0 commit comments