wishthis/vendor/ml/json-ld/Test/FileGetContentsLoaderTest.php

100 lines
2.7 KiB
PHP
Raw Normal View History

2022-01-21 08:23:52 +00:00
<?php
/*
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ML\JsonLD\Test;
use ML\IRI\IRI;
use ML\JsonLD\FileGetContentsLoader;
/**
* Test the parsing of a JSON-LD document into a Document.
*/
class FileGetContentsLoaderTest extends \PHPUnit_Framework_TestCase
{
protected $iri;
protected $loader;
public function setUp()
{
parent::setUp();
2022-10-09 11:01:52 +00:00
$this->iri = new IRI('https://www.example.com');
2022-01-21 08:23:52 +00:00
$this->loader = new FileGetContentsLoader;
}
public function tearDown()
{
unset($iri);
unset($this->loader);
parent::tearDown();
}
public function testParseLinkHeadersExactsValues()
{
$headers = array(
2022-10-09 11:01:52 +00:00
'<https://www.example.com>; param1=foo; param2="bar";',
2022-01-21 08:23:52 +00:00
);
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
2022-10-09 11:01:52 +00:00
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
2022-01-21 08:23:52 +00:00
$this->assertEquals('foo', $parsed[0]['param1']);
$this->assertEquals('bar', $parsed[0]['param2']);
}
public function testParseLinkHeadersTrimsValues()
{
$headers = array(
2022-10-09 11:01:52 +00:00
'< https://www.example.com >; param1= foo ; param2=" bar ";',
2022-01-21 08:23:52 +00:00
);
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
2022-10-09 11:01:52 +00:00
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
2022-01-21 08:23:52 +00:00
$this->assertEquals('foo', $parsed[0]['param1']);
$this->assertEquals('bar', $parsed[0]['param2']);
}
public function testParseLinkHeadersWithMultipleHeaders()
{
$headers = array(
2022-10-09 11:01:52 +00:00
'<https://www.example.com>; param1=foo; param2=bar;',
'<https://www.example.org>; param1=fizz; param2=buzz;',
2022-01-21 08:23:52 +00:00
);
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
$this->assertCount(2, $parsed);
}
public function testParseLinkHeadersWithMultipleLinks()
{
$headers = array(
2022-10-09 11:01:52 +00:00
'<https://www.example.com>; param1=foo; param2=bar;, '
. '<https://www.example.org>; param1=fizz; param2=buzz;'
2022-01-21 08:23:52 +00:00
);
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
$this->assertCount(2, $parsed);
2022-10-09 11:01:52 +00:00
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
$this->assertEquals('https://www.example.org', $parsed[1]['uri']);
2022-01-21 08:23:52 +00:00
}
public function testParseLinkHeadersConvertsRelativeLinksToAbsolute()
{
$headers = array('</foo/bar>;');
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
2022-10-09 11:01:52 +00:00
$this->assertEquals('https://www.example.com/foo/bar', $parsed[0]['uri']);
2022-01-21 08:23:52 +00:00
}
}