Changeset 90 in ExiteCMS8
- Timestamp:
- 09/07/11 22:02:10 (9 months ago)
- Location:
- trunk/fuel/core
- Files:
-
- 11 edited
-
classes/form.php (modified) (6 diffs)
-
classes/lang.php (modified) (1 diff)
-
classes/num.php (modified) (1 diff)
-
classes/upload.php (modified) (6 diffs)
-
classes/uri.php (modified) (1 diff)
-
config/form.php (modified) (1 diff)
-
phpunit.xml (modified) (1 diff)
-
tests/html.php (modified) (8 diffs)
-
tests/lang.php (modified) (4 diffs)
-
tests/num.php (modified) (2 diffs)
-
tests/uri.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fuel/core/classes/form.php
r82 r90 591 591 $fields = $this->field(); 592 592 $fields_output = ''; 593 593 594 foreach ($fields as $f) 594 595 { … … 597 598 $close = static::close(); 598 599 599 $template = $this->get_config('form_template', "\ t\t{form_open}\n{fields}\n\t\t{form_close}\n");600 $template = $this->get_config('form_template', "\n\t\t{form_open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{form_close}\n"); 600 601 $template = str_replace(array('{form_open}', '{fields}', '{form_close}'), 601 602 array($open, $fields_output, $close), … … 607 608 * Build & template individual field 608 609 * 609 * @param string|Fieldset_Field fieldinstance or name of a field in this form's fieldset610 * @param string|Fieldset_Field field instance or name of a field in this form's fieldset 610 611 * @return string 611 612 */ … … 716 717 $required_mark = $required ? $this->get_config('required_mark', null) : null; 717 718 $label = $field->label ? static::label($field->label, $field->get_attribute('id', null)) : ''; 719 $error_template = $this->get_config('error_template', ""); 720 $error_msg = ($this->get_config('inline_errors') && $field->error()) ? str_replace('{error_msg}', $field->error(), $error_template) : ''; 721 $error_class = $field->error() ? $this->get_config('error_class') : ''; 718 722 719 723 if (is_array($build_field)) 720 724 { 721 725 $label = $field->label ? static::label($field->label) : ''; 722 $template = $field->template ?: $this->get_config('multi_field_template', '\t\t \t{group_label}\n {fields}\t\t\t{label} {field}{fields}');726 $template = $field->template ?: $this->get_config('multi_field_template', '\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n'); 723 727 if ($template && preg_match('#\{fields\}(.*)\{fields\}#Dus', $template, $match) > 0) 724 728 { … … 733 737 734 738 $template = str_replace($match[0], '{fields}', $template); 735 $template = str_replace(array('{group_label}', '{required}', '{fields}' ), array($label, $required_mark, $build_fields), $template);739 $template = str_replace(array('{group_label}', '{required}', '{fields}', '{error_msg}', '{error_class}'), array($label, $required_mark, $build_fields, $error_msg, $error_class), $template); 736 740 737 741 return $template; … … 742 746 } 743 747 744 $template = $field->template ?: $this->get_config('field_template', '\t\t \t{label} {field}\n');745 $template = str_replace(array('{label}', '{required}', '{field}' ),746 array($label, $required_mark, $build_field ),748 $template = $field->template ?: $this->get_config('field_template', '\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} {error_msg}</td>\n\t\t</tr>\n'); 749 $template = str_replace(array('{label}', '{required}', '{field}', '{error_msg}', '{error_class}'), 750 array($label, $required_mark, $build_field, $error_msg, $error_class), 747 751 $template); 748 752 return $template; -
trunk/fuel/core/classes/lang.php
r87 r90 110 110 * @param string value for the key 111 111 * @param string group 112 * @return bool success112 * @return void 113 113 */ 114 114 public static function set($line, $value, $group = null) -
trunk/fuel/core/classes/num.php
r78 r90 159 159 if ($num >= 1000 && $num < 1000000) 160 160 { 161 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0 .f', $num) / 1000)).'K';161 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0f', $num) / 1000)).'K'; 162 162 } 163 163 elseif ($num >= 1000000 && $num < 1000000000) 164 164 { 165 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0 .f', $num) / 1000000)).'M';165 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0f', $num) / 1000000)).'M'; 166 166 } 167 167 elseif ($num >= 1000000000) 168 168 { 169 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0 .f', $num) / 1000000000)).'B';169 return sprintf('%01.'.$decimals.'f', (sprintf('%01.0f', $num) / 1000000000)).'B'; 170 170 } 171 171 -
trunk/fuel/core/classes/upload.php
r87 r90 241 241 foreach ($keys as $key) 242 242 { 243 // skip this entry if no file was uploaded244 if ($value['error'][$key] == static::UPLOAD_ERR_NO_FILE)245 {246 continue;247 }248 243 // store the file data 249 244 $file = array('field' => $name, 'key' => $key); … … 258 253 else 259 254 { 260 // skip this entry if no file was uploaded261 if ($value['error'] == static::UPLOAD_ERR_NO_FILE)262 {263 continue;264 }265 255 // store the file data 266 256 $file = array('field' => $name, 'key' => false, 'file' => $value['tmp_name']); … … 311 301 if ($files[$key]['error'] == UPLOAD_ERR_OK) 312 302 { 313 if (in_array( $files[$key]['extension'], (array) static::$config['ext_blacklist']))303 if (in_array(strtolower($files[$key]['extension']), (array) static::$config['ext_blacklist'])) 314 304 { 315 305 $files[$key]['error'] = static::UPLOAD_ERR_EXT_BLACKLISTED; 316 306 } 317 elseif ( ! empty(static::$config['ext_whitelist']) and ! in_array( $files[$key]['extension'], (array) static::$config['ext_whitelist']))307 elseif ( ! empty(static::$config['ext_whitelist']) and ! in_array(strtolower($files[$key]['extension']), (array) static::$config['ext_whitelist'])) 318 308 { 319 309 $files[$key]['error'] = static::UPLOAD_ERR_EXT_NOT_WHITELISTED; … … 447 437 throw new \Fuel_Exception('No uploaded files are selected.'); 448 438 } 449 439 450 440 // supplied new name and not auto renaming? 451 441 if (array_key_exists('new_name', static::$config) and ! static::$config['auto_rename'] and count($files) > 1) … … 462 452 umask($oldumask); 463 453 } 464 454 465 455 if ( ! is_dir($path)) 466 456 { … … 493 483 } 494 484 } 495 485 496 486 array_key_exists('new_name', static::$config) and $filename = (string) static::$config['new_name']; 497 487 -
trunk/fuel/core/classes/uri.php
r78 r90 106 106 $url .= ltrim($uri, '/'); 107 107 108 substr($url, -1) != '/' and strrchr($url, '.') !== \Config::get('url_suffix') and $url .= \Config::get('url_suffix'); 108 // Add a url_suffix if defined and the url doesn't already have one 109 if (substr($url, -1) != '/' and (($suffix = strrchr($url, '.')) === false or strlen($suffix) > 5)) 110 { 111 \Config::get('url_suffix') and $url .= \Config::get('url_suffix'); 112 } 109 113 110 114 if ( ! empty($get_variables)) 111 115 { 112 116 $char = strpos($url, '?') === false ? '?' : '&'; 113 $url .= $char. http_build_query($get_variables);117 $url .= $char.str_replace('%3A', ':', http_build_query($get_variables)); 114 118 } 115 119 -
trunk/fuel/core/config/form.php
r64 r90 22 22 23 23 return array( 24 'prep_value' => true, 25 'auto_id' => true, 26 'auto_id_prefix' => 'form_', 27 'form_method' => 'post', 28 'form_template' => "\t\t{form_open}\n{fields}\n\t\t{form_close}\n", 29 'field_template' => "\t\t\t{label} {field}\n", 30 'multi_field_template' => "\t\t\t{group_label}{required}\n {fields}\t\t\t{label} {field}{fields}", 31 'required_mark' => '*', 24 'prep_value' => true, 25 'auto_id' => true, 26 'auto_id_prefix' => 'form_', 27 'form_method' => 'post', 28 'form_template' => "\n\t\t{form_open}\n\t\t<table>\n{fields}\n\t\t</table>\n\t\t{form_close}\n", 29 'field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{field} {error_msg}</td>\n\t\t</tr>\n", 30 'multi_field_template' => "\t\t<tr>\n\t\t\t<td class=\"{error_class}\">{group_label}{required}</td>\n\t\t\t<td class=\"{error_class}\">{fields}\n\t\t\t\t{field} {label}<br />\n{fields}\t\t\t{error_msg}\n\t\t\t</td>\n\t\t</tr>\n", 31 'error_template' => '<span>{error_msg}</span>', 32 'required_mark' => '*', 33 'inline_errors' => false, 34 'error_class' => 'validation_error', 32 35 ); 33 36 -
trunk/fuel/core/phpunit.xml
r53 r90 4 4 <php> 5 5 <server name="doc_root" value="../../"/> 6 <server name="app_path" value=" fuel/app"/>6 <server name="app_path" value="exitecms"/> 7 7 <server name="core_path" value="fuel/core"/> 8 8 <server name="package_path" value="fuel/packages"/> -
trunk/fuel/core/tests/html.php
r64 r90 15 15 /** 16 16 * Html class tests 17 * 17 * 18 18 * @group Core 19 19 * @group Html … … 22 22 23 23 /** 24 * Tests Html::h()25 *26 * @test27 */28 public function test_h()29 {30 $output = Html::h('Example');31 $expected = "<h1>Example</h1>";32 $this->assertEquals($expected, $output);33 34 $output = Html::h('Some other example', '2', array('id' => 'h2', 'class' => 'sample', 'style' => 'color:red;'));35 $expected = '<h2 id="h2" class="sample" style="color:red;">Some other example</h2>';36 $this->assertEquals($expected, $output);37 38 $attributes = array('id' => 'sample', 'class' => 'sample', 'style' => 'color:blue;');39 $output = Html::h('Variable!', '3', $attributes);40 $expected = '<h3 id="sample" class="sample" style="color:blue;">Variable!</h3>';41 $this->assertEquals($expected, $output);42 }43 44 /**45 * Tests Html::br()46 *47 * @test48 */49 public function test_br()50 {51 $output = Html::br();52 $expected = "<br />";53 $this->assertEquals($expected, $output);54 55 $output = Html::br('2', array('id' => 'example', 'class' => 'sample', 'style' => 'color:red;'));56 $expected = '<br id="example" class="sample" style="color:red;" /><br id="example" class="sample" style="color:red;" />';57 $this->assertEquals($expected, $output);58 }59 60 /**61 * Tests Html::hr()62 *63 * @test64 */65 public function test_hr()66 {67 $output = Html::hr();68 $expected = "<hr />";69 $this->assertEquals($expected, $output);70 71 $output = Html::hr(array('id' => 'example', 'class' => 'sample', 'style' => 'color:red;'));72 $expected = '<hr id="example" class="sample" style="color:red;" />';73 $this->assertEquals($expected, $output);74 }75 76 /**77 * Tests Html::title()78 *79 * @test80 */81 public function test_title()82 {83 $output = Html::title();84 $expected = "<title></title>";85 $this->assertEquals($expected, $output);86 87 $output = Html::title('Some Title!');88 $expected = "<title>Some Title!</title>";89 $this->assertEquals($expected, $output);90 }91 92 /**93 * Tests Html::nbs()94 *95 * @test96 */97 public function test_nbs()98 {99 $output = Html::nbs();100 $expected = " ";101 $this->assertEquals($expected, $output);102 103 $output = Html::nbs(2);104 $expected = " ";105 $this->assertEquals($expected, $output);106 }107 108 /**109 24 * Tests Html::meta() 110 * 25 * 111 26 * @test 112 27 */ … … 137 52 /** 138 53 * Tests Html::anchor() 139 * 54 * 140 55 * @test 141 56 */ 142 57 public function test_anchor() 143 58 { 144 $index_url = Uri::create('');145 146 59 // External uri 147 60 $output = Html::anchor('http://google.com', 'Go to Google'); 148 61 $expected = '<a href="http://google.com">Go to Google</a>'; 149 62 $this->assertEquals($expected, $output); 150 63 151 64 $output = Html::anchor('javascript:do();', 'Do()'); 152 65 $expected = '<a href="javascript:do();">Do()</a>'; 153 66 $this->assertEquals($expected, $output); 154 67 155 68 $output = Html::anchor('http://google.com', 'Go to Google', array('rel' => 'example', 'class' => 'sample', 'style' => 'color:red;')); 156 69 $expected = '<a rel="example" class="sample" style="color:red;" href="http://google.com">Go to Google</a>'; 157 70 $this->assertEquals($expected, $output); 158 71 159 72 // Internal uri 160 73 $output = Html::anchor('controller/method', 'Method'); 161 $expected = '<a href="' . $index_url . 'controller/method">Method</a>';74 $expected = '<a href="' . Uri::create('controller/method') . '">Method</a>'; 162 75 $this->assertEquals($expected, $output); 163 76 } 164 77 165 78 /** 166 79 * Tests Html::img() 167 * 80 * 168 81 * This test does not account for the image file existing in 169 82 * the filesystem. There are no images bundled with the framework 170 83 * by default, so no reliable test can be run on an actual image. 171 * 84 * 172 85 * @test 173 86 */ 174 87 public function test_img() 175 88 { 176 $index_url = Uri::create(' ');177 89 $index_url = Uri::create('image.png'); 90 178 91 // Internal uri 179 92 $output = Html::img('image.png'); 180 $expected = '<img src="'. $index_url . ' image.png" alt="image" />';93 $expected = '<img src="'. $index_url . '" alt="image" />'; 181 94 $this->assertEquals($expected, $output); 182 95 183 96 $output = Html::img('image.png', array('alt' => 'Image')); 184 $expected = '<img alt="Image" src="'. $index_url . ' image.png" />';97 $expected = '<img alt="Image" src="'. $index_url . '" />'; 185 98 $this->assertEquals($expected, $output); 186 99 187 100 // External uri 188 101 $output = Html::img('http://google.com/image.png'); 189 102 $expected = '<img src="http://google.com/image.png" />'; 190 103 } 191 104 192 105 /** 193 106 * Tests Html::prep_url() 194 * 107 * 195 108 * @test 196 109 */ … … 200 113 $expected = 'http://google.com'; 201 114 $this->assertEquals($expected, $output); 202 115 203 116 $output = Html::prep_url('google.com', 'https'); 204 117 $expected = 'https://google.com'; 205 118 $this->assertEquals($expected, $output); 206 119 } 207 120 208 121 /** 209 122 * Tests Html::mail_to() 210 * 123 * 211 124 * @test 212 125 */ … … 216 129 $expected = '<a href="mailto:test@test.com">test@test.com</a>'; 217 130 $this->assertEquals($expected, $output); 218 131 219 132 $output = Html::mail_to('test@test.com', 'Email'); 220 133 $expected = '<a href="mailto:test@test.com">Email</a>'; 221 134 $this->assertEquals($expected, $output); 222 135 223 136 $output = Html::mail_to('test@test.com', NULL, 'Test'); 224 137 $expected = '<a href="mailto:test@test.com?subject=Test">test@test.com</a>'; 225 138 $this->assertEquals($expected, $output); 226 139 227 140 $output = Html::mail_to('test@test.com', 'Test', 'Test'); 228 141 $expected = '<a href="mailto:test@test.com?subject=Test">Test</a>'; 229 142 $this->assertEquals($expected, $output); 230 143 } 231 144 232 145 /** 233 146 * Tests Html::doctype() 234 * 147 * 235 148 * @test 236 149 */ … … 240 153 $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; 241 154 $this->assertEquals($expected, $output); 242 155 243 156 $output = Html::doctype('html5'); 244 157 $expected = '<!DOCTYPE html>'; 245 158 $this->assertEquals($expected, $output); 246 159 247 160 // Ensure static::$html5 is set 248 161 $doctype = Html::doctype('html5'); 249 162 $this->assertTrue(Html::$html5); 250 163 251 164 // Ensure === false if doctype is invalid 252 165 $this->assertFalse(Html::doctype('shouldfail')); 253 166 } 254 255 /** 256 * Tests Html::header() 257 * 258 * @test 259 */ 260 public function test_header() 261 { 262 // Doctype != html5 263 Html::$html5 = FALSE; 264 265 $output = Html::header(); 266 $expected = '<div id="header"></div>'; 267 $this->assertEquals($expected, $output); 268 269 $output = Html::header('Content'); 270 $expected = '<div id="header">Content</div>'; 271 $this->assertEquals($expected, $output); 272 273 // Doctype = html5 274 Html::$html5 = TRUE; 275 $output = Html::header(); 276 $expected = '<header></header>'; 277 $this->assertEquals($expected, $output); 278 279 $output = Html::header('Content'); 280 $expected = '<header>Content</header>'; 281 $this->assertEquals($expected, $output); 282 } 283 167 284 168 /** 285 169 * Tests Html::ul() & Html::ol() 286 * 170 * 287 171 * @test 288 172 */ … … 290 174 { 291 175 $list = array('one', 'two'); 292 176 293 177 $output = Html::ul($list); 294 178 $expected = '<ul> … … 298 182 '; 299 183 $this->assertEquals($expected, $output); 300 184 301 185 $output = Html::ol($list); 302 186 $expected = '<ol> -
trunk/fuel/core/tests/lang.php
r53 r90 15 15 /** 16 16 * Lang class tests 17 * 17 * 18 18 * @group Core 19 19 * @group Lang 20 20 */ 21 21 class Test_Lang extends TestCase { 22 22 23 23 /** 24 24 * Test for Lang::line() 25 * 25 * 26 26 * @test 27 */ 27 */ 28 28 public function test_line() 29 29 { 30 30 Lang::load('test'); 31 $output = Lang:: line('hello', array('name' => 'Bob'));31 $output = Lang::get('hello', array('name' => 'Bob')); 32 32 $expected = 'Hello there Bob!'; 33 33 $this->assertEquals($expected, $output); … … 36 36 /** 37 37 * Test for Lang::line() 38 * 38 * 39 39 * @test 40 */ 40 */ 41 41 public function test_line_invalid() 42 42 { 43 43 Lang::load('test'); 44 $output = Lang:: line('non_existant_hello', array('name' => 'Bob'));45 $expected = 'non_existant_hello';44 $output = Lang::get('non_existant_hello', array('name' => 'Bob')); 45 $expected = false; 46 46 $this->assertEquals($expected, $output); 47 47 } … … 49 49 /** 50 50 * Test for Lang::set() 51 * 51 * 52 52 * @test 53 */ 53 */ 54 54 public function test_set_return_true() 55 55 { 56 56 $output = Lang::set('testing_set_valid', 'Ahoy :name!'); 57 $this->assert True($output);57 $this->assertNull($output); 58 58 } 59 59 60 60 /** 61 61 * Test for Lang::set() 62 * 62 * 63 63 * @test 64 64 */ … … 66 66 { 67 67 Lang::set('testing_set_valid', 'Ahoy :name!'); 68 $output = Lang:: line('testing_set_valid', array('name' => 'Bob'));68 $output = Lang::get('testing_set_valid', array('name' => 'Bob')); 69 69 $expected = 'Ahoy Bob!'; 70 70 $this->assertEquals($expected, $output); -
trunk/fuel/core/tests/num.php
r77 r90 53 53 $output = Num::quantity('7500'); 54 54 $expected = '8K'; 55 56 $this->assertEquals($expected, $output); 57 58 $output = Num::quantity('7500', 1); 59 $expected = '7.5K'; 55 60 56 61 $this->assertEquals($expected, $output); … … 111 116 $this->assertEquals($expected, $output); 112 117 } 113 118 114 119 /** 115 120 * @see Num::mask_credit_card -
trunk/fuel/core/tests/uri.php
r64 r90 28 28 public function test_create() 29 29 { 30 Config::set('url_suffix', ''); 31 30 32 $prefix = Uri::create(''); 31 33 … … 47 49 $expected = $prefix."controller/thing.html?what=more"; 48 50 $this->assertEquals($expected, $output); 49 51 50 52 $output = Uri::create('http://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and')); 51 53 $expected = "http://example.com/controller/thing.html?what=more";
Note: See TracChangeset
for help on using the changeset viewer.
