PHPWord/tests/PhpWord/MediaTest.php

117 lines
3.7 KiB
PHP
Raw Normal View History

2014-02-24 19:17:06 +01:00
<?php
2014-03-27 23:55:06 +07: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
2015-12-05 21:25:59 +04:00
* @copyright 2010-2015 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
*/
2015-11-15 13:33:05 +04:00
namespace PhpOffice\PhpWord;
2014-02-24 19:17:06 +01:00
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
*/
class MediaTest extends \PHPUnit_Framework_TestCase
{
2014-03-28 13:50:53 +07:00
/**
* Get section media elements
*/
public function testGetSectionMediaElementsWithNull()
{
$this->assertEquals(array(), Media::getElements('section'));
}
2014-02-24 19:17:06 +01:00
2014-03-28 13:50:53 +07:00
/**
* Count section media elements
*/
public function testCountSectionMediaElementsWithNull()
{
$this->assertEquals(0, Media::countElements('section'));
}
/**
2014-03-28 13:50:53 +07:00
* Add section media element
*/
public function testAddSectionMediaElement()
{
$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
$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);
$this->assertCount(1, Media::getElements('section', 'link'));
2014-03-28 13:50:53 +07:00
}
/**
* Add header media element
*/
public function testAddHeaderMediaElement()
{
$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
$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
}
/**
* Add footer media element and reset media
2014-03-28 13:50:53 +07:00
*/
public function testAddFooterMediaElement()
{
$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));
$this->assertCount(2, Media::getElements('footer1'));
Media::resetElements();
$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()
{
Media::addElement('section', 'image', __DIR__ . '/_files/images/mars.jpg');
}
}