|
18 | 18 | namespace PhpOffice\PhpPresentation\Tests\Writer\ODPresentation;
|
19 | 19 |
|
20 | 20 | use PhpOffice\Common\Drawing as CommonDrawing;
|
| 21 | +use PhpOffice\Common\Text; |
21 | 22 | use PhpOffice\PhpPresentation\PhpPresentation;
|
22 | 23 | use PhpOffice\PhpPresentation\Shape\Comment;
|
| 24 | +use PhpOffice\PhpPresentation\Shape\Media; |
23 | 25 | use PhpOffice\PhpPresentation\Shape\RichText\Run;
|
24 | 26 | use PhpOffice\PhpPresentation\Slide\Transition;
|
25 | 27 | use PhpOffice\PhpPresentation\Style\Alignment;
|
@@ -257,6 +259,47 @@ public function testListWithRichText()
|
257 | 259 | $this->assertTrue($pres->elementExists($element, 'content.xml'));
|
258 | 260 | }
|
259 | 261 |
|
| 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 | + |
260 | 303 | public function testNote()
|
261 | 304 | {
|
262 | 305 | $oPhpPresentation = new PhpPresentation();
|
|
0 commit comments