|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * PHPPowerPoint |
| 4 | + * |
| 5 | + * @link https://github.com/PHPOffice/PHPPowerPoint |
| 6 | + * @copyright 2014 PHPPowerPoint |
| 7 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Test class for PHPPowerPoint_Writer_PowerPoint2007 |
| 12 | + * |
| 13 | + * @coversDefaultClass PHPPowerPoint_Writer_PowerPoint2007 |
| 14 | + */ |
| 15 | +class PHPPowerPoint_Writer_PowerPoint2007Test extends PHPUnit_Framework_TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Test create new instance |
| 19 | + */ |
| 20 | + public function testConstruct() |
| 21 | + { |
| 22 | + $objectPrefix = 'PHPPowerPoint_Writer_PowerPoint2007_'; |
| 23 | + $parts = array( |
| 24 | + 'contenttypes' => 'ContentTypes', |
| 25 | + 'docprops' => 'DocProps', |
| 26 | + 'rels' => 'Rels', |
| 27 | + 'theme' => 'Theme', |
| 28 | + 'presentation' => 'Presentation', |
| 29 | + 'slide' => 'Slide', |
| 30 | + 'drawing' => 'Drawing', |
| 31 | + 'chart' => 'Chart', |
| 32 | + ); |
| 33 | + |
| 34 | + $phpPowerPoint = new PHPPowerPoint(); |
| 35 | + $object = new PHPPowerPoint_Writer_PowerPoint2007($phpPowerPoint); |
| 36 | + |
| 37 | + $this->assertInstanceOf('PHPPowerPoint', $object->getPHPPowerPoint()); |
| 38 | + $this->assertEquals('./', $object->getDiskCachingDirectory()); |
| 39 | + $this->assertInstanceOf("{$objectPrefix}LayoutPack_Default", $object->getLayoutPack()); |
| 40 | + foreach ($parts as $partName => $objectName) { |
| 41 | + $this->assertInstanceOf($objectPrefix . $objectName, $object->getWriterPart($partName)); |
| 42 | + } |
| 43 | + $this->assertInstanceOf('PHPPowerPoint_HashTable', $object->getDrawingHashTable()); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Test save |
| 48 | + */ |
| 49 | + public function testSave() |
| 50 | + { |
| 51 | + $filename = tempnam(sys_get_temp_dir(), 'PHPPowerPoint'); |
| 52 | + $imageFile = dirname(__FILE__) . '/../../resources/images/PHPPowerPointLogo.png'; |
| 53 | + |
| 54 | + $phpPowerPoint = new PHPPowerPoint(); |
| 55 | + $slide = $phpPowerPoint->getActiveSlide(); |
| 56 | + $slide->createRichTextShape(); |
| 57 | + $slide->createLineShape(10, 10, 10, 10); |
| 58 | + $slide->createChartShape()->getPlotArea()->setType(new PHPPowerPoint_Shape_Chart_Type_Bar3D()); |
| 59 | + $slide->createDrawingShape()->setName('Drawing')->setPath($imageFile); |
| 60 | + $slide->createTableShape()->createRow(); |
| 61 | + |
| 62 | + $object = new PHPPowerPoint_Writer_PowerPoint2007($phpPowerPoint); |
| 63 | + $object->save($filename); |
| 64 | + |
| 65 | + $this->assertTrue(file_exists($filename)); |
| 66 | + |
| 67 | + unlink($filename); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Test get writer part null |
| 72 | + */ |
| 73 | + public function testGetWriterPartNull() |
| 74 | + { |
| 75 | + $object = new PHPPowerPoint_Writer_PowerPoint2007(new PHPPowerPoint()); |
| 76 | + |
| 77 | + $this->assertNull($object->getWriterPart('foo')); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Test get PHPPowerPoint exception |
| 82 | + * |
| 83 | + * @expectedException Exception |
| 84 | + * @expectedExceptionMessage No PHPPowerPoint assigned. |
| 85 | + */ |
| 86 | + public function testGetPHPPowerPointException() |
| 87 | + { |
| 88 | + $object = new PHPPowerPoint_Writer_PowerPoint2007(); |
| 89 | + $object->getPHPPowerPoint(); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Test set/get Office 2003 compatibility |
| 94 | + */ |
| 95 | + public function testSetGetOffice2003Compatibility() |
| 96 | + { |
| 97 | + $object = new PHPPowerPoint_Writer_PowerPoint2007(new PHPPowerPoint()); |
| 98 | + $this->assertFalse($object->getOffice2003Compatibility()); |
| 99 | + |
| 100 | + $object->setOffice2003Compatibility(true); |
| 101 | + $this->assertTrue($object->getOffice2003Compatibility()); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Test set/get disk caching |
| 106 | + */ |
| 107 | + public function testSetGetUseDiskCaching() |
| 108 | + { |
| 109 | + $object = new PHPPowerPoint_Writer_PowerPoint2007(new PHPPowerPoint()); |
| 110 | + $this->assertFalse($object->getUseDiskCaching()); |
| 111 | + |
| 112 | + $object->setUseDiskCaching(true, sys_get_temp_dir()); |
| 113 | + $this->assertTrue($object->getUseDiskCaching()); |
| 114 | + $this->assertEquals(sys_get_temp_dir(), $object->getDiskCachingDirectory()); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Test set/get disk caching exception |
| 119 | + * |
| 120 | + * @expectedException Exception |
| 121 | + */ |
| 122 | + public function testSetUseDiskCachingException() |
| 123 | + { |
| 124 | + $object = new PHPPowerPoint_Writer_PowerPoint2007(new PHPPowerPoint()); |
| 125 | + $object->setUseDiskCaching(true, 'foo'); |
| 126 | + } |
| 127 | +} |
0 commit comments