Skip to content

Commit 1ce9654

Browse files
committed
#161 : Unit Tests
1 parent 3afb967 commit 1ce9654

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

tests/PhpPresentation/Tests/Reader/PowerPoint2007Test.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,4 +494,17 @@ public function testZoom()
494494
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
495495
$this->assertEquals(2.68, $oPhpPresentation->getZoom());
496496
}
497+
498+
public function testSlideLayout()
499+
{
500+
$file = PHPPRESENTATION_TESTS_BASE_DIR . '/resources/files/Issue_00150.pptx';
501+
$object = new PowerPoint2007();
502+
$oPhpPresentation = $object->load($file);
503+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\PhpPresentation', $oPhpPresentation);
504+
505+
$this->assertCount(3, $oPhpPresentation->getAllMasterSlides());
506+
$this->assertCount(11, $oPhpPresentation->getAllMasterSlides()[0]->getAllSlideLayouts());
507+
$this->assertCount(11, $oPhpPresentation->getAllMasterSlides()[1]->getAllSlideLayouts());
508+
$this->assertCount(11, $oPhpPresentation->getAllMasterSlides()[2]->getAllSlideLayouts());
509+
}
497510
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation 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/PHPPresentation/contributors.
12+
*
13+
* @copyright 2009-2015 PHPPresentation contributors
14+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15+
* @link https://github.com/PHPOffice/PHPPresentation
16+
*/
17+
18+
namespace PhpOffice\PhpPresentation\Tests;
19+
20+
use PhpOffice\PhpPresentation\Slide\SlideLayout;
21+
22+
/**
23+
* Test class for PhpPresentation
24+
*
25+
* @coversDefaultClass PhpOffice\PhpPresentation\Slide\SlideLayout
26+
*/
27+
class SlideLayoutTest extends \PHPUnit_Framework_TestCase
28+
{
29+
public function testBase()
30+
{
31+
$mockSlideMaster = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Slide\SlideMaster');
32+
33+
$object = new SlideLayout($mockSlideMaster);
34+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide', $object);
35+
$this->assertInstanceOf('\\ArrayObject', $object->getShapeCollection());
36+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\ColorMap', $object->colorMap);
37+
}
38+
39+
public function testLayoutName()
40+
{
41+
// Mocks
42+
$mockSlideMaster = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Slide\SlideMaster');
43+
44+
// Expected
45+
$expectedLayoutName = 'Title'.rand(1, 100);
46+
47+
$object = new SlideLayout($mockSlideMaster);
48+
49+
$this->assertNull($object->getLayoutName());
50+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideLayout', $object->setLayoutName($expectedLayoutName));
51+
$this->assertEquals($expectedLayoutName, $object->getLayoutName());
52+
}
53+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation 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/PHPPresentation/contributors.
12+
*
13+
* @copyright 2009-2015 PHPPresentation contributors
14+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15+
* @link https://github.com/PHPOffice/PHPPresentation
16+
*/
17+
18+
namespace PhpOffice\PhpPresentation\Tests;
19+
20+
use PhpOffice\PhpPresentation\Slide\SlideMaster;
21+
22+
/**
23+
* Test class for PhpPresentation
24+
*
25+
* @coversDefaultClass PhpOffice\PhpPresentation\Slide\SlideMaster
26+
*/
27+
class SlideMasterTest extends \PHPUnit_Framework_TestCase
28+
{
29+
public function testBase()
30+
{
31+
$object = new SlideMaster();
32+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\AbstractSlide', $object);
33+
$this->assertNull($object->getParent());
34+
$this->assertInstanceOf('\\ArrayObject', $object->getShapeCollection());
35+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\ColorMap', $object->colorMap);
36+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\Background\\Color', $object->getBackground());
37+
$this->assertEquals('FFFFFF', $object->getBackground()->getColor()->getRGB());
38+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->getTextStyles());
39+
}
40+
41+
public function testLayout()
42+
{
43+
$object = new SlideMaster();
44+
45+
// Mock Post
46+
$mockSlideLayout = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Slide\SlideLayout', array($object));
47+
48+
$this->assertEmpty($object->getAllSlideLayouts());
49+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideLayout', $object->createSlideLayout());
50+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideLayout', $object->addSlideLayout($mockSlideLayout));
51+
$this->assertCount(2, $object->getAllSlideLayouts());
52+
}
53+
54+
public function testSchemeColors()
55+
{
56+
// Mock Pre
57+
$mockSchemeColorAccent1 = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Style\SchemeColor');
58+
$mockSchemeColorAccent1->setValue('accent1');
59+
$mockSchemeColorAccent1->setRGB('ABCDEF');
60+
$mockSchemeColorNew = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Style\SchemeColor');
61+
$mockSchemeColorNew->setValue('new');
62+
$mockSchemeColorNew->setRGB('ABCDEF');
63+
64+
$object = new SlideMaster();
65+
66+
$this->assertInternalType('array', $object->getAllSchemeColors());
67+
$this->assertCount(12, $object->getAllSchemeColors());
68+
// Add idem value
69+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideMaster', $object->addSchemeColor($mockSchemeColorAccent1));
70+
$this->assertCount(12, $object->getAllSchemeColors());
71+
// Add new value
72+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideMaster', $object->addSchemeColor($mockSchemeColorNew));
73+
$this->assertCount(13, $object->getAllSchemeColors());
74+
75+
}
76+
77+
public function testTextStyles()
78+
{
79+
// Mock Pre
80+
$mockTextStyle = $this->getMockForAbstractClass('PhpOffice\PhpPresentation\Style\TextStyle');
81+
82+
$object = new SlideMaster();
83+
84+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->getTextStyles());
85+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Slide\\SlideMaster', $object->setTextStyles($mockTextStyle));
86+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Style\\TextStyle', $object->getTextStyles());
87+
}
88+
}
124 KB
Binary file not shown.

0 commit comments

Comments
 (0)