Skip to content

Commit

Permalink
add check on targetfile extension
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 2, 2014
1 parent af991cc commit 9c98875
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 21 additions & 7 deletions spec/Spatie/Browsershot/BrowsershotSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,36 @@ function it_should_fail_if_target_file_is_not_set()
$this->shouldThrow(new \Exception('targetfile not set'))->during('save', ['']);
}

function it_should_fail_if_binary_does_not_exist()


function it_should_fail_if_invalid_url_is_set()
{
$this
->setURL($this->getTestURL())
->setBinPath('')
->shouldThrow(new \Exception('binary does not exist'))
->setURL('gibberish')
->shouldThrow(new \Exception('url is invalid'))
->during('save', [$this->getTestPath()]);
}

function it_should_fail_if_invalid_url_is_set()
function it_should_fail_if_target_file_not_is_image()
{
$this
->setURL('gibberish')
->shouldThrow(new \Exception('url is invalid'))
->setURL($this->getTestURL())
->shouldThrow(new \Exception('targetfile extension not valid'))
->during('save', [$this->getTestPath() . 'txt']);
}

function it_should_fail_if_binary_does_not_exist()
{
$this
->setURL($this->getTestURL())
->setBinPath('')
->shouldThrow(new \Exception('binary does not exist'))
->during('save', [$this->getTestPath()]);
}

/*
* still figuring out how this test can be run on Travis CI
*
function it_should_create_an_image_if_run_succesfully()
{
$this
Expand All @@ -45,6 +58,7 @@ function it_should_create_an_image_if_run_succesfully()
$this->shouldExist($this->getTestPath());
}
*/


public function getTestPath()
Expand Down
4 changes: 4 additions & 0 deletions src/Spatie/Browsershot/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function save($targetFile)
throw new Exception('targetfile not set');
}

if (! in_array(strtolower(pathinfo($targetFile, PATHINFO_EXTENSION)), ['jpeg', 'jpg', 'png'])) {
throw new Exception('targetfile extension not valid');
}

if ($this->URL == '') {
throw new Exception('url not set');
}
Expand Down

0 comments on commit 9c98875

Please sign in to comment.