. * * @package LibreNMS * @link http://librenms.org * @copyright 2017 Tony Murray * @author Tony Murray */ namespace LibreNMS\Tests; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use RecursiveRegexIterator; use RegexIterator; class SVGTest extends \PHPUnit_Framework_TestCase { public function testSVGContainsPNG() { foreach ($this->getSvgFiles() as $file => $_unused) { $svg = file_get_contents($file); $this->assertFalse( str_contains($svg, 'data:image/'), "$file contains a bitmap image, please use a regular png or valid svg" ); } } public function testSVGHasLengthWidth() { foreach ($this->getSvgFiles() as $file => $_unused) { if ($file == 'html/images/safari-pinned-tab.svg') { continue; } $svg = file_get_contents($file); $this->assertEquals( 0, preg_match('/]*(length|width)=/', $svg, $matches), "$file: SVG files must not contain length or width attributes " ); } } public function testSVGHasViewBox() { foreach ($this->getSvgFiles() as $file => $_unused) { $svg = file_get_contents($file); $this->assertTrue( str_contains($svg, 'viewBox'), "$file: SVG files must have the viewBox attribute set" ); } } private function getSvgFiles() { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('html/images')); return new RegexIterator($iterator, '/^.+\.svg$/i', RecursiveRegexIterator::GET_MATCH); } }