Changeset 19842
- Timestamp:
- 07/03/09 14:23:36 (7 months ago)
- Files:
-
- plugins/sfDoctrineEditableComponentPlugin/trunk/config/routing.yml (modified) (1 diff)
- plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php (modified) (1 diff)
- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php (modified) (2 diffs)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php (modified) (1 diff)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility (added)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility/actions (added)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility/actions/actions.class.php (added)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility/config (added)
- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility/config/module.yml (added)
- plugins/sfDoctrineEditableComponentPlugin/trunk/test/functional/sfEditableComponentModuleTest.php (modified) (1 diff)
- plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfDoctrineEditableComponentPlugin/trunk/config/routing.yml
r19821 r19842 2 2 url: /editable_component_service 3 3 param: { module: sfEditableComponent, action: update } 4 5 editable_component_auth_test_service: 6 url: /editable_component_auth_test_service 7 param: { module: sfEditableComponentTestUtility, action: auth } plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php
r19832 r19842 14 14 public function configure() 15 15 { 16 $this->dispatcher->connect('context.load_factories', array($this, 'listen dForContextLoadFactories'));16 $this->dispatcher->connect('context.load_factories', array($this, 'listenForContextLoadFactories')); 17 17 } 18 18 19 public function listen dForContextLoadFactories()19 public function listenForContextLoadFactories() 20 20 { 21 sfConfig::set('sf_enabled_modules', array_merge(sfConfig::get('sf_enabled_modules', array()), array('sfEditableComponent'))); 21 $pluginModules = array('sfEditableComponent'); 22 23 // Enables the auth testing service utility only in 'test' env 24 if ('test' === sfConfig::get('sf_environment')) 25 { 26 $pluginModules[] = 'sfEditableComponentTestUtility'; 27 } 28 29 sfConfig::set('sf_enabled_modules', array_merge(sfConfig::get('sf_enabled_modules', array()), $pluginModules)); 22 30 } 23 31 } plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php
r19832 r19842 21 21 static function updateComponent($name, $content, $type = null, $namespace = null) 22 22 { 23 $component = Doctrine::getTable('sfEditableComponent')->get EditableComponent($name, $type, $namespace);23 $component = Doctrine::getTable('sfEditableComponent')->getComponent($name, $type, $namespace); 24 24 25 25 // FIXME: filter html content … … 39 39 * @return sfEditableComponent 40 40 */ 41 static public function get EditableComponent($name, $type = null, $namespace = null, $createAndSave = true)41 static public function getComponent($name, $type = null, $namespace = null, $createAndSave = true) 42 42 { 43 43 if (is_null($type)) plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php
r19821 r19842 15 15 public function executeShow() 16 16 { 17 $this->component = sfEditableComponentTable::get EditableComponent($this->name, $this->type, $this->namespace);17 $this->component = sfEditableComponentTable::getComponent($this->name, $this->type, $this->namespace); 18 18 } 19 19 } plugins/sfDoctrineEditableComponentPlugin/trunk/test/functional/sfEditableComponentModuleTest.php
r19832 r19842 1 1 <?php 2 2 $app = 'backend'; 3 3 require_once dirname(__FILE__).'/../bootstrap.php'; 4 4 5 $adminCredential = sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'); 6 5 7 $browser = new sfTestFunctional(new sfBrowser()); 8 $browser->setTester('doctrine', 'sfTesterDoctrine'); 9 10 Doctrine::getTable('sfEditableComponent')->createQuery('e')->delete()->execute(); 11 12 # Init session 13 $browser->info(sprintf('Testing from app "%s"', $app))->get('/'); 14 15 if (class_exists('sfGuardSecurityUser', true) && $browser->getUser() instanceof sfGuardSecurityUser) 16 { 17 $browser->test()->comment(sprintf('This plugin cannot be tested using the "%s" app configuration', $app)); 18 $browser->test()->comment('because it uses the sfGuardSecurityUser as the user class'); 19 $browser->test()->comment('Please try to use another app'); 20 $browser->shutdown(); 21 exit(0); 22 } 6 23 7 24 $browser-> 8 info(sprintf('Testing from app "%s"', $app))->9 25 info('Testing service in unauthenticated mode')-> 26 27 get('/editable_component_service')-> 28 with('response')->begin()-> 29 isStatusCode(403)-> 30 end()-> 31 with('doctrine')->begin()-> 32 check('sfEditableComponent', array(), 0)-> 33 end()-> 10 34 11 get('/')-> 12 with('user')->begin()-> 13 hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'), false)-> 14 end()-> 35 post('/editable_component_service')-> 36 with('response')->begin()-> 37 isStatusCode(403)-> 38 end()-> 39 with('doctrine')->begin()-> 40 check('sfEditableComponent', array(), 0)-> 41 end()-> 15 42 16 get('/editable_component_service')-> 17 with('response')->begin()-> 18 isStatusCode(403)-> 19 end()-> 43 post('/editable_component_service', array('id' => 'foo'))-> 44 with('response')->begin()-> 45 isStatusCode(403)-> 46 end()-> 47 with('doctrine')->begin()-> 48 check('sfEditableComponent', array(), 0)-> 49 end()-> 50 51 post('/editable_component_service', array('id' => 'foo', 'value' => 'bar'))-> 52 with('response')->begin()-> 53 isStatusCode(403)-> 54 end()-> 55 with('doctrine')->begin()-> 56 check('sfEditableComponent', array(), 0)-> 57 end()-> 58 59 info('Testing service in authenticated mode')-> 60 61 get('/editable_component_auth_test_service?authenticate&credential='.$adminCredential)-> 62 with('user')->hasCredential($adminCredential)-> 63 64 get('/editable_component_service')-> 65 with('response')->begin()-> 66 isStatusCode(404)-> 67 end()-> 68 with('doctrine')->begin()-> 69 check('sfEditableComponent', array(), 0)-> 70 end()-> 20 71 21 post('/editable_component_service')-> 22 with('response')->begin()-> 23 isStatusCode(403)-> 24 end()-> 72 post('/editable_component_service')-> 73 with('response')->begin()-> 74 isStatusCode(404)-> 75 end()-> 76 with('doctrine')->begin()-> 77 check('sfEditableComponent', array(), 0)-> 78 end()-> 25 79 26 post('/editable_component_service', array('id' => 'foo'))-> 27 with('response')->begin()-> 28 isStatusCode(403)-> 29 end()-> 80 post('/editable_component_service', array('id' => 'foo'))-> 81 with('response')->begin()-> 82 isStatusCode(404)-> 83 end()-> 84 with('doctrine')->begin()-> 85 check('sfEditableComponent', array(), 0)-> 86 end()-> 30 87 31 post('/editable_component_service', array('id' => 'foo', 'value' => 'bar'))-> 32 with('response')->begin()-> 33 isStatusCode(403)-> 34 end()-> 35 36 info('Testing service in authenticated mode'); 37 38 $browser->getUser()->addCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin')); 39 40 $browser-> 41 with('user')->begin()-> 42 hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'))-> 43 end()-> 44 45 get('/editable_component_service')-> 46 with('response')->begin()-> 47 isStatusCode(404)-> 48 end()-> 49 50 post('/editable_component_service')-> 51 with('response')->begin()-> 52 isStatusCode(404)-> 53 end()-> 54 55 post('/editable_component_service', array('id' => 'foo'))-> 56 with('response')->begin()-> 57 isStatusCode(404)-> 58 end()-> 59 60 post('/editable_component_service', array('id' => 'foo', 'value' => 'bar'))-> 61 with('response')->begin()-> 62 isStatusCode(200)-> 63 end()-> 88 post('/editable_component_service', array('id' => 'foo', 'value' => 'bar'))-> 89 with('response')->begin()-> 90 isStatusCode(200)-> 91 contains('bar')-> 92 end()-> 93 with('doctrine')->begin()-> 94 check('sfEditableComponent', array('name' => 'foo', 'namespace' => 'default', 'type' => 'html'), 1)-> 95 end()-> 96 97 post('/editable_component_service', array('id' => 'foo', 'value' => 'baz'))-> 98 with('response')->begin()-> 99 isStatusCode(200)-> 100 contains('baz')-> 101 end()-> 102 with('doctrine')->begin()-> 103 check('sfEditableComponent', array('name' => 'foo', 'namespace' => 'default', 'type' => 'html', 'content' => 'bar'), 0)-> 104 check('sfEditableComponent', array('name' => 'foo', 'namespace' => 'default', 'type' => 'html'), 1)-> 105 end()-> 64 106 65 107 shutdown() plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php
r19832 r19842 6 6 7 7 // removes old test records 8 PluginsfEditableComponentTable::getEditableComponent('bar', 'html', 'foo')->delete(); 9 PluginsfEditableComponentTable::getEditableComponent('bar2', 'html', 'foo')->delete(); 8 Doctrine::getTable('sfEditableComponent')->createQuery('e')->delete()->execute(); 10 9 11 // get EditableComponent()12 $t->diag('get EditableComponent()');13 $c = PluginsfEditableComponentTable::get EditableComponent('bar', 'html', 'foo');14 $t->isa_ok($c, 'sfEditableComponent', 'get EditableComponent() returns a sfEditableComponent when createAndSave=true');15 $t->is($c->getName(), 'bar', 'get EditableComponent() saves the name when createAndSave=true');16 $t->is($c->getNamespace(), 'foo', 'get EditableComponent() saves the namespace when createAndSave=true');17 $t->is($c->getType(), 'html', 'get EditableComponent() saves the type when createAndSave=true');18 $t->is($c->exists(), true, 'get EditableComponent() saved the object when createAndSave=true');10 // getComponent() 11 $t->diag('getComponent()'); 12 $c = PluginsfEditableComponentTable::getComponent('bar', 'html', 'foo'); 13 $t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a sfEditableComponent when createAndSave=true'); 14 $t->is($c->getName(), 'bar', 'getComponent() saves the name when createAndSave=true'); 15 $t->is($c->getNamespace(), 'foo', 'getComponent() saves the namespace when createAndSave=true'); 16 $t->is($c->getType(), 'html', 'getComponent() saves the type when createAndSave=true'); 17 $t->is($c->exists(), true, 'getComponent() saved the object when createAndSave=true'); 19 18 20 $c2 = PluginsfEditableComponentTable::get EditableComponent('bar', 'html', 'foo');21 $t->is($c2->getId(), $c->getId(), 'get EditableComponent() do not create duplicate components');19 $c2 = PluginsfEditableComponentTable::getComponent('bar', 'html', 'foo'); 20 $t->is($c2->getId(), $c->getId(), 'getComponent() do not create duplicate components'); 22 21 23 $c = PluginsfEditableComponentTable::get EditableComponent('bar2', 'html', 'foo', false);24 $t->isa_ok($c, 'sfEditableComponent', 'get EditableComponent() returns a sfEditableComponent when createAndSave=false');25 $t->is($c->getName(), 'bar2', 'get EditableComponent() saves the name when createAndSave=false');26 $t->is($c->getNamespace(), 'foo', 'get EditableComponent() saves the namespace when createAndSave=false');27 $t->is($c->getType(), 'html', 'get EditableComponent() saves the type when createAndSave=false');28 $t->is($c->exists(), false, 'get EditableComponent() did not save the object when createAndSave=false');22 $c = PluginsfEditableComponentTable::getComponent('bar2', 'html', 'foo', false); 23 $t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a sfEditableComponent when createAndSave=false'); 24 $t->is($c->getName(), 'bar2', 'getComponent() saves the name when createAndSave=false'); 25 $t->is($c->getNamespace(), 'foo', 'getComponent() saves the namespace when createAndSave=false'); 26 $t->is($c->getType(), 'html', 'getComponent() saves the type when createAndSave=false'); 27 $t->is($c->exists(), false, 'getComponent() did not save the object when createAndSave=false'); 29 28 30 29 // updateComponent() 31 30 $t->diag('updateComponent()'); 32 31 PluginsfEditableComponentTable::updateComponent('bar2', 'my beautiful content', 'html', 'foo'); 33 $c = PluginsfEditableComponentTable::get EditableComponent('bar2', 'html', 'foo', false);32 $c = PluginsfEditableComponentTable::getComponent('bar2', 'html', 'foo', false); 34 33 $t->is($c->getContent(), 'my beautiful content', 'updateComponent() updates component content');

