Skip to content

Instantly share code, notes, and snippets.

@JoshuaEstes
Created October 21, 2011 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaEstes/1304240 to your computer and use it in GitHub Desktop.
Save JoshuaEstes/1304240 to your computer and use it in GitHub Desktop.
Test template for a symfony 1.4 admin generated action
<?php
/**
* Symfony admin generator test template
* @see https://gist.github.com/1304240
*/
/**
* The model name
*/
$model = 'ModelName';
/**
* module
*/
$module = 'module_name';
/**
* Route
*/
$route = '/module_name';
/**
* signin route
*/
$signin_route = '/sfGuardAuth/signin';
/**
* signout route
*/
$signout_route = '/sfGuardAuth/signout';
include(dirname(__FILE__).'/../../bootstrap/functional.php');
$browser = new sfTestFunctional(new sfBrowser());
/**
* Doctrine test setup
*/
$browser->setTester('doctrine', 'sfTesterDoctrine');
new sfDatabaseManager($configuration);
$connection = Doctrine_Manager::connection();
$connection->beginTransaction();
Doctrine::loadData(sfConfig::get('sf_test_dir').'/fixtures/sfGuardUser.yml',true);
/*** end doctrine test setup ***/
$browser->info('Make sure page is secure')->
get($route)->
with('request')->begin()->
isParameter('module', $module)->
isParameter('action', 'index')->
isMethod('get')->
end()->
with('response')->begin()->
isStatusCode(401)->
end()->
with('user')->begin()->
isAuthenticated(false)->
end();
/**
* Signin
*
* @link https://gist.github.com/941570
*/
$browser->info('Signing into the web site')
->get($signout_route)
->get($signin_route)
->click('Sign in', array(
'signin' => array(
'username' => 'testuser',
'password' => 'testuser'
)))
->with('form')->begin()
->hasErrors(false)
->end()
->with('user')->begin()
->isAuthenticated()
->end()
;
/**
*
*/
$browser->info('Make sure page works')->
get($route)->
with('request')->begin()->
isParameter('module', $module)->
isParameter('action', 'index')->
isMethod('get')->
end()->
with('response')->begin()->
isStatusCode(200)->
end()->
with('user')->begin()->
isAuthenticated()->
end()
;
/**
* Create a new item
*/
$browser->info('Create a new entry')
->get(sprintf('/%s/new',$route))
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','new')
->isMethod('get')
->end()
->with('response')->begin()
->isStatusCode(200)
->end()
->with('user')->begin()
->isAuthenticated()
->end()
->click('Save',array(
/**
* This Section needs to be customized
*/
sfInflector::underscore($model) => array(
)
))
->with('form')->begin()
->hasErrors(false)
->end()
->with('doctrine')->begin()
/**
* Update this part
*/
->check($model,array(
))
->end()
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','create')
->isMethod('post')
->end()
->with('response')->begin()
->isRedirected()
->isStatusCode(302)
->end()
->followRedirect()
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','edit')
->isMethod('get')
->end()
->with('response')->begin()
->isStatusCode(200)
->end()
;
$id = $browser->getRequest()->getParameter('id');
/**
* Edit/Update
*/
$browser->info('Test to make sure edit works')
->get(sprintf('/%s/%s/edit',$route,$id))
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','edit')
->isMethod('get')
->end()
->with('response')->begin()
->isStatusCode(200)
->end()
->click('Save',array(
/**
* This section needs to be customized
*/
sfInflector::underscore($model) => array(
)
))
->with('form')->begin()
->hasErrors(false)
->end()
->with('doctrine')->begin()
/**
* This section needs to be customized
*/
->check($model,array(
'id' => $id,
))
->end()
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','update')
->isMethod('put')
->end()
->with('response')->begin()
->isRedirected()
->isStatusCode(302)
->end()
->with('user')->begin()
->isFlash('notice','The item was updated successfully.')
->end()
->followRedirect()
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','edit')
->isMethod('get')
->end()
->with('response')->begin()
->isStatusCode(200)
->end()
;
/**
* Test the delete
*/
$browser->info('Lets try to delete this new item')
->get(sprintf('/%s/%s/edit',$route,$id))
->click('Delete',array(),array(
'method' => 'delete',
'_with_csrf' => true
))
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','delete')
->isMethod('delete')
->end()
->with('response')->begin()
->isRedirected()
->isStatusCode(302)
->end()
->with('doctrine')->begin()
->check($model,array(
'id' => $id
),false)
->end()
->followRedirect()
->with('request')->begin()
->isParameter('module',$module)
->isParameter('action','index')
->isMethod('get')
->end()
->with('response')->begin()
->isStatusCode(200)
->end()
;
/**
* Signout
*
* @link https://gist.github.com/941570
*/
$browser->info('Signing out')
->get($signout_route);
// rollback all our changes and updates
$connection->rollback();
sfGuardUser:
test_user:
password: testuser
username: testuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment