PDF rausgenommen
This commit is contained in:
77
msd2/myoos/vendor/fig/link-util/test/GenericLinkProviderTest.php
vendored
Normal file
77
msd2/myoos/vendor/fig/link-util/test/GenericLinkProviderTest.php
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Fig\Link\Tests;
|
||||
|
||||
use Fig\Link\GenericLinkProvider;
|
||||
use Fig\Link\Link;
|
||||
|
||||
class GenericLinkProviderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function test_can_add_links_by_method()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$provider = (new GenericLinkProvider())
|
||||
->withLink($link);
|
||||
|
||||
$this->assertContains($link, $provider->getLinks());
|
||||
}
|
||||
|
||||
|
||||
public function test_can_add_links_by_constructor()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$provider = (new GenericLinkProvider())
|
||||
->withLink($link);
|
||||
|
||||
$this->assertContains($link, $provider->getLinks());
|
||||
}
|
||||
|
||||
public function test_can_get_links_by_rel()
|
||||
{
|
||||
$link1 = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
$link2 = (new Link())
|
||||
->withHref('http://www.php-fig.org/')
|
||||
->withRel('home')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$provider = (new GenericLinkProvider())
|
||||
->withLink($link1)
|
||||
->withLink($link2);
|
||||
|
||||
$links = $provider->getLinksByRel('home');
|
||||
$this->assertContains($link2, $links);
|
||||
$this->assertFalse(in_array($link1, $links));
|
||||
}
|
||||
|
||||
public function test_can_remove_links()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$provider = (new GenericLinkProvider())
|
||||
->withLink($link)
|
||||
->withoutLink($link);
|
||||
|
||||
$this->assertFalse(in_array($link, $provider->getLinks()));
|
||||
}
|
||||
}
|
59
msd2/myoos/vendor/fig/link-util/test/LinkTest.php
vendored
Normal file
59
msd2/myoos/vendor/fig/link-util/test/LinkTest.php
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Fig\Link\Tests;
|
||||
|
||||
use Fig\Link\Link;
|
||||
|
||||
class LinkTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function test_can_set_and_retrieve_values()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$this->assertEquals('http://www.google.com', $link->getHref());
|
||||
$this->assertContains('next', $link->getRels());
|
||||
$this->assertArrayHasKey('me', $link->getAttributes());
|
||||
$this->assertEquals('you', $link->getAttributes()['me']);
|
||||
}
|
||||
|
||||
public function test_can_remove_values()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withAttribute('me', 'you')
|
||||
;
|
||||
|
||||
$link = $link->withoutAttribute('me')
|
||||
->withoutRel('next');
|
||||
|
||||
$this->assertEquals('http://www.google.com', $link->getHref());
|
||||
$this->assertFalse(in_array('next', $link->getRels()));
|
||||
$this->assertFalse(array_key_exists('me', $link->getAttributes()));
|
||||
}
|
||||
|
||||
public function test_multiple_rels()
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref('http://www.google.com')
|
||||
->withRel('next')
|
||||
->withRel('reference');
|
||||
|
||||
$this->assertCount(2, $link->getRels());
|
||||
$this->assertContains('next', $link->getRels());
|
||||
$this->assertContains('reference', $link->getRels());
|
||||
}
|
||||
|
||||
public function test_constructor()
|
||||
{
|
||||
$link = new Link('next', 'http://www.google.com');
|
||||
|
||||
$this->assertEquals('http://www.google.com', $link->getHref());
|
||||
$this->assertContains('next', $link->getRels());
|
||||
}
|
||||
}
|
56
msd2/myoos/vendor/fig/link-util/test/TemplatedHrefTraitTest.php
vendored
Normal file
56
msd2/myoos/vendor/fig/link-util/test/TemplatedHrefTraitTest.php
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Fig\Link\Tests;
|
||||
|
||||
|
||||
use Fig\Link\Link;
|
||||
|
||||
class TemplatedHrefTraitTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider templatedHrefProvider
|
||||
*
|
||||
* @param string $href
|
||||
* The href to check.
|
||||
*/
|
||||
public function test_templated($href)
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref($href);
|
||||
|
||||
$this->assertTrue($link->isTemplated());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider notTemplatedHrefProvider
|
||||
*
|
||||
* @param string $href
|
||||
* The href to check.
|
||||
*/
|
||||
public function test_not_templated($href)
|
||||
{
|
||||
$link = (new Link())
|
||||
->withHref($href);
|
||||
|
||||
$this->assertFalse($link->isTemplated());
|
||||
}
|
||||
|
||||
public function templatedHrefProvider()
|
||||
{
|
||||
return [
|
||||
['http://www.google.com/{param}/foo'],
|
||||
['http://www.google.com/foo?q={param}'],
|
||||
];
|
||||
}
|
||||
|
||||
public function notTemplatedHrefProvider()
|
||||
{
|
||||
return [
|
||||
['http://www.google.com/foo'],
|
||||
['/foo/bar/baz'],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user