Changeset 8932
- Timestamp:
- 05/13/08 23:29:55 (5 months ago)
- Files:
-
- branches/dwhittle/1.0/lib/filter/sfExecutionFilter.class.php (modified) (1 diff)
- branches/dwhittle/1.0/test/functional/fixtures/project/apps/frontend/modules/validation/actions/actions.class.php (modified) (1 diff)
- branches/dwhittle/1.0/test/functional/fixtures/project/apps/frontend/modules/validation/validate/Index2.yml (copied) (copied from branches/1.0/test/functional/fixtures/project/apps/frontend/modules/validation/validate/Index2.yml)
- branches/dwhittle/1.0/test/functional/validationTest.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/i18n/sfMessageFormat.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/lib/filter/sfValidationExecutionFilter.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/actions/actions.class.php (modified) (1 diff)
- branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/templates/Index2Success.php (copied) (copied from branches/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/templates/Index2Success.php)
- branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/validate/Index2.yml (copied) (copied from branches/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/validate/Index2.yml)
- branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/validationTest.php (modified) (1 diff)
- branches/dwhittle/1.1/test/unit/yaml/sfYamlDumperTest.php (modified) (6 diffs)
- branches/dwhittle/1.1/test/unit/yaml/sfYamlParserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.0/lib/filter/sfExecutionFilter.class.php
r7797 r8932 72 72 $validated = true; 73 73 74 // the case of the first letter of the action is insignificant 74 75 // get the current action validation configuration 75 $validationConfig = $moduleName.'/'.sfConfig::get('sf_app_module_validate_dir_name').'/'.$actionName.'.yml'; 76 $validationConfigWithFirstLetterLower = $moduleName.'/'.sfConfig::get('sf_app_module_validate_dir_name').'/'.strtolower(substr($actionName, 0, 1)).substr($actionName, 1).'.yml'; 77 $validationConfigWithFirstLetterUpper = $moduleName.'/'.sfConfig::get('sf_app_module_validate_dir_name').'/'.ucfirst($actionName).'.yml'; 78 79 // determine $validateFile by testing both the uppercase and lowercase 80 // types of validation configurations. 81 $validateFile = null; 82 if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$validationConfigWithFirstLetterLower, true))) 83 { 84 $validateFile = $testValidateFile; 85 } 86 else if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$validationConfigWithFirstLetterUpper, true))) 87 { 88 $validateFile = $testValidateFile; 89 } 76 90 77 91 // load validation configuration 78 92 // do NOT use require_once 79 if ( null !== $validateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$validationConfig, true))93 if (!is_null($validateFile)) 80 94 { 81 95 // create validator manager branches/dwhittle/1.0/test/functional/fixtures/project/apps/frontend/modules/validation/actions/actions.class.php
r6598 r8932 13 13 public function executeIndex() 14 14 { 15 if (sfWebRequest::POST == $this->getRequest()->getMethod()) 16 { 17 $this->getResponse()->setHttpHeader('X-Validated', 'ok'); 18 } 15 19 } 16 20 17 21 public function handleErrorIndex() 18 22 { 23 $this->getResponse()->setHttpHeader('X-Validated', 'ko'); 24 25 return sfView::SUCCESS; 26 } 27 28 public function executeIndex2() 29 { 30 if (sfWebRequest::POST == $this->getRequest()->getMethod()) 31 { 32 $this->getResponse()->setHttpHeader('X-Validated', 'ok'); 33 } 34 } 35 36 public function handleErrorIndex2() 37 { 38 $this->getResponse()->setHttpHeader('X-Validated', 'ko'); 39 19 40 return sfView::SUCCESS; 20 41 } branches/dwhittle/1.0/test/functional/validationTest.php
r6598 r8932 138 138 checkResponseElement('body ul[class="errors"] li[class="input4"]', 'Required') 139 139 ; 140 141 // check that /validation/index and /validation/Index both uses the index.yml validation file (see #1617) 142 // those tests are only relevant on machines where filesystems are case sensitive. 143 $b-> 144 post('/validation/index')-> 145 isStatusCode(200)-> 146 isRequestParameter('module', 'validation')-> 147 isRequestParameter('action', 'index')-> 148 isResponseHeader('X-Validated', 'ko') 149 ; 150 151 $b-> 152 post('/validation/Index')-> 153 isStatusCode(200)-> 154 isRequestParameter('module', 'validation')-> 155 isRequestParameter('action', 'Index')-> 156 isResponseHeader('X-Validated', 'ko') 157 ; 158 159 $b-> 160 post('/validation/INdex')-> 161 isStatusCode(404) 162 ; 163 164 $b-> 165 post('/validation/index2')-> 166 isStatusCode(200)-> 167 isRequestParameter('module', 'validation')-> 168 isRequestParameter('action', 'index2')-> 169 isResponseHeader('X-Validated', 'ko') 170 ; 171 172 $b-> 173 post('/validation/Index2')-> 174 isStatusCode(200)-> 175 isRequestParameter('module', 'validation')-> 176 isRequestParameter('action', 'Index2')-> 177 isResponseHeader('X-Validated', 'ko') 178 ; branches/dwhittle/1.1/lib/i18n/sfMessageFormat.class.php
r6812 r8932 186 186 $this->loadCatalogue($catalogue); 187 187 188 if (empty($args))189 {190 $args = array();191 }192 193 188 foreach ($this->messages[$catalogue] as $variant) 194 189 { 195 // foreach of the translation units196 foreach ($variant as $source => $result)190 // we found it, so return the target translation 191 if (isset($variant[$string])) 197 192 { 198 // we found it, so return the target translation 199 if ($source == $string) 193 $target = $variant[$string]; 194 195 // check if it contains only strings. 196 if (is_array($target)) 200 197 { 201 // check if it contains only strings. 202 $target = is_string($result) ? $result : $result[0]; 203 204 // found, but untranslated 205 if (empty($target)) 206 { 207 return $this->postscript[0].$this->replaceArgs($string, $args).$this->postscript[1]; 208 } 209 else 210 { 211 return $this->replaceArgs($target, $args); 212 } 198 $target = array_shift($target); 213 199 } 200 201 // found, but untranslated 202 if (empty($target)) 203 { 204 return $this->postscript[0].$this->replaceArgs($string, $args).$this->postscript[1]; 205 } 206 return $this->replaceArgs($target, $args); 214 207 } 215 208 } branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/lib/filter/sfValidationExecutionFilter.class.php
r7797 r8932 108 108 $validated = true; 109 109 110 // lowercase first letter and enforce convention 111 $actionName[0] = strtolower($actionName[0]); 112 110 // the case of the first letter of the action is insignificant 113 111 // get the current action validation configuration 114 $validationConfig = $moduleName.'/validate/'.$actionName.'.yml'; 112 $validationConfigWithFirstLetterLower = strtolower(substr($actionName, 0, 1)).substr($actionName, 1).'.yml'; 113 $validationConfigWithFirstLetterUpper = ucfirst($actionName).'.yml'; 114 115 // determine $validateFile by testing both the uppercase and lowercase 116 // types of validation configurations. 117 $validateFile = null; 118 if (!is_null($testValidateFile = $this->context->getConfigCache()->checkConfig('modules/'.$moduleName.'/validate/'.$validationConfigWithFirstLetterLower, true))) 119 { 120 $validateFile = $testValidateFile; 121 } 122 else if (!is_null($testValidateFile = $this->context->getConfigCache()->checkConfig('modules/'.$moduleName.'/validate/'.$validationConfigWithFirstLetterUpper, true))) 123 { 124 $validateFile = $testValidateFile; 125 } 115 126 116 127 // load validation configuration 117 128 // do NOT use require_once 118 if ( null !== $validateFile = $this->context->getConfigCache()->checkConfig('modules/'.$validationConfig, true))129 if (!is_null($validateFile)) 119 130 { 120 131 // create validator manager branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/modules/validation/actions/actions.class.php
r7167 r8932 13 13 public function executeIndex() 14 14 { 15 if (sfWebRequest::POST == $this->getRequest()->getMethod()) 16 { 17 $this->getResponse()->setHttpHeader('X-Validated', 'ok'); 18 } 15 19 } 16 20 17 21 public function handleErrorIndex() 18 22 { 23 $this->getResponse()->setHttpHeader('X-Validated', 'ko'); 24 25 return sfView::SUCCESS; 26 } 27 28 public function executeIndex2() 29 { 30 if (sfWebRequest::POST == $this->getRequest()->getMethod()) 31 { 32 $this->getResponse()->setHttpHeader('X-Validated', 'ok'); 33 } 34 } 35 36 public function handleErrorIndex2() 37 { 38 $this->getResponse()->setHttpHeader('X-Validated', 'ko'); 39 19 40 return sfView::SUCCESS; 20 41 } branches/dwhittle/1.1/lib/plugins/sfCompat10Plugin/test/functional/validationTest.php
r7167 r8932 157 157 $headers = $b->getResponse()->getHttpHeaders(); 158 158 $b->test()->ok(!isset($headers['X-Test']), 'Validation for GET is also triggered by HEAD requests'); 159 160 // check that /validation/index and /validation/Index both uses the index.yml validation file (see #1617) 161 // those tests are only relevant on machines where filesystems are case sensitive. 162 $b-> 163 post('/validation/index')-> 164 isStatusCode(200)-> 165 isRequestParameter('module', 'validation')-> 166 isRequestParameter('action', 'index')-> 167 isResponseHeader('X-Validated', 'ko') 168 ; 169 170 $b-> 171 post('/validation/Index')-> 172 isStatusCode(200)-> 173 isRequestParameter('module', 'validation')-> 174 isRequestParameter('action', 'Index')-> 175 isResponseHeader('X-Validated', 'ko') 176 ; 177 178 // needed to pass tests on case and non case sensitive machines 179 if (!file_exists(dirname(__FILE__).'/fixtures/apps/frontend/modules/validation/templates/IndexSuccess.php')) 180 { 181 $b->throwsException('sfRenderException'); 182 } 183 184 $b-> 185 post('/validation/INdex')-> 186 isStatusCode(404) 187 ; 188 189 $b-> 190 post('/validation/index2')-> 191 isStatusCode(200)-> 192 isRequestParameter('module', 'validation')-> 193 isRequestParameter('action', 'index2')-> 194 isResponseHeader('X-Validated', 'ko') 195 ; 196 197 if (!is_readable(dirname(__FILE__).'/fixtures/apps/frontend/modules/validation/templates/index2Success.php')) 198 { 199 $b->throwsException('sfRenderException'); 200 } 201 202 $b-> 203 post('/validation/Index2')-> 204 isStatusCode(200)-> 205 isRequestParameter('module', 'validation')-> 206 isRequestParameter('action', 'Index2')-> 207 isResponseHeader('X-Validated', 'ko') 208 ; 209 branches/dwhittle/1.1/test/unit/yaml/sfYamlDumperTest.php
r8490 r8932 70 70 { '': bar, 'foo''bar': { }, bar: [1, foo], foobar: { foo: bar, bar: [1, foo], foobar: { foo: bar, bar: [1, foo] } } } 71 71 EOF; 72 $t->is( sfYaml::dump($array, -10), $expected, '::dump() takes an inline level argument');73 $t->is( sfYaml::dump($array, 0), $expected, '::dump() takes an inline level argument');72 $t->is($dumper->dump($array, -10), $expected, '->dump() takes an inline level argument'); 73 $t->is($dumper->dump($array, 0), $expected, '->dump() takes an inline level argument'); 74 74 75 75 $expected = <<<EOF … … 80 80 81 81 EOF; 82 $t->is( sfYaml::dump($array, 1), $expected, '::dump() takes an inline level argument');82 $t->is($dumper->dump($array, 1), $expected, '->dump() takes an inline level argument'); 83 83 84 84 $expected = <<<EOF … … 94 94 95 95 EOF; 96 $t->is( sfYaml::dump($array, 2), $expected, '::dump() takes an inline level argument');96 $t->is($dumper->dump($array, 2), $expected, '->dump() takes an inline level argument'); 97 97 98 98 $expected = <<<EOF … … 112 112 113 113 EOF; 114 $t->is( sfYaml::dump($array, 3), $expected, '::dump() takes an inline level argument');114 $t->is($dumper->dump($array, 3), $expected, '->dump() takes an inline level argument'); 115 115 116 116 $expected = <<<EOF … … 132 132 133 133 EOF; 134 $t->is( sfYaml::dump($array, 4), $expected, '::dump() takes an inline level argument');135 $t->is( sfYaml::dump($array, 10), $expected, '::dump() takes an inline level argument');134 $t->is($dumper->dump($array, 4), $expected, '->dump() takes an inline level argument'); 135 $t->is($dumper->dump($array, 10), $expected, '->dump() takes an inline level argument'); 136 136 137 137 // objects … … 142 142 } 143 143 $a = array('foo' => new A(), 'bar' => 1); 144 $t->is(sfYaml::dump($a), <<<EOF 145 foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";} 146 bar: 1 147 148 EOF 149 , '::dump() is able to dump objects'); 144 $t->is($dumper->dump($a), '{ foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";}, bar: 1 }', '->dump() is able to dump objects'); branches/dwhittle/1.1/test/unit/yaml/sfYamlParserTest.php
r8490 r8932 74 74 } 75 75 $a = array('foo' => new A(), 'bar' => 1); 76 $t->is( sfYaml::load(<<<EOF76 $t->is($parser->parse(<<<EOF 77 77 foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";} 78 78 bar: 1 79 79 EOF 80 ), $a, ' ::dump() is able to dump objects');80 ), $a, '->parse() is able to dump objects');