diff --git a/tests/src/Util/JSonLDTest.php b/tests/src/Util/JSonLDTest.php new file mode 100644 index 0000000000..1cb1bb1f9b --- /dev/null +++ b/tests/src/Util/JSonLDTest.php @@ -0,0 +1,80 @@ +. + * + */ + +namespace Friendica\Test\src\Util; + +use Friendica\Util\JsonLD; +use PHPUnit\Framework\TestCase; + +/** + * JsonLD utility test class + */ +class JsonLDTest extends TestCase +{ + public function testFetchElementArrayNotFound() + { + $object = []; + + $data = JsonLD::fetchElementArray($object, 'field'); + $this->assertNull($data); + } + + public function testFetchElementNotFound() + { + $object = []; + + $data = JsonLD::fetchElement($object, 'field'); + $this->assertNull($data); + } + + public function testFetchElementFound() + { + $object = ['field' => 'value']; + + $data = JsonLD::fetchElement($object, 'field'); + $this->assertSame('value', $data); + } + + public function testFetchElementFoundID() + { + $object = ['field' => ['field2' => 'value2', '@id' => 'value', 'field3' => 'value3']]; + + $data = JsonLD::fetchElement($object, 'field'); + $this->assertSame('value', $data); + } + + public function testFetchElementType() + { + $object = ['source' => ['content' => 'body', 'mediaType' => 'text/bbcode']]; + + $data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/bbcode'); + $this->assertSame('body', $data); + } + + public function testFetchElementTypeArray() + { + $object = ['source' => [['content' => 'body2', 'mediaType' => 'text/html'], + ['content' => 'body', 'mediaType' => 'text/bbcode']]]; + + $data = JsonLD::fetchElement($object, 'source', 'content', 'mediaType', 'text/bbcode'); + $this->assertSame('body', $data); + } +}