Skip to content

Commit 4d76bae

Browse files
authored
Merge pull request #1544 from troosan/avoid_remote_image_loading_during_tests
Use embedded http server to test loading of remote images
2 parents 7b7d4e4 + c408ac5 commit 4d76bae

File tree

11 files changed

+119
-20
lines changed

11 files changed

+119
-20
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ Change Log
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
v0.17.0 (?? ??? 2019)
7+
----------------------
8+
### Added
9+
10+
### Fixed
11+
12+
### Miscelaneous
13+
- Use embedded http server to test loading of remote images @troosan #
14+
615
v0.16.0 (30 dec 2018)
716
----------------------
817
### Added

tests/PhpWord/Element/CellTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
21+
2022
/**
2123
* Test class for PhpOffice\PhpWord\Element\Cell
2224
*
2325
* @runTestsInSeparateProcesses
2426
*/
25-
class CellTest extends \PHPUnit\Framework\TestCase
27+
class CellTest extends AbstractWebServerEmbeddedTest
2628
{
2729
/**
2830
* New instance
@@ -165,7 +167,7 @@ public function testAddImageFooter()
165167
public function testAddImageSectionByUrl()
166168
{
167169
$oCell = new Cell();
168-
$element = $oCell->addImage('http://php.net/images/logos/php-med-trans-light.gif');
170+
$element = $oCell->addImage(self::getRemoteGifImageUrl());
169171

170172
$this->assertCount(1, $oCell->getElements());
171173
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);

tests/PhpWord/Element/FooterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
21+
2022
/**
2123
* Test class for PhpOffice\PhpWord\Element\Footer
2224
*
2325
* @runTestsInSeparateProcesses
2426
*/
25-
class FooterTest extends \PHPUnit\Framework\TestCase
27+
class FooterTest extends AbstractWebServerEmbeddedTest
2628
{
2729
/**
2830
* New instance
@@ -116,7 +118,7 @@ public function testAddImage()
116118
public function testAddImageByUrl()
117119
{
118120
$oFooter = new Footer(1);
119-
$element = $oFooter->addImage('http://php.net/images/logos/php-med-trans-light.gif');
121+
$element = $oFooter->addImage(self::getRemoteGifImageUrl());
120122

121123
$this->assertCount(1, $oFooter->getElements());
122124
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);

tests/PhpWord/Element/HeaderTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
21+
2022
/**
2123
* Test class for PhpOffice\PhpWord\Element\Header
2224
*
2325
* @runTestsInSeparateProcesses
2426
*/
25-
class HeaderTest extends \PHPUnit\Framework\TestCase
27+
class HeaderTest extends AbstractWebServerEmbeddedTest
2628
{
2729
/**
2830
* New instance
@@ -125,7 +127,7 @@ public function testAddImage()
125127
public function testAddImageByUrl()
126128
{
127129
$oHeader = new Header(1);
128-
$element = $oHeader->addImage('http://php.net/images/logos/php-med-trans-light.gif');
130+
$element = $oHeader->addImage(self::getRemoteGifImageUrl());
129131

130132
$this->assertCount(1, $oHeader->getElements());
131133
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $element);

tests/PhpWord/Element/ImageTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717

1818
namespace PhpOffice\PhpWord\Element;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
2021
use PhpOffice\PhpWord\SimpleType\Jc;
2122

2223
/**
2324
* Test class for PhpOffice\PhpWord\Element\Image
2425
*
2526
* @runTestsInSeparateProcesses
2627
*/
27-
class ImageTest extends \PHPUnit\Framework\TestCase
28+
class ImageTest extends AbstractWebServerEmbeddedTest
2829
{
2930
/**
3031
* New instance
@@ -131,15 +132,15 @@ public function testInvalidImagePhp()
131132
*/
132133
public function testUnsupportedImage()
133134
{
134-
//disable ssl verification, never do this in real application, you should pass the certiciate instead!!!
135+
//disable ssl verification, never do this in real application, you should pass the certificiate instead!!!
135136
$arrContextOptions = array(
136137
'ssl' => array(
137138
'verify_peer' => false,
138139
'verify_peer_name' => false,
139140
),
140141
);
141142
stream_context_set_default($arrContextOptions);
142-
$object = new Image('https://samples.libav.org/image-samples/RACECAR.BMP');
143+
$object = new Image(self::getRemoteBmpImageUrl());
143144
$object->getSource();
144145
}
145146

@@ -215,7 +216,7 @@ public function testConstructFromString()
215216
*/
216217
public function testConstructFromGd()
217218
{
218-
$source = 'http://php.net/images/logos/php-icon.png';
219+
$source = self::getRemoteImageUrl();
219220

220221
$image = new Image($source);
221222
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $image);

tests/PhpWord/MediaTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @runTestsInSeparateProcesses
2626
*/
27-
class MediaTest extends \PHPUnit\Framework\TestCase
27+
class MediaTest extends AbstractWebServerEmbeddedTest
2828
{
2929
/**
3030
* Get section media elements
@@ -49,7 +49,7 @@ public function testAddSectionMediaElement()
4949
{
5050
$local = __DIR__ . '/_files/images/mars.jpg';
5151
$object = __DIR__ . '/_files/documents/sheet.xls';
52-
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
52+
$remote = self::getRemoteImageUrl();
5353
Media::addElement('section', 'image', $local, new Image($local));
5454
Media::addElement('section', 'image', $local, new Image($local));
5555
Media::addElement('section', 'image', $remote, new Image($local));
@@ -77,7 +77,7 @@ public function testAddSectionLinkElement()
7777
public function testAddHeaderMediaElement()
7878
{
7979
$local = __DIR__ . '/_files/images/mars.jpg';
80-
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
80+
$remote = self::getRemoteImageUrl();
8181
Media::addElement('header1', 'image', $local, new Image($local));
8282
Media::addElement('header1', 'image', $local, new Image($local));
8383
Media::addElement('header1', 'image', $remote, new Image($remote));
@@ -92,7 +92,7 @@ public function testAddHeaderMediaElement()
9292
public function testAddFooterMediaElement()
9393
{
9494
$local = __DIR__ . '/_files/images/mars.jpg';
95-
$remote = 'http://php.net/images/logos/php-med-trans-light.gif';
95+
$remote = self::getRemoteImageUrl();
9696
Media::addElement('footer1', 'image', $local, new Image($local));
9797
Media::addElement('footer1', 'image', $local, new Image($local));
9898
Media::addElement('footer1', 'image', $remote, new Image($remote));

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Shared;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
2021
use PhpOffice\PhpWord\Element\Section;
2122
use PhpOffice\PhpWord\SimpleType\Jc;
2223
use PhpOffice\PhpWord\SimpleType\LineSpacingRule;
@@ -27,7 +28,7 @@
2728
* Test class for PhpOffice\PhpWord\Shared\Html
2829
* @coversDefaultClass \PhpOffice\PhpWord\Shared\Html
2930
*/
30-
class HtmlTest extends \PHPUnit\Framework\TestCase
31+
class HtmlTest extends AbstractWebServerEmbeddedTest
3132
{
3233
/**
3334
* Test unit conversion functions with various numbers
@@ -487,7 +488,7 @@ public function testParseImage()
487488
*/
488489
public function testParseRemoteImage()
489490
{
490-
$src = 'https://phpword.readthedocs.io/en/latest/_images/phpword.png';
491+
$src = self::getRemoteImageUrl();
491492

492493
$phpWord = new \PhpOffice\PhpWord\PhpWord();
493494
$section = $phpWord->addSection();

tests/PhpWord/Writer/HTMLTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Writer;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
2021
use PhpOffice\PhpWord\PhpWord;
2122
use PhpOffice\PhpWord\Settings;
2223
use PhpOffice\PhpWord\SimpleType\Jc;
@@ -26,7 +27,7 @@
2627
*
2728
* @runTestsInSeparateProcesses
2829
*/
29-
class HTMLTest extends \PHPUnit\Framework\TestCase
30+
class HTMLTest extends AbstractWebServerEmbeddedTest
3031
{
3132
/**
3233
* Construct
@@ -57,7 +58,7 @@ public function testSave()
5758
{
5859
$localImage = __DIR__ . '/../_files/images/PhpWord.png';
5960
$archiveImage = 'zip://' . __DIR__ . '/../_files/documents/reader.docx#word/media/image1.jpeg';
60-
$gdImage = 'http://php.net/images/logos/php-med-trans-light.gif';
61+
$gdImage = self::getRemoteGifImageUrl();
6162
$objectSrc = __DIR__ . '/../_files/documents/sheet.xls';
6263
$file = __DIR__ . '/../_files/temp.html';
6364

tests/PhpWord/Writer/Word2007Test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace PhpOffice\PhpWord\Writer;
1919

20+
use PhpOffice\PhpWord\AbstractWebServerEmbeddedTest;
2021
use PhpOffice\PhpWord\PhpWord;
2122
use PhpOffice\PhpWord\SimpleType\Jc;
2223
use PhpOffice\PhpWord\TestHelperDOCX;
@@ -26,7 +27,7 @@
2627
*
2728
* @runTestsInSeparateProcesses
2829
*/
29-
class Word2007Test extends \PHPUnit\Framework\TestCase
30+
class Word2007Test extends AbstractWebServerEmbeddedTest
3031
{
3132
/**
3233
* Tear down after each test
@@ -75,7 +76,7 @@ public function testConstruct()
7576
public function testSave()
7677
{
7778
$localImage = __DIR__ . '/../_files/images/earth.jpg';
78-
$remoteImage = 'http://php.net/images/logos/new-php-logo.png';
79+
$remoteImage = self::getRemoteGifImageUrl();
7980
$phpWord = new PhpWord();
8081
$phpWord->addFontStyle('Font', array('size' => 11));
8182
$phpWord->addParagraphStyle('Paragraph', array('alignment' => Jc::CENTER));
10.1 KB
Loading

0 commit comments

Comments
 (0)