2017-03-07 21:04:35 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SVGTest.php
|
|
|
|
*
|
|
|
|
* -Description-
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-02-08 23:29:04 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-03-07 21:04:35 +00:00
|
|
|
*
|
2021-02-08 23:29:04 +00:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 18:09:53 +00:00
|
|
|
*
|
2017-03-07 21:04:35 +00:00
|
|
|
* @copyright 2017 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
|
2020-04-17 22:37:56 +00:00
|
|
|
use Illuminate\Support\Str;
|
2017-03-07 21:04:35 +00:00
|
|
|
use RecursiveDirectoryIterator;
|
|
|
|
use RecursiveIteratorIterator;
|
|
|
|
use RecursiveRegexIterator;
|
|
|
|
use RegexIterator;
|
|
|
|
|
2018-10-23 16:32:44 +00:00
|
|
|
/**
|
|
|
|
* Class SVGTest
|
2021-09-10 18:09:53 +00:00
|
|
|
*
|
2018-10-23 16:32:44 +00:00
|
|
|
* @group os
|
|
|
|
*/
|
2017-12-20 14:36:49 +00:00
|
|
|
class SVGTest extends TestCase
|
2017-03-07 21:04:35 +00:00
|
|
|
{
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testSVGContainsPNG(): void
|
2017-03-07 21:04:35 +00:00
|
|
|
{
|
|
|
|
foreach ($this->getSvgFiles() as $file => $_unused) {
|
|
|
|
$svg = file_get_contents($file);
|
|
|
|
|
|
|
|
$this->assertFalse(
|
2020-04-17 22:37:56 +00:00
|
|
|
Str::contains($svg, 'data:image/'),
|
2017-03-07 21:04:35 +00:00
|
|
|
"$file contains a bitmap image, please use a regular png or valid svg"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testSVGHasLengthWidth(): void
|
2017-03-07 21:04:35 +00:00
|
|
|
{
|
|
|
|
foreach ($this->getSvgFiles() as $file => $_unused) {
|
|
|
|
if ($file == 'html/images/safari-pinned-tab.svg') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-07-26 13:45:34 +00:00
|
|
|
if (str_starts_with($file, 'html/images/custommap/background/')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-07 21:04:35 +00:00
|
|
|
$svg = file_get_contents($file);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
0,
|
|
|
|
preg_match('/<svg[^>]*(length|width)=/', $svg, $matches),
|
|
|
|
"$file: SVG files must not contain length or width attributes "
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:21:54 +00:00
|
|
|
public function testSVGHasViewBox(): void
|
2017-03-07 21:04:35 +00:00
|
|
|
{
|
|
|
|
foreach ($this->getSvgFiles() as $file => $_unused) {
|
|
|
|
$svg = file_get_contents($file);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
2020-04-17 22:37:56 +00:00
|
|
|
Str::contains($svg, 'viewBox'),
|
2017-03-07 21:04:35 +00:00
|
|
|
"$file: SVG files must have the viewBox attribute set"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 13:45:34 +00:00
|
|
|
private function getSvgFiles(): RegexIterator
|
2017-03-07 21:04:35 +00:00
|
|
|
{
|
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('html/images'));
|
2020-09-21 12:54:51 +00:00
|
|
|
|
2017-03-07 21:04:35 +00:00
|
|
|
return new RegexIterator($iterator, '/^.+\.svg$/i', RecursiveRegexIterator::GET_MATCH);
|
|
|
|
}
|
|
|
|
}
|