From 95d997c79d3d004671883cb962ac368865d08150 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 6 Jun 2020 12:53:36 +0000 Subject: [PATCH] Added tests for JsonLD class --- tests/src/Util/JSonLDTest.php | 80 +++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/src/Util/JSonLDTest.php 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); + } +} -- 2.39.5