Skip to content

Instantly share code, notes, and snippets.

@matiit
Created October 6, 2015 12:18
Show Gist options
  • Save matiit/5e3c9fdda2f84bf280f4 to your computer and use it in GitHub Desktop.
Save matiit/5e3c9fdda2f84bf280f4 to your computer and use it in GitHub Desktop.
<?php
namespace JustPark\Tests\Unit\Auth;
use JustPark\Auth\ShareableLinkAuth;
class ShareableLinkAuthTest extends \PHPUnit_Framework_TestCase
{
public function test_it_generates_working_link()
{
$listing = \Mockery::mock('Listing')->makePartial();
$listing->id = 10;
$auth = new ShareableLinkAuth('anthony');
$url = '/listings/something';
$shareableUrl = $auth->getLink($url, $listing);
$this->assertTrue($auth->check($shareableUrl, $listing));
$this->assertContains('auth=', $shareableUrl);
}
public function test_it_cares_about_querystring()
{
$listing = \Mockery::mock('Listing')->makePartial();
$listing->id = 10;
$auth = new ShareableLinkAuth('anthony');
$url = '/listings/something?x=1&y=2';
$shareableUrl = $auth->getLink($url, $listing);
// ensure link has parameters.
$this->assertContains('?x=1&y=2', $shareableUrl);
$this->assertContains('&auth=', $shareableUrl);
// ensure it validates with changed parameters.
$shareableUrl = str_replace('&y=2', '', $shareableUrl);
$this->assertTrue($auth->check($shareableUrl, $listing));
}
public function test_check_it_fails_check_with_dummy_auth()
{
$listing = \Mockery::mock('Listing')->makePartial();
$listing->id = 10;
$auth = new ShareableLinkAuth('anthony');
$this->assertFalse(
$auth->check('/listings/something?x=1&y=2auth=bjksvdjkndvsjkbsdjsdfjkfsdhjkfsdjhkf', $listing)
);
}
public function test_it_fails_with_wrong_model()
{
$listing = \Mockery::mock('Listing')->makePartial();
$listing->id = 10;
$auth = new ShareableLinkAuth('anthony');
$url = '/listings/something?x=1&y=2';
$shareableUrl = $auth->getLink($url, $listing);
$listing->id = 11;
$this->assertFalse($auth->check($shareableUrl, $listing));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment