Skip to content

Commit

Permalink
PHPOffice#123 : Support for Video (Unit tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Mar 31, 2016
1 parent 5fe42ae commit 088247d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/PhpPresentation/Tests/Shape/MediaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace PhpPresentation\Tests\Shape;

use PhpOffice\PhpPresentation\Shape\Media;

class MediaTest extends \PHPUnit_Framework_TestCase
{
public function testInheritance()
{
$object = new Media();

$this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing', $object);
}
}
43 changes: 43 additions & 0 deletions tests/PhpPresentation/Tests/Writer/ODPresentation/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
namespace PhpOffice\PhpPresentation\Tests\Writer\ODPresentation;

use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\Common\Text;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Comment;
use PhpOffice\PhpPresentation\Shape\Media;
use PhpOffice\PhpPresentation\Shape\RichText\Run;
use PhpOffice\PhpPresentation\Slide\Transition;
use PhpOffice\PhpPresentation\Style\Alignment;
Expand Down Expand Up @@ -257,6 +259,47 @@ public function testListWithRichText()
$this->assertTrue($pres->elementExists($element, 'content.xml'));
}

public function testMedia()
{
$expectedName = 'MyName';
$expectedWidth = rand(1, 100);
$expectedHeight = rand(1, 100);
$expectedX = rand(1, 100);
$expectedY = rand(1, 100);

$oMedia = new Media();
$oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
->setName($expectedName)
->setResizeProportional(false)
->setHeight($expectedHeight)
->setWidth($expectedWidth)
->setOffsetX($expectedX)
->setOffsetY($expectedY);

$expectedWidth = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedWidth), 3) . 'cm';
$expectedHeight = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedHeight), 3) . 'cm';
$expectedX = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedX), 3) . 'cm';
$expectedY = Text::numberFormat(CommonDrawing::pixelsToCentimeters($expectedY), 3) . 'cm';

$oPhpPresentation = new PhpPresentation();
$oSlide = $oPhpPresentation->getActiveSlide();
$oSlide->addShape($oMedia);

$xmlObject = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame';
$this->assertTrue($xmlObject->elementExists($element, 'content.xml'));
$this->assertEquals($expectedName, $xmlObject->getElementAttribute($element, 'draw:name', 'content.xml'));
$this->assertEquals($expectedWidth, $xmlObject->getElementAttribute($element, 'svg:width', 'content.xml'));
$this->assertEquals($expectedHeight, $xmlObject->getElementAttribute($element, 'svg:height', 'content.xml'));
$this->assertEquals($expectedX, $xmlObject->getElementAttribute($element, 'svg:x', 'content.xml'));
$this->assertEquals($expectedY, $xmlObject->getElementAttribute($element, 'svg:y', 'content.xml'));
$element = '/office:document-content/office:body/office:presentation/draw:page/draw:frame/draw:plugin';
$this->assertTrue($xmlObject->elementExists($element, 'content.xml'));
$this->assertEquals('application/vnd.sun.star.media', $xmlObject->getElementAttribute($element, 'draw:mime-type', 'content.xml'));
$this->assertStringStartsWith('Pictures/', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml'));
$this->assertStringEndsWith('ogv', $xmlObject->getElementAttribute($element, 'xlink:href', 'content.xml'));
}

public function testNote()
{
$oPhpPresentation = new PhpPresentation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Comment;
use PhpOffice\PhpPresentation\Shape\Group;
use PhpOffice\PhpPresentation\Shape\Media;
use PhpOffice\PhpPresentation\Shape\RichText;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Bullet;
Expand Down Expand Up @@ -470,6 +471,39 @@ public function testLine()
$this->assertTrue($pres->elementExists($element, 'ppt/slides/slide1.xml'));
}

public function testMedia()
{
$expectedName = 'MyName';
$expectedWidth = rand(1, 100);
$expectedHeight = rand(1, 100);
$expectedX = rand(1, 100);
$expectedY = rand(1, 100);

$oMedia = new Media();
$oMedia->setPath(PHPPRESENTATION_TESTS_BASE_DIR . '/resources/videos/sintel_trailer-480p.ogv')
->setName($expectedName)
->setResizeProportional(false)
->setHeight($expectedHeight)
->setWidth($expectedWidth)
->setOffsetX($expectedX)
->setOffsetY($expectedY);

$oPhpPresentation = new PhpPresentation();
$oSlide = $oPhpPresentation->getActiveSlide();
$oSlide->addShape($oMedia);

$xmlObject = TestHelperDOCX::getDocument($oPhpPresentation, 'PowerPoint2007');
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:cNvPr';
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
$this->assertEquals($expectedName, $xmlObject->getElementAttribute($element, 'name', 'ppt/slides/slide1.xml'));

$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/a:videoFile';
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
$element = '/p:sld/p:cSld/p:spTree/p:pic/p:nvPicPr/p:nvPr/p:extLst/p:ext';
$this->assertTrue($xmlObject->elementExists($element, 'ppt/slides/slide1.xml'));
$this->assertEquals('{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}', $xmlObject->getElementAttribute($element, 'uri', 'ppt/slides/slide1.xml'));
}

public function testNote()
{
$oPhpPresentation = new PhpPresentation();
Expand Down
Binary file added tests/resources/videos/sintel_trailer-480p.mp4
Binary file not shown.
Binary file added tests/resources/videos/sintel_trailer-480p.ogv
Binary file not shown.

0 comments on commit 088247d

Please sign in to comment.