@@ -45,12 +45,38 @@ public function testURLImageSourceAllowed(): void
45
45
$ spreadsheet ->disconnectWorksheets ();
46
46
}
47
47
48
+ public function testURLImageSourceAllowedFlag (): void
49
+ {
50
+ if (getenv ('SKIP_URL_IMAGE_TEST ' ) === '1 ' ) {
51
+ self ::markTestSkipped ('Skipped due to setting of environment variable ' );
52
+ }
53
+ $ filename = realpath (__DIR__ . '/../../../data/Reader/XLSX/urlImage.xlsx ' );
54
+ self ::assertNotFalse ($ filename );
55
+ $ reader = IOFactory::createReader ('Xlsx ' );
56
+ $ spreadsheet = $ reader ->load ($ filename , XlsxReader::ALLOW_EXTERNAL_IMAGES );
57
+ $ worksheet = $ spreadsheet ->getActiveSheet ();
58
+ $ collection = $ worksheet ->getDrawingCollection ();
59
+ self ::assertCount (1 , $ collection );
60
+
61
+ foreach ($ collection as $ drawing ) {
62
+ self ::assertInstanceOf (Drawing::class, $ drawing );
63
+ // Check if the source is a URL or a file path
64
+ self ::assertTrue ($ drawing ->getIsURL ());
65
+ self ::assertSame ('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png ' , $ drawing ->getPath ());
66
+ self ::assertSame (IMAGETYPE_PNG , $ drawing ->getType ());
67
+ self ::assertSame (84 , $ drawing ->getWidth ());
68
+ self ::assertSame (44 , $ drawing ->getHeight ());
69
+ }
70
+ $ spreadsheet ->disconnectWorksheets ();
71
+ }
72
+
48
73
public function testURLImageSourceNotAllowed (): void
49
74
{
50
75
$ filename = realpath (__DIR__ . '/../../../data/Reader/XLSX/urlImage.xlsx ' );
51
76
self ::assertNotFalse ($ filename );
52
77
$ reader = IOFactory::createReader ('Xlsx ' );
53
78
$ reader ->setAllowExternalImages (false );
79
+ self ::assertFalse ($ reader ->getAllowExternalImages ());
54
80
$ spreadsheet = $ reader ->load ($ filename );
55
81
$ worksheet = $ spreadsheet ->getActiveSheet ();
56
82
$ collection = $ worksheet ->getDrawingCollection ();
@@ -87,6 +113,18 @@ public function testURLImageSourceNotFoundNotAllowed(): void
87
113
$ spreadsheet ->disconnectWorksheets ();
88
114
}
89
115
116
+ public function testURLImageSourceNotFoundNotAllowedFlag (): void
117
+ {
118
+ $ filename = realpath (__DIR__ . '/../../../data/Reader/XLSX/urlImage.notfound.xlsx ' );
119
+ self ::assertNotFalse ($ filename );
120
+ $ reader = IOFactory::createReader ('Xlsx ' );
121
+ $ spreadsheet = $ reader ->load ($ filename , XlsxReader::DONT_ALLOW_EXTERNAL_IMAGES );
122
+ $ worksheet = $ spreadsheet ->getActiveSheet ();
123
+ $ collection = $ worksheet ->getDrawingCollection ();
124
+ self ::assertCount (0 , $ collection );
125
+ $ spreadsheet ->disconnectWorksheets ();
126
+ }
127
+
90
128
public function testURLImageSourceBadProtocol (): void
91
129
{
92
130
$ filename = realpath (__DIR__ . '/../../../data/Reader/XLSX/urlImage.bad.dontuse ' );
0 commit comments