Changeset 8486
- Timestamp:
- 04/16/08 21:49:30 (7 months ago)
- Files:
-
- branches/dwhittle/1.0/lib/request/sfWebRequest.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/command/cli.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/form/sfFormField.class.php (modified) (4 diffs)
- branches/dwhittle/1.1/lib/helper/AssetHelper.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfPropelPlugin/lib/propel/generator/sfPropelFormGenerator.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/widget/sfWidget.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormSchema.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/widget/sfWidgetFormSchemaDecorator.class.php (modified) (1 diff)
- branches/dwhittle/1.1/test/other/tasksTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/form/sfFormFieldTest.php (modified) (4 diffs)
- branches/dwhittle/1.1/test/unit/helper/AssetHelperTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.0/lib/request/sfWebRequest.class.php
r8030 r8486 255 255 * @return array An array of re-ordered uploaded file information 256 256 */ 257 protected function convertFileInformation( array$taintedFiles)257 protected function convertFileInformation($taintedFiles) 258 258 { 259 259 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 18 18 19 19 $application = new sfSymfonyCommandApplication($dispatcher, new sfAnsiColorFormatter(), array('symfony_lib_dir' => realpath(dirname(__FILE__).'/..'))); 20 $ application->run();20 $statusCode = $application->run(); 21 21 } 22 22 catch (Exception $e) … … 28 28 29 29 $application->renderException($e); 30 $statusCode = $e->getCode(); 30 31 31 exit( 1);32 exit(is_numeric($statusCode) && $statusCode ? $statusCode : 1); 32 33 } 33 34 34 exit( 0);35 exit(is_numeric($statusCode) ? $statusCode : 0); branches/dwhittle/1.1/lib/form/sfFormField.class.php
r8424 r8486 71 71 * The formatted row will use the parent widget schema formatter. 72 72 * 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) 76 78 * 77 79 * @return string The formatted row 78 80 */ 79 public function renderRow($ help = '')81 public function renderRow($attributes = array(), $label = null, $help = null) 80 82 { 81 83 if (is_null($this->parent)) … … 84 86 } 85 87 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); 87 89 88 90 $error = $this->error instanceof sfValidatorErrorSchema ? $this->error->getGlobalErrors() : $this->error; 89 91 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%' => '')); 91 95 } 92 96 … … 113 117 * Returns the label tag. 114 118 * 119 * @param string The label name (not null to override the current value) 120 * 115 121 * @return string The label tag 116 122 */ 117 public function renderLabel( )123 public function renderLabel($label = null) 118 124 { 119 125 if (is_null($this->parent)) … … 122 128 } 123 129 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; 125 144 } 126 145 branches/dwhittle/1.1/lib/helper/AssetHelper.php
r7775 r8486 556 556 echo get_stylesheets(); 557 557 } 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 */ 571 function 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 */ 586 function 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 */ 601 function 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 608 function _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 315 315 $options = array(); 316 316 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 330 317 if ($column->isForeignKey()) 331 318 { … … 335 322 { 336 323 $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 } 337 339 } 338 340 branches/dwhittle/1.1/lib/widget/sfWidget.class.php
r7772 r8486 284 284 * @param string The tag name 285 285 * @param string The content of the tag 286 * @param An array of HTML attributes to be merged with the default HTML attributes286 * @param array An array of HTML attributes to be merged with the default HTML attributes 287 287 * 288 288 * @param string A HTML tag string branches/dwhittle/1.1/lib/widget/sfWidgetFormSchema.class.php
r8424 r8486 281 281 * @param string The field name 282 282 * @param string The field value 283 * @param array An array of HTML attributes to be merged with the current HTML attributes 283 284 * @param array An array of errors for the field 284 285 * 285 286 * @return string A HTML string representing the rendered widget 286 287 */ 287 public function renderField($name, $value = null, $ errors = array())288 public function renderField($name, $value = null, $attributes = array(), $errors = array()) 288 289 { 289 290 if (is_null($widget = $this[$name])) … … 296 297 $clone->setIdFormat($this->options['id_format']); 297 298 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); 299 300 } 300 301 … … 340 341 { 341 342 $error = isset($errors[$name]) ? $errors[$name] : array(); 342 $field = $this->renderField($name, $value, $error);343 $field = $this->renderField($name, $value, array(), $error); 343 344 344 345 // 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 188 188 * @see sfWidgetFormSchema 189 189 */ 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); 193 193 } 194 194 branches/dwhittle/1.1/test/other/tasksTest.php
r7989 r8486 47 47 } 48 48 49 public function execute_command($cmd )49 public function execute_command($cmd, $awaited_return=0) 50 50 { 51 51 chdir($this->tmp_dir); … … 55 55 passthru(sprintf('%s "%s" %s 2>&1', $this->php_cli, $symfony, $cmd), $return); 56 56 $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)); 58 58 59 59 return $content; … … 66 66 } 67 67 68 $t = new lime_test(3 2, new lime_output_color());68 $t = new lime_test(33, new lime_output_color()); 69 69 $c = new sf_test_project(); 70 70 $c->initialize($t); … … 76 76 $content = $c->execute_command('generate:app frontend'); 77 77 $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); 78 81 79 82 $content = $c->execute_command('generate:module frontend foo'); branches/dwhittle/1.1/test/unit/form/sfFormFieldTest.php
r7157 r8486 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(2 2, new lime_output_color());13 $t = new lime_test(24, new lime_output_color()); 14 14 15 15 // widgets … … 73 73 EOF; 74 74 $t->is($f->renderRow(), $output, '->renderRow() renders a row'); 75 75 76 $output = <<<EOF 76 77 <tr> … … 79 80 <li>title error</li> 80 81 </ul> 82 <input type="password" name="article[title]" value="symfony" class="foo" id="title" /></td> 83 </tr> 84 85 EOF; 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 97 EOF; 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> 81 106 <input type="text" name="article[title]" value="symfony" id="article_title" /><br />help</td> 82 107 </tr> 83 108 84 109 EOF; 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 86 112 $output = <<<EOF 87 113 <tr> … … 99 125 EOF; 100 126 $t->is($child->renderRow(), $output, '->renderRow() renders a row when the widget has a parent'); 127 101 128 try 102 129 { branches/dwhittle/1.1/test/unit/helper/AssetHelperTest.php
r7775 r8486 16 16 require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); 17 17 18 $t = new lime_test( 45, new lime_output_color());18 $t = new lime_test(53, new lime_output_color()); 19 19 20 20 class myRequest … … 38 38 } 39 39 40 $context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse')); 40 class 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')); 41 49 42 50 // _compute_public_path() … … 159 167 '<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", 160 168 '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()'); 186 use_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()'); 194 use_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 );