/** * @dataProvider validCommandProvider **/ public function testValidCommandsCreateExpectedImage($input, $expected) { $turtle = new Turtle($input); $expectedFilename = '' === $expected ? 'empty-output' : str_replace(array(' ', ':', '"', '?'), array('-', 'c', 'q', 'p'), $expected); $expectedFilename = "test-images/{$expectedFilename}.png"; if (!file_exists($expectedFilename)) { $this->markTestSkipped("No test image available for: {$expected}"); } // md5 is being performed on both the outputs of the imges to make // the phpunit output more palettable when there is an error $this->assertEquals(md5(file_get_contents($expectedFilename)), md5($turtle->getImage()), "Generated image does not match expected image."); }
<?php require_once 'toolbox.php'; removeMagicQuotes($_GET); $turtle = new Turtle($_GET['commands'], 350, 350); $maxFilenameLength = 20; $filename = str_replace(array(' ', ':', '"', '?'), array('-', 'c', 'q', 'p'), $_GET['commands']); if (strlen($filename) > $maxFilenameLength) { $filenameMd5 = md5($filename); $filename = substr($filename, 0, $maxFilenameLength) . '_' . $filenameMd5; } header("Content-Disposition: Attachment;filename={$filename}.png"); header('Content-Type: image/png'); echo $turtle->getImage();