2014-05-14 13:24:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Cms\Classes\Page;
|
|
|
|
|
use Cms\Classes\Theme;
|
|
|
|
|
use Cms\Classes\Layout;
|
|
|
|
|
use Cms\Classes\Controller;
|
|
|
|
|
use Cms\Classes\CodeParser;
|
|
|
|
|
use Cms\Classes\ComponentManager;
|
|
|
|
|
|
2020-02-03 04:21:04 +00:00
|
|
|
class ComponentManagerTest extends \October\Core\Tests\TestCase
|
2014-05-14 13:24:20 +00:00
|
|
|
{
|
2019-06-12 16:22:20 +00:00
|
|
|
public function setUp() : void
|
2016-02-09 10:42:14 +00:00
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php';
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Post.php';
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/MainMenu.php';
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/ContentBlock.php';
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Comments.php';
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/classes/Users.php';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
public function testListComponents()
|
|
|
|
|
{
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$components = $manager->listComponents();
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('testArchive', $components);
|
|
|
|
|
$this->assertArrayHasKey('testPost', $components);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testListComponentDetails()
|
|
|
|
|
{
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$components = $manager->listComponentDetails();
|
2016-02-09 10:42:14 +00:00
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertArrayHasKey('testArchive', $components);
|
|
|
|
|
$this->assertArrayHasKey('name', $components['testArchive']);
|
|
|
|
|
$this->assertArrayHasKey('description', $components['testArchive']);
|
|
|
|
|
$this->assertEquals('Blog Archive Dummy Component', $components['testArchive']['name']);
|
|
|
|
|
$this->assertEquals('Displays an archive of blog posts.', $components['testArchive']['description']);
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('testPost', $components);
|
|
|
|
|
$this->assertArrayHasKey('name', $components['testPost']);
|
|
|
|
|
$this->assertArrayHasKey('description', $components['testPost']);
|
|
|
|
|
$this->assertEquals('Blog Post Dummy Component', $components['testPost']['name']);
|
|
|
|
|
$this->assertEquals('Displays a blog post.', $components['testPost']['description']);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-09 10:42:14 +00:00
|
|
|
public function testGetComponentWithFactoryUsingAutomaticResolution()
|
|
|
|
|
{
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$components = $manager->listComponentDetails();
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('testComments', $components);
|
|
|
|
|
$this->assertArrayHasKey('name', $components['testComments']);
|
|
|
|
|
$this->assertArrayHasKey('description', $components['testComments']);
|
|
|
|
|
$this->assertEquals('Blog Comments Dummy Component', $components['testComments']['name']);
|
|
|
|
|
$this->assertEquals('Displays the list of comments on a post.', $components['testComments']['description']);
|
|
|
|
|
|
|
|
|
|
$comments = $manager->makeComponent('testComments', $this->spoofPageCode(), []);
|
|
|
|
|
$users = $comments->getUsers()->getUsers();
|
|
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('Art Vandelay', $users);
|
|
|
|
|
$this->assertArrayHasKey('Carl', $users);
|
|
|
|
|
$this->assertEquals('Arquitecht and Importer/Exporter', $users['Art Vandelay']);
|
|
|
|
|
$this->assertEquals('where is he?', $users['Carl']);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 13:24:20 +00:00
|
|
|
public function testFindByAlias()
|
|
|
|
|
{
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
|
|
|
|
|
$component = $manager->resolve('testArchive');
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertEquals('\October\Tester\Components\Archive', $component);
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$component = $manager->resolve('testPost');
|
2014-09-20 07:59:19 +00:00
|
|
|
$this->assertEquals('\October\Tester\Components\Post', $component);
|
2014-05-14 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testHasComponent()
|
|
|
|
|
{
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$result = $manager->hasComponent('testArchive');
|
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = $manager->hasComponent('October\Tester\Components\Archive');
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
2014-09-20 07:59:19 +00:00
|
|
|
$result = $manager->hasComponent('October\Tester\Components\Post');
|
2014-05-14 13:24:20 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testMakeComponent()
|
|
|
|
|
{
|
2015-02-10 06:45:07 +00:00
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php';
|
2014-05-14 13:24:20 +00:00
|
|
|
|
|
|
|
|
$pageObj = $this->spoofPageCode();
|
|
|
|
|
|
|
|
|
|
// Test a defined property
|
|
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$object = $manager->makeComponent('testArchive', $pageObj, ['posts-per-page' => 20]);
|
|
|
|
|
$this->assertNotNull($object);
|
|
|
|
|
$this->assertEquals(20, $object->property('posts-per-page'));
|
|
|
|
|
|
|
|
|
|
// Test an undefined property with default
|
|
|
|
|
$object = $manager->makeComponent('testArchive', $pageObj);
|
|
|
|
|
$this->assertNotNull($object);
|
|
|
|
|
$this->assertEquals(10, $object->property('posts-per-page'));
|
|
|
|
|
$this->assertEquals(2020, $object->property('undefined-property', 2020));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefineProperties()
|
|
|
|
|
{
|
2015-02-10 06:45:07 +00:00
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php';
|
2014-05-14 13:24:20 +00:00
|
|
|
$manager = ComponentManager::instance();
|
|
|
|
|
$object = $manager->makeComponent('testArchive');
|
|
|
|
|
$details = $object->componentDetails();
|
|
|
|
|
$this->assertCount(2, $details);
|
|
|
|
|
$this->assertNotNull($details);
|
|
|
|
|
$this->assertArrayHasKey('name', $details);
|
|
|
|
|
$this->assertArrayHasKey('description', $details);
|
|
|
|
|
$this->assertEquals('Blog Archive Dummy Component', $details['name']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function spoofPageCode()
|
|
|
|
|
{
|
|
|
|
|
// Spoof all the objects we need to make a page object
|
2014-12-10 06:42:50 +00:00
|
|
|
$theme = Theme::load('test');
|
2014-05-14 13:24:20 +00:00
|
|
|
$page = Page::load($theme, 'index.htm');
|
|
|
|
|
$layout = Layout::load($theme, 'content.htm');
|
|
|
|
|
$controller = new Controller($theme);
|
|
|
|
|
$parser = new CodeParser($page);
|
|
|
|
|
$pageObj = $parser->source($page, $layout, $controller);
|
|
|
|
|
return $pageObj;
|
|
|
|
|
}
|
2014-09-15 21:36:05 +00:00
|
|
|
}
|