1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
<?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\JsonLD\JsonLD;
/**
* Tests JsonLD's API
*
* @author Markus Lanthaler <mail@markus-lanthaler.com>
*/
class JsonLDApiTest extends JsonTestCase
{
/**
* Tests the expansion API
*
* @group expansion
*/
public function testExpansion()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
$expected = json_decode(file_get_contents($path . 'sample-expanded.jsonld'));
$input = $path . 'sample-in.jsonld';
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the file path');
$input = file_get_contents($input);
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the raw input (string)');
$input = json_decode($input);
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the parsed object');
}
/**
* Tests the compaction API
*
* @group compaction
*/
public function testCompaction()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
$expected = json_decode(file_get_contents($path . 'sample-compacted.jsonld'));
$input = $path . 'sample-in.jsonld';
$context = $path . 'sample-context.jsonld';
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the file path');
$input = file_get_contents($input);
$context = file_get_contents($context);
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the raw input (string)');
$input = json_decode($input);
$context = json_decode($context);
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the parsed object');
}
/**
* Tests the flattening API
*
* @group flattening
*/
public function testFlatten()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
$expected = json_decode(file_get_contents($path . 'sample-flattened.jsonld'));
$input = $path . 'sample-in.jsonld';
$context = $path . 'sample-context.jsonld';
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the file path');
$input = file_get_contents($input);
$context = file_get_contents($context);
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the raw input (string)');
$input = json_decode($input);
$context = json_decode($context);
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the parsed object');
}
/**
* Tests the framing API
*
* This test intentionally uses the same fixtures as the flattening tests.
*
* @group framing
*/
public function testFrame()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
$expected = json_decode(file_get_contents($path . 'sample-flattened.jsonld'));
$input = $path . 'sample-in.jsonld';
$context = $path . 'sample-context.jsonld';
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the file path');
$input = file_get_contents($input);
$context = file_get_contents($context);
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the raw input (string)');
$input = json_decode($input);
$context = json_decode($context);
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the parsed object');
}
/**
* Tests the document API
*
* This test intentionally uses the same fixtures as the flattening tests.
*/
public function testGetDocument()
{
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
$expected = json_decode(file_get_contents($path . 'sample-serialized-document.jsonld'));
$input = $path . 'sample-in.jsonld';
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the file path');
$input = file_get_contents($input);
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the raw input (string)');
$input = json_decode($input);
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the parsed object');
}
}
|