Ejemplo n.º 1
0
  public function doSave($con = null)
  {

    // autogenerage a suitable username
    if (!isset($values['username'])) {
      srand(time());
      $username = $this->getValue('firstname').'_'.substr($this->getValue('lastname'), 0, 1).'_'.rand(1, 1000);
            
      $usr = new sfGuardUser();
      while ($usr->getTable()->retrieveByUsername($username))
      {
        $username = $this->getValue('firstname').'_'.substr($this->getValue('lastname'), 0, 1).'_'.rand(1, 1000);
      }
   
      $this->values['username'] = $username;
    }
    
    // do all the saving magic
    return parent::doSave($con);
  }
Ejemplo n.º 2
0
include dirname(__FILE__) . '/../../bootstrap/functional.php';
/**
 * This is an example class of sfTestFunctional
 * It may require some attention to work with the default values (line 40).
 */
$browser = new sfBrowser();
$test_browser = new sfTestFunctional($browser);
$test_browser->setTester('json.response', 'sfTesterJsonResponse');
$test_browser->get('/user')->with('request')->begin()->isParameter('module', 'user')->isParameter('action', 'index')->end()->with('response')->begin()->isStatusCode(200)->end()->with('json.response')->begin()->isJson()->end();
/**
 * Test the creation
 */
$entity = new sfGuardUser();
$entity_array = $entity->exportTo('array');
$identifier = $entity->getTable()->getIdentifier();
/**
 * Please build a valid $entity_array here
 */
unset($entity_array[$identifier]);
//$entity_array['name'] = "pony";
//$entity_array['created_at'] = date('Y-m-d H:i:s');
//$entity_array['updated_at'] = date('Y-m-d H:i:s');
$test_browser->call('/user', 'post', array('content' => json_encode($entity_array)))->with('request')->begin()->isParameter('module', 'user')->isParameter('action', 'create')->end()->with('response')->begin()->isStatusCode(200)->end();
/**
 * If the new entity has been created
 */
$location = $browser->getResponse()->getHttpHeader('Location');
if ($location) {
    // Get ?
    $test_browser->get($location)->with('request')->begin()->isParameter('module', 'user')->isParameter('action', 'show')->end()->with('response')->begin()->isStatusCode(200)->end()->with('json.response')->begin()->isJson()->end();