Development

Changeset 8486

You must first sign up to be able to contribute.

Changeset 8486

Show
Ignore:
Timestamp:
04/16/08 21:49:30 (7 months ago)
Author:
dwhittle
Message:

dwhittle: merged changes to branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dwhittle/1.0/lib/request/sfWebRequest.class.php

    r8030 r8486  
    255255   * @return array An array of re-ordered uploaded file information 
    256256   */ 
    257   protected function convertFileInformation(array $taintedFiles) 
     257  protected function convertFileInformation($taintedFiles) 
    258258  { 
    259259    return $this->pathsToArray(preg_replace('#^(/[^/]+)?(/name|/type|/tmp_name|/error|/size)([^\s]*)( = [^\n]*)#m', '$1$3$2$4', $this->arrayToPaths($taintedFiles))); 
  • branches/dwhittle/1.1/lib/command/cli.php

    r7702 r8486  
    1818 
    1919  $application = new sfSymfonyCommandApplication($dispatcher, new sfAnsiColorFormatter(), array('symfony_lib_dir' => realpath(dirname(__FILE__).'/..'))); 
    20   $application->run(); 
     20  $statusCode = $application->run(); 
    2121} 
    2222catch (Exception $e) 
     
    2828 
    2929  $application->renderException($e); 
     30  $statusCode = $e->getCode(); 
    3031 
    31   exit(1); 
     32  exit(is_numeric($statusCode) && $statusCode ? $statusCode : 1); 
    3233} 
    3334 
    34 exit(0); 
     35exit(is_numeric($statusCode) ? $statusCode : 0); 
  • branches/dwhittle/1.1/lib/form/sfFormField.class.php

    r8424 r8486  
    7171   * The formatted row will use the parent widget schema formatter. 
    7272   * The formatted row contains the label, the field, the error and 
    73    * the help message if given. 
    74    * 
    75    * @param  string The help text 
     73   * the help message. 
     74   * 
     75   * @param  array  An array of HTML attributes to merge with the current attributes 
     76   * @param  string The label name (not null to override the current value) 
     77   * @param  string The help text (not null to override the current value) 
    7678   * 
    7779   * @return string The formatted row 
    7880   */ 
    79   public function renderRow($help = ''
     81  public function renderRow($attributes = array(), $label = null, $help = null
    8082  { 
    8183    if (is_null($this->parent)) 
     
    8486    } 
    8587 
    86     $field = $this->parent->getWidget()->renderField($this->name, $this->value, $this->error); 
     88    $field = $this->parent->getWidget()->renderField($this->name, $this->value, !is_array($attributes) ? array() : $attributes, $this->error); 
    8789 
    8890    $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 
    8991 
    90     return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel(), $field, $error, $help), array('%hidden_fields%' => '')); 
     92    $help = is_null($help) ? $this->parent->getWidget()->getHelp($this->name) : $help; 
     93 
     94    return strtr($this->parent->getWidget()->getFormFormatter()->formatRow($this->renderLabel($label), $field, $error, $help), array('%hidden_fields%' => '')); 
    9195  } 
    9296 
     
    113117   * Returns the label tag. 
    114118   * 
     119   * @param  string The label name (not null to override the current value) 
     120   * 
    115121   * @return string The label tag 
    116122   */ 
    117   public function renderLabel(
     123  public function renderLabel($label = null
    118124  { 
    119125    if (is_null($this->parent)) 
     
    122128    } 
    123129 
    124     return $this->parent->getWidget()->getFormFormatter()->generateLabel($this->name); 
     130    if (!is_null($label)) 
     131    { 
     132      $currentLabel = $this->parent->getWidget()->getLabel($this->name); 
     133      $this->parent->getWidget()->setLabel($this->name, $label); 
     134    } 
     135 
     136    $html = $this->parent->getWidget()->getFormFormatter()->generateLabel($this->name); 
     137 
     138    if (!is_null($label)) 
     139    { 
     140      $this->parent->getWidget()->setLabel($this->name, $currentLabel); 
     141    } 
     142 
     143    return $html; 
    125144  } 
    126145 
  • branches/dwhittle/1.1/lib/helper/AssetHelper.php

    r7775 r8486  
    556556  echo get_stylesheets(); 
    557557} 
     558 
     559/** 
     560 * Returns a <script> include tag for the given internal URI. 
     561 * 
     562 * The helper automatically adds the sf_format to the internal URI, so you don't have to. 
     563 * 
     564 * @param  string  The internal URI for the dynamic javascript 
     565 * @param  Boolean Whether to generate an absolute URL 
     566 * @param  array   An array of options (absolute) 
     567 * 
     568 * @return string  XHTML compliant <script> tag(s) 
     569 * @see    javascript_include_tag  
     570 */ 
     571function dynamic_javascript_include_tag($uri, $absolute = false, $options = array()) 
     572{ 
     573  $options['raw_name'] = true; 
     574 
     575  return javascript_include_tag(_dynamic_path($uri, 'js', $absolute), $options); 
     576} 
     577 
     578/** 
     579 * Adds a dynamic javascript to the response object. 
     580 * 
     581 * The first argument is an internal URI. 
     582 * The helper automatically adds the sf_format to the internal URI, so you don't have to. 
     583 * 
     584 * @see sfResponse->addJavascript() 
     585 */ 
     586function use_dynamic_javascript($js, $position = '', $options = array()) 
     587{ 
     588  $options['raw_name'] = true; 
     589 
     590  return use_javascript(_dynamic_path($js, 'js'), $position, $options); 
     591} 
     592 
     593/** 
     594 * Adds a dynamic stylesheet to the response object. 
     595 * 
     596 * The first argument is an internal URI. 
     597 * The helper automatically adds the sf_format to the internal URI, so you don't have to. 
     598 * 
     599 * @see sfResponse->addStylesheet() 
     600 */ 
     601function use_dynamic_stylesheet($css, $position = '', $options = array()) 
     602{ 
     603  $options['raw_name'] = true; 
     604 
     605  return use_stylesheet(_dynamic_path($css, 'css'), $position, $options); 
     606} 
     607 
     608function _dynamic_path($uri, $format, $absolute = false) 
     609{ 
     610  return url_for($uri.(false === strpos($uri, '?') ? '?' : '&').'sf_format='.$format, $absolute); 
     611} 
  • branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php

    r8400 r8486  
    315315    $options = array(); 
    316316 
    317     switch ($column->getType()) 
    318     { 
    319       case PropelColumnTypes::CHAR: 
    320       case PropelColumnTypes::VARCHAR: 
    321       case PropelColumnTypes::LONGVARCHAR: 
    322         if ($column->getSize()) 
    323         { 
    324           $options[] = sprintf('\'max_length\' => %s', $column->getSize()); 
    325         } 
    326         break; 
    327       default: 
    328     } 
    329  
    330317    if ($column->isForeignKey()) 
    331318    { 
     
    335322    { 
    336323      $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getPhpName(), $column->getPhpName()); 
     324    } 
     325    else 
     326    { 
     327      switch ($column->getType()) 
     328      { 
     329        case PropelColumnTypes::CHAR: 
     330        case PropelColumnTypes::VARCHAR: 
     331        case PropelColumnTypes::LONGVARCHAR: 
     332          if ($column->getSize()) 
     333          { 
     334            $options[] = sprintf('\'max_length\' => %s', $column->getSize()); 
     335          } 
     336          break; 
     337        default: 
     338      } 
    337339    } 
    338340 
  • branches/dwhittle/1.1/lib/widget/sfWidget.class.php

    r7772 r8486  
    284284   * @param string The tag name 
    285285   * @param string The content of the tag 
    286    * @param An array of HTML attributes to be merged with the default HTML attributes 
     286   * @param array  An array of HTML attributes to be merged with the default HTML attributes 
    287287   * 
    288288   * @param string A HTML tag string 
  • branches/dwhittle/1.1/lib/widget/sfWidgetFormSchema.class.php

    r8424 r8486  
    281281   * @param  string  The field name 
    282282   * @param  string  The field value 
     283   * @param  array   An array of HTML attributes to be merged with the current HTML attributes 
    283284   * @param  array   An array of errors for the field 
    284285   * 
    285286   * @return string  A HTML string representing the rendered widget 
    286287   */ 
    287   public function renderField($name, $value = null, $errors = array()) 
     288  public function renderField($name, $value = null, $attributes = array(), $errors = array()) 
    288289  { 
    289290    if (is_null($widget = $this[$name])) 
     
    296297    $clone->setIdFormat($this->options['id_format']); 
    297298 
    298     return $clone->render($this->generateName($name), $value, $clone->getAttributes(), $errors); 
     299    return $clone->render($this->generateName($name), $value, array_merge($clone->getAttributes(), $attributes), $errors); 
    299300  } 
    300301 
     
    340341      { 
    341342        $error = isset($errors[$name]) ? $errors[$name] : array(); 
    342         $field = $this->renderField($name, $value, $error); 
     343        $field = $this->renderField($name, $value, array(), $error); 
    343344 
    344345        // don't add a label tag and errors if we embed a form schema 
  • branches/dwhittle/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php

    r8424 r8486  
    188188   * @see sfWidgetFormSchema 
    189189   */ 
    190   public function renderField($name, $value = null, $errors = array()) 
    191   { 
    192     return $this->widget->renderField($name, $value, $errors); 
     190  public function renderField($name, $value = null, $attributes = array(), $errors = array()) 
     191  { 
     192    return $this->widget->renderField($name, $value, $attributes, $errors); 
    193193  } 
    194194 
  • branches/dwhittle/1.1/test/other/tasksTest.php

    r7989 r8486  
    4747  } 
    4848 
    49   public function execute_command($cmd
     49  public function execute_command($cmd, $awaited_return=0
    5050  { 
    5151    chdir($this->tmp_dir); 
     
    5555    passthru(sprintf('%s "%s" %s 2>&1', $this->php_cli, $symfony, $cmd), $return); 
    5656    $content = ob_get_clean(); 
    57     $this->t->cmp_ok($return, '<=', 0, sprintf('"symfony %s" returns ok', $cmd)); 
     57    $this->t->cmp_ok($return, '==', $awaited_return, sprintf('"symfony %s" returns awaited value (%d)', $cmd, $awaited_return)); 
    5858 
    5959    return $content; 
     
    6666} 
    6767 
    68 $t = new lime_test(32, new lime_output_color()); 
     68$t = new lime_test(33, new lime_output_color()); 
    6969$c = new sf_test_project(); 
    7070$c->initialize($t); 
     
    7676$content = $c->execute_command('generate:app frontend'); 
    7777$t->ok(is_dir($c->tmp_dir.DS.'apps'.DS.'frontend'), '"generate:app" creates a "frontend" directory under "apps" directory'); 
     78 
     79// failing 
     80$content = $c->execute_command('generate:module wrongapp foo', 1); 
    7881 
    7982$content = $c->execute_command('generate:module frontend foo'); 
  • branches/dwhittle/1.1/test/unit/form/sfFormFieldTest.php

    r7157 r8486  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(22, new lime_output_color()); 
     13$t = new lime_test(24, new lime_output_color()); 
    1414 
    1515// widgets 
     
    7373EOF; 
    7474$t->is($f->renderRow(), $output, '->renderRow() renders a row'); 
     75 
    7576$output = <<<EOF 
    7677<tr> 
     
    7980    <li>title error</li> 
    8081  </ul> 
     82<input type="password" name="article[title]" value="symfony" class="foo" id="title" /></td> 
     83</tr> 
     84 
     85EOF; 
     86$t->is($f->renderRow(array('class' => 'foo', 'type' => 'password', 'id' => 'title')), $output, '->renderRow() can take an array of HTML attributes as its first argument'); 
     87 
     88$output = <<<EOF 
     89<tr> 
     90  <th><label for="article_title">My title</label></th> 
     91  <td>  <ul class="error_list"> 
     92    <li>title error</li> 
     93  </ul> 
     94<input type="text" name="article[title]" value="symfony" id="article_title" /></td> 
     95</tr> 
     96 
     97EOF; 
     98$t->is($f->renderRow(array(), 'My title'), $output, '->renderRow() can take a label name as its second argument'); 
     99 
     100$output = <<<EOF 
     101<tr> 
     102  <th><label for="article_title">Title</label></th> 
     103  <td>  <ul class="error_list"> 
     104    <li>title error</li> 
     105  </ul> 
    81106<input type="text" name="article[title]" value="symfony" id="article_title" /><br />help</td> 
    82107</tr> 
    83108 
    84109EOF; 
    85 $t->is($f->renderRow('help'), $output, '->renderRow() can take a help message'); 
     110$t->is($f->renderRow(array(), null, 'help'), $output, '->renderRow() can take a help message as its third argument'); 
     111 
    86112$output = <<<EOF 
    87113<tr> 
     
    99125EOF; 
    100126$t->is($child->renderRow(), $output, '->renderRow() renders a row when the widget has a parent'); 
     127 
    101128try 
    102129{ 
  • branches/dwhittle/1.1/test/unit/helper/AssetHelperTest.php

    r7775 r8486  
    1616require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); 
    1717 
    18 $t = new lime_test(45, new lime_output_color()); 
     18$t = new lime_test(53, new lime_output_color()); 
    1919 
    2020class myRequest 
     
    3838} 
    3939 
    40 $context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse')); 
     40class myController 
     41
     42  public function genUrl($parameters = array(), $absolute = false) 
     43  { 
     44    return ($absolute ? '/' : '').$parameters; 
     45  } 
     46
     47 
     48$context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse', 'controller' => 'myController')); 
    4149 
    4250// _compute_public_path() 
     
    159167  '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n".'<link rel="stylesheet" type="text/css" media="screen" href="/css/style2.css" />'."\n", 
    160168  'get_stylesheets() returns all the stylesheets previously added by use_stylesheet()'); 
     169 
     170// _dynamic_path() 
     171$t->diag('_dynamic_path()'); 
     172$t->is(_dynamic_path('module/action', 'js'), 'module/action?sf_format=js', '_dynamic_path() converts an internal URI to a URL'); 
     173$t->is(_dynamic_path('module/action?key=value', 'js'), 'module/action?key=value&sf_format=js', '_dynamic_path() converts an internal URI to a URL'); 
     174$t->is(_dynamic_path('module/action', 'js', true), '/module/action?sf_format=js', '_dynamic_path() converts an internal URI to a URL'); 
     175 
     176// dynamic_javascript_include_tag() 
     177$t->diag('dynamic_javascript_include_tag()'); 
     178$t->is(dynamic_javascript_include_tag('module/action'), '<script type="text/javascript" src="module/action?sf_format=js"></script>'."\n", 'dynamic_javascript_include_tag() returns a tag relative to the given action'); 
     179$t->is(dynamic_javascript_include_tag('module/action', true), '<script type="text/javascript" src="/module/action?sf_format=js"></script>'."\n", 'dynamic_javascript_include_tag() takes an absolute boolean as its second argument'); 
     180$t->is(dynamic_javascript_include_tag('module/action', true, array('class' => 'foo')), '<script type="text/javascript" src="/module/action?sf_format=js" class="foo"></script>'."\n", 'dynamic_javascript_include_tag() takes an array of HTML attributes as its third argument'); 
     181 
     182$context->response = new sfWebResponse($context->getEventDispatcher()); 
     183 
     184// use_dynamic_javascript() 
     185$t->diag('use_dynamic_javascript()'); 
     186use_dynamic_javascript('module/action'); 
     187$t->is(get_javascripts(), 
     188  '<script type="text/javascript" src="module/action?sf_format=js"></script>'."\n", 
     189  'use_dynamic_javascript() register a dynamic javascript in the response' 
     190); 
     191 
     192// use_dynamic_stylesheet() 
     193$t->diag('use_dynamic_stylesheet()'); 
     194use_dynamic_stylesheet('module/action'); 
     195$t->is(get_stylesheets(), 
     196  '<link rel="stylesheet" type="text/css" media="screen" href="module/action?sf_format=css" />'."\n",  
     197  'use_dynamic_stylesheet() register a dynamic stylesheet in the response' 
     198);