Skip to content

Commit 3652b1e

Browse files
committed
QA: Writers tests
1 parent 4d4a204 commit 3652b1e

File tree

4 files changed

+241
-1
lines changed

4 files changed

+241
-1
lines changed

Classes/PHPPowerPoint/Writer/ODPresentation/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function writeContent(PHPPowerPoint $pPHPPowerPoint = null)
334334
$this->_writeChart($objWriter, $shape, $shapeId);
335335
}
336336
*/
337-
} elseif ($shape instanceof PHPPowerPoint_Shape_BaseDrawing) {
337+
} elseif ($shape instanceof PHPPowerPoint_Shape_Drawing) {
338338
$this->_writePic($objWriter, $shape, $shapeId);
339339
}
340340
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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_ODPresentation
12+
*
13+
* @coversDefaultClass PHPPowerPoint_Writer_ODPresentation
14+
*/
15+
class PHPPowerPoint_Writer_ODPresentationTest extends PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* Test create new instance
19+
*/
20+
public function testConstruct()
21+
{
22+
$objectPrefix = 'PHPPowerPoint_Writer_ODPresentation_';
23+
$parts = array(
24+
'content' => 'Content',
25+
'manifest' => 'Manifest',
26+
'meta' => 'Meta',
27+
'mimetype' => 'Mimetype',
28+
'styles' => 'Styles',
29+
'drawing' => 'Drawing',
30+
);
31+
32+
$phpPowerPoint = new PHPPowerPoint();
33+
$phpPowerPoint->getActiveSlide()->createDrawingShape();
34+
$object = new PHPPowerPoint_Writer_ODPresentation($phpPowerPoint);
35+
36+
$this->assertInstanceOf('PHPPowerPoint', $object->getPHPPowerPoint());
37+
$this->assertEquals('./', $object->getDiskCachingDirectory());
38+
foreach ($parts as $partName => $objectName) {
39+
$this->assertInstanceOf($objectPrefix . $objectName, $object->getWriterPart($partName));
40+
}
41+
$this->assertInstanceOf('PHPPowerPoint_HashTable', $object->getDrawingHashTable());
42+
}
43+
44+
/**
45+
* Test save
46+
*/
47+
public function testSave()
48+
{
49+
$filename = tempnam(sys_get_temp_dir(), 'PHPPowerPoint');
50+
$imageFile = dirname(__FILE__) . '/../../resources/images/PHPPowerPointLogo.png';
51+
52+
$phpPowerPoint = new PHPPowerPoint();
53+
$slide = $phpPowerPoint->getActiveSlide();
54+
$slide->createRichTextShape();
55+
$slide->createLineShape(10, 10, 10, 10);
56+
$slide->createChartShape()->getPlotArea()->setType(new PHPPowerPoint_Shape_Chart_Type_Bar3D());
57+
$slide->createDrawingShape()->setName('Drawing')->setPath($imageFile);
58+
$slide->createTableShape()->createRow();
59+
60+
$object = new PHPPowerPoint_Writer_ODPresentation($phpPowerPoint);
61+
$object->save($filename);
62+
63+
$this->assertTrue(file_exists($filename));
64+
65+
unlink($filename);
66+
}
67+
68+
/**
69+
* Test get writer part null
70+
*/
71+
public function testGetWriterPartNull()
72+
{
73+
$object = new PHPPowerPoint_Writer_ODPresentation(new PHPPowerPoint());
74+
75+
$this->assertNull($object->getWriterPart('foo'));
76+
}
77+
78+
/**
79+
* Test get PHPPowerPoint exception
80+
*
81+
* @expectedException Exception
82+
* @expectedExceptionMessage No PHPPowerPoint assigned.
83+
*/
84+
public function testGetPHPPowerPointException()
85+
{
86+
$object = new PHPPowerPoint_Writer_ODPresentation();
87+
$object->getPHPPowerPoint();
88+
}
89+
90+
/**
91+
* Test set/get disk caching
92+
*/
93+
public function testSetGetUseDiskCaching()
94+
{
95+
$object = new PHPPowerPoint_Writer_ODPresentation(new PHPPowerPoint());
96+
$this->assertFalse($object->getUseDiskCaching());
97+
98+
$object->setUseDiskCaching(true, sys_get_temp_dir());
99+
$this->assertTrue($object->getUseDiskCaching());
100+
$this->assertEquals(sys_get_temp_dir(), $object->getDiskCachingDirectory());
101+
}
102+
103+
/**
104+
* Test set/get disk caching exception
105+
*
106+
* @expectedException Exception
107+
*/
108+
public function testSetUseDiskCachingException()
109+
{
110+
$object = new PHPPowerPoint_Writer_ODPresentation(new PHPPowerPoint());
111+
$object->setUseDiskCaching(true, 'foo');
112+
}
113+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
}
4.74 KB
Loading

0 commit comments

Comments
 (0)