Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

v0.17.0 (?? ??? 2019)
----------------------
### Added

### Fixed

### Miscelaneous
- Use embedded http server to test loading of remote images @troosan #

v0.16.0 (30 dec 2018)
----------------------
### Added
Expand Down
6 changes: 4 additions & 2 deletions tests/PhpWord/Element/CellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;

/**
* Test class for PhpOffice\PhpWord\Element\Cell
*
* @runTestsInSeparateProcesses
*/
class CellTest extends \PHPUnit\Framework\TestCase
class CellTest extends AbstractWebServerEmbeddedTest
{
/**
* New instance
Expand Down Expand Up @@ -165,7 +167,7 @@ public function testAddImageFooter()
public function testAddImageSectionByUrl()
{
$oCell = new Cell();
$element = $oCell->addImage('http://php.net/images/logos/php-med-trans-light.gif');
$element = $oCell->addImage(self::getRemoteGifImageUrl());

$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
Expand Down
6 changes: 4 additions & 2 deletions tests/PhpWord/Element/FooterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;

/**
* Test class for PhpOffice\PhpWord\Element\Footer
*
* @runTestsInSeparateProcesses
*/
class FooterTest extends \PHPUnit\Framework\TestCase
class FooterTest extends AbstractWebServerEmbeddedTest
{
/**
* New instance
Expand Down Expand Up @@ -116,7 +118,7 @@ public function testAddImage()
public function testAddImageByUrl()
{
$oFooter = new Footer(1);
$element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif');
$element = $oFooter->addImage(self::getRemoteGifImageUrl());

$this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
Expand Down
6 changes: 4 additions & 2 deletions tests/PhpWord/Element/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;

/**
* Test class for PhpOffice\PhpWord\Element\Header
*
* @runTestsInSeparateProcesses
*/
class HeaderTest extends \PHPUnit\Framework\TestCase
class HeaderTest extends AbstractWebServerEmbeddedTest
{
/**
* New instance
Expand Down Expand Up @@ -125,7 +127,7 @@ public function testAddImage()
public function testAddImageByUrl()
{
$oHeader = new Header(1);
$element = $oHeader->addImage('http://php.net/images/logos/php-med-trans-light.gif');
$element = $oHeader->addImage(self::getRemoteGifImageUrl());

$this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);
Expand Down
9 changes: 5 additions & 4 deletions tests/PhpWord/Element/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
use PhpOffice\PhpWord\SimpleType\Jc;

/**
* Test class for PhpOffice\PhpWord\Element\Image
*
* @runTestsInSeparateProcesses
*/
class ImageTest extends \PHPUnit\Framework\TestCase
class ImageTest extends AbstractWebServerEmbeddedTest
{
/**
* New instance
Expand Down Expand Up @@ -131,15 +132,15 @@ public function testInvalidImagePhp()
*/
public function testUnsupportedImage()
{
//disable ssl verification, never do this in real application, you should pass the certiciate instead!!!
//disable ssl verification, never do this in real application, you should pass the certificiate instead!!!
$arrContextOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
),
);
stream_context_set_default($arrContextOptions);
$object = new Image('https://samples.libav.org/image-samples/RACECAR.BMP');
$object = new Image(self::getRemoteBmpImageUrl());
$object->getSource();
}

Expand Down Expand Up @@ -215,7 +216,7 @@ public function testConstructFromString()
*/
public function testConstructFromGd()
{
$source = 'http://php.net/images/logos/php-icon.png';
$source = self::getRemoteImageUrl();

$image = new Image($source);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image);
Expand Down
8 changes: 4 additions & 4 deletions tests/PhpWord/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @runTestsInSeparateProcesses
*/
class MediaTest extends \PHPUnit\Framework\TestCase
class MediaTest extends AbstractWebServerEmbeddedTest
{
/**
* Get section media elements
Expand All @@ -49,7 +49,7 @@ public function testAddSectionMediaElement()
{
$local = __DIR__ . '/_files/images/mars.jpg';
$object = __DIR__ . '/_files/documents/sheet.xls';
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
$remote = self::getRemoteImageUrl();
Media::addElement('section', 'image', $local, new Image($local));
Media::addElement('section', 'image', $local, new Image($local));
Media::addElement('section', 'image', $remote, new Image($local));
Expand Down Expand Up @@ -77,7 +77,7 @@ public function testAddSectionLinkElement()
public function testAddHeaderMediaElement()
{
$local = __DIR__ . '/_files/images/mars.jpg';
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
$remote = self::getRemoteImageUrl();
Media::addElement('header1', 'image', $local, new Image($local));
Media::addElement('header1', 'image', $local, new Image($local));
Media::addElement('header1', 'image', $remote, new Image($remote));
Expand All @@ -92,7 +92,7 @@ public function testAddHeaderMediaElement()
public function testAddFooterMediaElement()
{
$local = __DIR__ . '/_files/images/mars.jpg';
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
$remote = self::getRemoteImageUrl();
Media::addElement('footer1', 'image', $local, new Image($local));
Media::addElement('footer1', 'image', $local, new Image($local));
Media::addElement('footer1', 'image', $remote, new Image($remote));
Expand Down
5 changes: 3 additions & 2 deletions tests/PhpWord/Shared/HtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace PhpOffice\PhpWord\Shared;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
Expand All @@ -27,7 +28,7 @@
* Test class for PhpOffice\PhpWord\Shared\Html
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Html
*/
class HtmlTest extends \PHPUnit\Framework\TestCase
class HtmlTest extends AbstractWebServerEmbeddedTest
{
/**
* Test unit conversion functions with various numbers
Expand Down Expand Up @@ -487,7 +488,7 @@ public function testParseImage()
*/
public function testParseRemoteImage()
{
$src = 'https://phpword.readthedocs.io/en/latest/_images/phpword.png';
$src = self::getRemoteImageUrl();

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
Expand Down
5 changes: 3 additions & 2 deletions tests/PhpWord/Writer/HTMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace PhpOffice\PhpWord\Writer;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\SimpleType\Jc;
Expand All @@ -26,7 +27,7 @@
*
* @runTestsInSeparateProcesses
*/
class HTMLTest extends \PHPUnit\Framework\TestCase
class HTMLTest extends AbstractWebServerEmbeddedTest
{
/**
* Construct
Expand Down Expand Up @@ -57,7 +58,7 @@ public function testSave()
{
$localImage = __DIR__ . '/../_files/images/PhpWord.png';
$archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg';
$gdImage = 'http://php.net/images/logos/php-med-trans-light.gif';
$gdImage = self::getRemoteGifImageUrl();
$objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
$file = __DIR__ . '/../_files/temp.html';

Expand Down
5 changes: 3 additions & 2 deletions tests/PhpWord/Writer/Word2007Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace PhpOffice\PhpWord\Writer;

use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\SimpleType\Jc;
use PhpOffice\PhpWord\TestHelperDOCX;
Expand All @@ -26,7 +27,7 @@
*
* @runTestsInSeparateProcesses
*/
class Word2007Test extends \PHPUnit\Framework\TestCase
class Word2007Test extends AbstractWebServerEmbeddedTest
{
/**
* Tear down after each test
Expand Down Expand Up @@ -75,7 +76,7 @@ public function testConstruct()
public function testSave()
{
$localImage = __DIR__ . '/../_files/images/earth.jpg';
$remoteImage = 'http://php.net/images/logos/new-php-logo.png';
$remoteImage = self::getRemoteGifImageUrl();
$phpWord = new PhpWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
Expand Down
Binary file added tests/PhpWord/_files/images/new-php-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions tests/PhpWord/_includes/AbstractWebServerEmbeddedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWord;

use Symfony\Component\Process\Process;

abstract class AbstractWebServerEmbeddedTest extends \PHPUnit\Framework\TestCase
{
private static $httpServer;

public static function setUpBeforeClass()
{
if (self::isBuiltinServerSupported()) {
self::$httpServer = new Process('php -S localhost:8080 -t tests/PhpWord/_files');
self::$httpServer->start();
while (!self::$httpServer->isRunning()) {
usleep(1000);
}
}
}

public static function tearDownAfterClass()
{
if (self::isBuiltinServerSupported()) {
self::$httpServer->stop();
}
}

protected static function getBaseUrl()
{
return 'http://localhost:8080';
}

protected static function getRemoteImageUrl()
{
if (self::$httpServer) {
return self::getBaseUrl() . '/images/new-php-logo.png';
}

return 'http://php.net/images/logos/new-php-logo.png';
}

protected static function getRemoteGifImageUrl()
{
if (self::$httpServer) {
return self::getBaseUrl() . '/images/mario.gif';
}

return 'http://php.net/images/logos/php-med-trans-light.gif';
}

protected static function getRemoteBmpImageUrl()
{
if (self::$httpServer) {
return self::getBaseUrl() . '/images/duke_nukem.bmp';
}

return 'https://samples.libav.org/image-samples/RACECAR.BMP';
}

private static function isBuiltinServerSupported()
{
return version_compare(PHP_VERSION, '5.4.0', '>=');
}
}