<?php

namespace ActivityPhpTest\Server;

use ActivityPhpTest\MyCustomOntology;
use ActivityPhp\Server;
use ActivityPhp\Type;
use ActivityPhp\Type\Ontology;
use Exception;
use PHPUnit\Framework\TestCase;

class ServerOntologyTest extends TestCase
{
	/**
	 * Check that an ontology can be define from server configuration
	 */
	public function testOntologyServerLoading()
	{
		$ontologies = [
		    'peertube'
		];

		$server = new Server([
		    'ontologies' => $ontologies,
		    'logger'    => [
		       'driver' => '\Psr\Log\NullLogger'
		    ],
		    'cache' => [
		        'enabled' => false,
		    ]
		]);

		$person = Type::create('Person', ['playlists' => 'bob']);

		$this->assertEquals(
		    'bob',
		    $person->getPlaylists()
		);

		Ontology::clear();
	}


	/**
	 * Add a new ontology
	 */
	public function testAddCustomOntology()
	{
		$ontologies = [
		    'custom-ontology' => MyCustomOntology::class,
		];

		$server = new Server([
		    'ontologies' => $ontologies,
		    'logger'    => [
		       'driver' => '\Psr\Log\NullLogger'
		    ],
		    'cache' => [
		        'enabled' => false,
		    ]
		]);

		$person = Type::create('Person', ['myOntologyField' => 'bob']);

		$this->assertEquals(
		    'bob',
		    $person->myOntologyField
		);

		Ontology::clear();
	}


	/**
	 * Check that an ontology can be define from server configuration
	 */
	public function testLoadAllOntologiesServerLoading()
	{
		$ontologies = [
		    '*'
		];

		$server = new Server([
		    'ontologies' => $ontologies,
		    'logger'    => [
		       'driver' => '\Psr\Log\NullLogger'
		    ],
		    'cache' => [
		        'enabled' => false,
		    ]
		]);

		$person = Type::create('Person', ['playlists' => 'bob']);

		$this->assertEquals(
		    'bob',
		    $person->getPlaylists()
		);

		Ontology::clear();
	}


	/**
	 * Try to load an undefined ontology
	 */
	public function testLoadUndefinedOntologyLoading()
	{
		$this->expectException(Exception::class);

		$ontologies = [
		    'undefined'
		];

		$server = new Server([
		    'ontologies' => $ontologies,
		    'logger'    => [
		       'driver' => '\Psr\Log\NullLogger'
		    ],
		    'cache' => [
		        'enabled' => false,
		    ]
		]);
	}
}
__halt_compiler();----SIGNATURE:----LNc2OJJ51QsN5Naef9/Uj/29eVIobtFZbSsvaSgLzu2VApxPPE6OVpbwQuf9wEvJBAeKkUUp1ocf3/Nl/ozydMAay46Naf1BzDB+Vx2W063hU2DBfFNOCd22JH5ugb+m35NyhfIQ6qIW1lPkwl8mgMXeGwDvUSJvJuAaRQrVOXbmKMqMJ6Ryyz2nh/OxHDH0UDvc3BVjYj8M/lOQDMDVPY0a/7VzWoZG8DufZ/tlTGzbsEvSRuQGsigRYB460pSyOyaj/6g/hE38RSL08mbdrHuLayekb2TmJCG6WN3kzhWgk5gzxI2+46N3oKYvEfzfsCEXXCAx+XX0Tn1KpHw/uwK5kquLux82DfflRWbNmVU7GA+ittQItUg5sEot2QJLDL2zY4w+HPOfmuKN0Q/lCwjQHPYHZqsULARhLCv5ifqx1FGKRTrhhd7f703uKMWVEpOe614UoK3BM8TZgET4s9SxMAsQhNs1I0wDhSMDmnHABjZKqQKX7tO4McnIYdca5CtNZ4qwqaZIC2oW95ZYFznCZ2dJ6yTCG2c07ceF1DB3x9uayX0uDtiufH7IRcqP7riwfT05dwGWsPTp9vK5crrgEelWR/0UY6HBg0yLT6y4Wil0hy8G9+AlCr5xJNItjWvMuZjcdWzH8m1EivsxFWn3MovNKbtGRTUdkQMCpJ0=----ATTACHMENT:----NDYyOTY4NTMwNDMyNjg0IDQxMzA0NTIyNzA3NTYxMTAgNDAxNjM2NTM1MTc4ODAzNw==