Skip to content

Commit 088247d

Browse files
committed
#123 : Support for Video (Unit tests)
1 parent 5fe42ae commit 088247d

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PhpPresentation\Tests\Shape;
4+
5+
use PhpOffice\PhpPresentation\Shape\Media;
6+
7+
class MediaTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testInheritance()
10+
{
11+
$object = new Media();
12+
13+
$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing', $object);
14+
}
15+
}

tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
namespace PhpOffice\PhpPresentation\Tests\Writer\ODPresentation;
1919

2020
use PhpOffice\Common\Drawing as CommonDrawing;
21+
use PhpOffice\Common\Text;
2122
use PhpOffice\PhpPresentation\PhpPresentation;
2223
use PhpOffice\PhpPresentation\Shape\Comment;
24+
use PhpOffice\PhpPresentation\Shape\Media;
2325
use PhpOffice\PhpPresentation\Shape\RichText\Run;
2426
use PhpOffice\PhpPresentation\Slide\Transition;
2527
use PhpOffice\PhpPresentation\Style\Alignment;
@@ -257,6 +259,47 @@ public function testListWithRichText()
257259
$this->assertTrue($pres->elementExists($element, 'content.xml'));
258260
}
259261

262+
public function testMedia()
263+
{
264+
$expectedName = 'MyName';
265+
$expectedWidth = rand(1, 100);
266+
$expectedHeight = rand(1, 100);
267+
$expectedX = rand(1, 100);
268+
$expectedY = rand(1, 100);
269+
270+
$oMedia = new Media();
271+
$oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
272+
->setName($expectedName)
273+
->setResizeProportional(false)
274+
->setHeight($expectedHeight)
275+
->setWidth($expectedWidth)
276+
->setOffsetX($expectedX)
277+
->setOffsetY($expectedY);
278+
279+
$expectedWidth = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedWidth), 3) . 'cm';
280+
$expectedHeight = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedHeight), 3) . 'cm';
281+
$expectedX = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedX), 3) . 'cm';
282+
$expectedY = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedY), 3) . 'cm';
283+
284+
$oPhpPresentation = new PhpPresentation();
285+
$oSlide = $oPhpPresentation->getActiveSlide();
286+
$oSlide->addShape($oMedia);
287+
288+
$xmlObject = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
289+
$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame';
290+
$this->assertTrue($xmlObject->elementExists($element, 'content.xml'));
291+
$this->assertEquals($expectedName, $xmlObject->getElementAttribute($element, 'draw:name', 'content.xml'));
292+
$this->assertEquals($expectedWidth, $xmlObject->getElementAttribute($element, 'svg:width', 'content.xml'));
293+
$this->assertEquals($expectedHeight, $xmlObject->getElementAttribute($element, 'svg:height', 'content.xml'));
294+
$this->assertEquals($expectedX, $xmlObject->getElementAttribute($element, 'svg:x', 'content.xml'));
295+
$this->assertEquals($expectedY, $xmlObject->getElementAttribute($element, 'svg:y', 'content.xml'));
296+
$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:plugin';
297+
$this->assertTrue($xmlObject->elementExists($element, 'content.xml'));
298+
$this->assertEquals('application/vnd.sun.star.media', $xmlObject->getElementAttribute($element, 'draw:mime-type', 'content.xml'));
299+
$this->assertStringStartsWith('Pictures/', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml'));
300+
$this->assertStringEndsWith('ogv', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml'));
301+
}
302+
260303
public function testNote()
261304
{
262305
$oPhpPresentation = new PhpPresentation();

tests/PhpPresentation/Tests/Writer/PowerPoint2007/PptSlidesTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpOffice\PhpPresentation\PhpPresentation;
2222
use PhpOffice\PhpPresentation\Shape\Comment;
2323
use PhpOffice\PhpPresentation\Shape\Group;
24+
use PhpOffice\PhpPresentation\Shape\Media;
2425
use PhpOffice\PhpPresentation\Shape\RichText;
2526
use PhpOffice\PhpPresentation\Style\Alignment;
2627
use PhpOffice\PhpPresentation\Style\Bullet;
@@ -470,6 +471,39 @@ public function testLine()
470471
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
471472
}
472473

474+
public function testMedia()
475+
{
476+
$expectedName = 'MyName';
477+
$expectedWidth = rand(1, 100);
478+
$expectedHeight = rand(1, 100);
479+
$expectedX = rand(1, 100);
480+
$expectedY = rand(1, 100);
481+
482+
$oMedia = new Media();
483+
$oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
484+
->setName($expectedName)
485+
->setResizeProportional(false)
486+
->setHeight($expectedHeight)
487+
->setWidth($expectedWidth)
488+
->setOffsetX($expectedX)
489+
->setOffsetY($expectedY);
490+
491+
$oPhpPresentation = new PhpPresentation();
492+
$oSlide = $oPhpPresentation->getActiveSlide();
493+
$oSlide->addShape($oMedia);
494+
495+
$xmlObject = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
496+
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr';
497+
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
498+
$this->assertEquals($expectedName, $xmlObject->getElementAttribute($element, 'name', 'ppt/slides/slide1.xml'));
499+
500+
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/a:videoFile';
501+
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
502+
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/p:extLst/p:ext';
503+
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
504+
$this->assertEquals('{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}', $xmlObject->getElementAttribute($element, 'uri', 'ppt/slides/slide1.xml'));
505+
}
506+
473507
public function testNote()
474508
{
475509
$oPhpPresentation = new PhpPresentation();
4.17 MB
Binary file not shown.
12.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)