/** * Automatic plugin modules and helper loading * * @param sfEvent $event */ public function listenToContextLoadFactories(sfEvent $event) { // Enable module automatically sfConfig::set('sf_enabled_modules', array_merge(sfConfig::get('sf_enabled_modules', array()), array('ioEditableContent'))); // Load helper as well $event->getSubject()->getConfiguration()->loadHelpers(array('EditableContent')); // create the editable content service $this->_editableContentService = $this->_createEditableContentService($event->getSubject()->getUser()); // load the editor assets if ($this->_editableContentService->shouldShowEditor()) { $this->_loadEditorAssets($event->getSubject()); } }
<?php require_once dirname(__FILE__) . '/../../bootstrap/functional.php'; require_once $_SERVER['SYMFONY'] . '/vendor/lime/lime.php'; $dispatcher = $configuration->getEventDispatcher(); $t = new lime_test(); $t->info('1 - Test some basic getters and setters'); $service = new ioEditableContentService($context->getUser(), $dispatcher, array('test_option' => 'test_val')); $t->is($service->getOption('test_option', 'default'), 'test_val', '->getOption() works for options passed in the constructor'); $service->setOption('new_option', 'foo'); $t->is($service->getOption('new_option'), 'foo', '->setOption() sets the option value correctly'); $t->is($service->getOption('fake_option', 'bar'), 'bar', '->getOption() on a nonexistent option returns the default value.'); $t->info('2 - Test shouldShowEditor()'); $service = new ioEditableContentService($context->getUser(), $dispatcher); $t->is($service->shouldShowEditor(null, true), false, '->shouldShowEditor() returns false: no credential passed in, but we still require auth.'); $context->getUser()->setAuthenticated(true); $t->is($service->shouldShowEditor(null, true), true, '->shouldShowEditor() returns true if no credential is passed to require.'); $service->setOption('admin_credential', 'test_edit_credential'); $t->is($service->shouldShowEditor(null, true), false, '->shouldShowEditor() returns false: the user does not have the credential'); $context->getUser()->addCredential('test_edit_credential'); $t->is($service->shouldShowEditor(null, true), true, '->shouldShowEditor() returns true: the user has the proper credential'); $t->info('3 - Test getContent()'); $service = new ioEditableContentService($context->getUser(), $dispatcher); $blog = new Blog(); $blog->title = 'Unit test blog'; $blog->body = 'Lorem Ipsum'; $blog->save(); $t->info(' 3.1 - Test a single-field, no partial rendering'); $result = $service->getContent($blog, array('title')); $t->is($result, 'Unit test blog', '->getContent() returns the correct value'); $t->info(' 3.2 - Test multiple fields, no partial - throws an exception');