2014-02-24 19:17:06 +01:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
|
*/
|
|
|
|
|
|
2014-03-23 11:59:22 -04:00
|
|
|
namespace PhpOffice\PhpWord\Tests;
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-18 17:26:03 +04:00
|
|
|
use PhpOffice\PhpWord\Media;
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Container\Section;
|
|
|
|
|
use PhpOffice\PhpWord\Element\Image;
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
|
|
|
|
* Test class for PhpOffice\PhpWord\Media
|
|
|
|
|
*
|
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
|
*/
|
2014-03-09 14:18:49 -04:00
|
|
|
class MediaTest extends \PHPUnit_Framework_TestCase
|
2014-03-02 14:40:58 -05:00
|
|
|
{
|
2014-03-28 13:50:53 +07:00
|
|
|
/**
|
|
|
|
|
* Get section media elements
|
|
|
|
|
*/
|
2014-03-02 14:40:58 -05:00
|
|
|
public function testGetSectionMediaElementsWithNull()
|
|
|
|
|
{
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(Media::getMediaElements('section'), array());
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-28 13:50:53 +07:00
|
|
|
/**
|
|
|
|
|
* Count section media elements
|
|
|
|
|
*/
|
2014-03-02 14:40:58 -05:00
|
|
|
public function testCountSectionMediaElementsWithNull()
|
|
|
|
|
{
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(Media::countMediaElements('section'), 0);
|
2014-03-02 14:40:58 -05:00
|
|
|
}
|
2014-03-12 09:25:21 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-03-28 13:50:53 +07:00
|
|
|
* Add section media element
|
2014-03-12 09:25:21 -04:00
|
|
|
*/
|
|
|
|
|
public function testAddSectionMediaElement()
|
|
|
|
|
{
|
2014-03-28 13:50:53 +07:00
|
|
|
$local = __DIR__ . "/_files/images/mars.jpg";
|
|
|
|
|
$object = __DIR__ . "/_files/documents/sheet.xls";
|
|
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-04 00:29:57 +07:00
|
|
|
Media::addMediaElement('section', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('section', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('section', 'image', $remote, new Image($local));
|
|
|
|
|
Media::addMediaElement('section', 'object', $object);
|
|
|
|
|
Media::addMediaElement('section', 'object', $object);
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(3, Media::countMediaElements('section'));
|
2014-03-28 13:50:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add section link
|
|
|
|
|
*/
|
|
|
|
|
public function testAddSectionLinkElement()
|
|
|
|
|
{
|
2014-04-04 00:29:57 +07:00
|
|
|
$expected = Media::countMediaElements('section') + 1;
|
|
|
|
|
$actual = Media::addMediaElement('section', 'link', 'http://test.com');
|
2014-03-28 13:50:53 +07:00
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(1, Media::countMediaElements('section', 'link'));
|
|
|
|
|
$this->assertEquals(1, count(Media::getMediaElements('section', 'link')));
|
2014-03-28 13:50:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add header media element
|
|
|
|
|
*/
|
|
|
|
|
public function testAddHeaderMediaElement()
|
|
|
|
|
{
|
|
|
|
|
$local = __DIR__ . "/_files/images/mars.jpg";
|
|
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-04 00:29:57 +07:00
|
|
|
Media::addMediaElement('header1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('header1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('header1', 'image', $remote, new Image($remote));
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(2, Media::countMediaElements('header1'));
|
2014-04-01 19:05:07 +07:00
|
|
|
$this->assertEquals(2, count(Media::getMediaElements('header1')));
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEmpty(Media::getMediaElements('header2'));
|
2014-03-28 13:50:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-05 00:57:50 +07:00
|
|
|
* Add footer media element and reset media
|
2014-03-28 13:50:53 +07:00
|
|
|
*/
|
|
|
|
|
public function testAddFooterMediaElement()
|
|
|
|
|
{
|
|
|
|
|
$local = __DIR__ . "/_files/images/mars.jpg";
|
|
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-04 00:29:57 +07:00
|
|
|
Media::addMediaElement('footer1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('footer1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addMediaElement('footer1', 'image', $remote, new Image($remote));
|
2014-03-12 09:25:21 -04:00
|
|
|
|
2014-04-04 00:29:57 +07:00
|
|
|
$this->assertEquals(2, Media::countMediaElements('footer1'));
|
2014-04-05 00:57:50 +07:00
|
|
|
|
|
|
|
|
Media::reset();
|
|
|
|
|
$this->assertEquals(0, Media::countMediaElements('footer1'));
|
2014-03-12 09:25:21 -04:00
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|