2014-02-24 19:17:06 +01:00
|
|
|
<?php
|
2014-03-27 23:55:06 +07:00
|
|
|
/**
|
2014-05-05 13:06:53 +04:00
|
|
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
|
|
|
|
* word processing documents.
|
|
|
|
|
*
|
|
|
|
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
|
|
|
* General Public License version 3 as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please read the LICENSE
|
|
|
|
|
* file that was distributed with this source code. For the full list of
|
|
|
|
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
2014-03-27 23:55:06 +07:00
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
2014-05-05 12:38:31 +04:00
|
|
|
* @copyright 2010-2014 PHPWord contributors
|
2014-05-04 21:03:28 +04:00
|
|
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
2014-03-27 23:55:06 +07:00
|
|
|
*/
|
|
|
|
|
|
2014-03-23 11:59:22 -04:00
|
|
|
namespace PhpOffice\PhpWord\Tests;
|
2014-02-24 19:17:06 +01:00
|
|
|
|
2014-03-31 01:13:02 +07:00
|
|
|
use PhpOffice\PhpWord\Element\Image;
|
2014-05-04 21:03:28 +04:00
|
|
|
use PhpOffice\PhpWord\Media;
|
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()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$this->assertEquals(array(), Media::getElements('section'));
|
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-06-20 09:34:49 +04:00
|
|
|
$this->assertEquals(0, Media::countElements('section'));
|
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()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$local = __DIR__ . '/_files/images/mars.jpg';
|
|
|
|
|
$object = __DIR__ . '/_files/documents/sheet.xls';
|
2014-03-28 13:50:53 +07:00
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-05 19:02:49 +07:00
|
|
|
Media::addElement('section', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('section', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('section', 'image', $remote, new Image($local));
|
|
|
|
|
Media::addElement('section', 'object', $object);
|
|
|
|
|
Media::addElement('section', 'object', $object);
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(3, Media::getElements('section'));
|
2014-03-28 13:50:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add section link
|
|
|
|
|
*/
|
|
|
|
|
public function testAddSectionLinkElement()
|
|
|
|
|
{
|
2014-04-05 19:02:49 +07:00
|
|
|
$expected = Media::countElements('section') + 1;
|
|
|
|
|
$actual = Media::addElement('section', 'link', 'http://test.com');
|
2014-03-28 13:50:53 +07:00
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(1, Media::getElements('section', 'link'));
|
2014-03-28 13:50:53 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add header media element
|
|
|
|
|
*/
|
|
|
|
|
public function testAddHeaderMediaElement()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$local = __DIR__ . '/_files/images/mars.jpg';
|
2014-03-28 13:50:53 +07:00
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-05 19:02:49 +07:00
|
|
|
Media::addElement('header1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('header1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('header1', 'image', $remote, new Image($remote));
|
2014-03-28 13:50:53 +07:00
|
|
|
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(2, Media::getElements('header1'));
|
2014-04-05 19:02:49 +07:00
|
|
|
$this->assertEmpty(Media::getElements('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()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
$local = __DIR__ . '/_files/images/mars.jpg';
|
2014-03-28 13:50:53 +07:00
|
|
|
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
|
2014-04-05 19:02:49 +07:00
|
|
|
Media::addElement('footer1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('footer1', 'image', $local, new Image($local));
|
|
|
|
|
Media::addElement('footer1', 'image', $remote, new Image($remote));
|
2014-03-12 09:25:21 -04:00
|
|
|
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(2, Media::getElements('footer1'));
|
2014-04-05 00:57:50 +07:00
|
|
|
|
2014-04-08 16:09:31 +07:00
|
|
|
Media::resetElements();
|
2014-06-20 09:34:49 +04:00
|
|
|
$this->assertCount(0, Media::getElements('footer1'));
|
2014-04-05 19:02:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add image element exception
|
|
|
|
|
*
|
|
|
|
|
* @expectedException Exception
|
|
|
|
|
* @expectedExceptionMessage Image object not assigned.
|
|
|
|
|
*/
|
|
|
|
|
public function testAddElementImageException()
|
|
|
|
|
{
|
2015-02-06 22:28:31 +04:00
|
|
|
Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg');
|
2014-03-12 09:25:21 -04:00
|
|
|
}
|
2014-03-23 17:37:26 +07:00
|
|
|
}
|