Changeset 8495
- Timestamp:
- 04/17/08 05:40:07 (1 year ago)
- Files:
-
- branches/1.1/lib/test/sfTestBrowser.class.php (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/test/sfTestBrowser.class.php
r8462 r8495 21 21 class sfTestBrowser extends sfBrowser 22 22 { 23 protected 23 protected static 24 24 $test = null; 25 25 … … 37 37 $output = isset($options['output']) ? $options['output'] : new lime_output_color(); 38 38 39 $this->test = new lime_test(null, $output); 39 if (is_null(self::$test)) 40 { 41 self::$test = new lime_test(null, $output); 42 } 40 43 } 41 44 … … 47 50 public function test() 48 51 { 49 return $this->test;52 return self::$test; 50 53 } 51 54 … … 79 82 $uri = $this->fixUri($uri); 80 83 81 $this->test ->comment(sprintf('%s %s', strtolower($method), $uri));84 $this->test()->comment(sprintf('%s %s', strtolower($method), $uri)); 82 85 83 86 return parent::call($uri, $method, $parameters, $changeStack); … … 91 94 public function back() 92 95 { 93 $this->test ->comment('back');96 $this->test()->comment('back'); 94 97 95 98 return parent::back(); … … 103 106 public function forward() 104 107 { 105 $this->test ->comment('forward');108 $this->test()->comment('forward'); 106 109 107 110 return parent::forward(); … … 119 122 if ($location = $this->context->getResponse()->getHttpHeader('location')) 120 123 { 121 $boolean ? $this->test ->pass(sprintf('page redirected to "%s"', $location)) : $this->test->fail(sprintf('page redirected to "%s"', $location));124 $boolean ? $this->test()->pass(sprintf('page redirected to "%s"', $location)) : $this->test()->fail(sprintf('page redirected to "%s"', $location)); 122 125 } 123 126 else 124 127 { 125 $boolean ? $this->test ->fail('page redirected') : $this->test->pass('page not redirected');128 $boolean ? $this->test()->fail('page redirected') : $this->test()->pass('page not redirected'); 126 129 } 127 130 … … 158 161 public function isStatusCode($statusCode = 200) 159 162 { 160 $this->test ->is($this->getResponse()->getStatusCode(), $statusCode, sprintf('status code is "%s"', $statusCode));163 $this->test()->is($this->getResponse()->getStatusCode(), $statusCode, sprintf('status code is "%s"', $statusCode)); 161 164 162 165 return $this; … … 172 175 public function responseContains($text) 173 176 { 174 $this->test ->like($this->getResponse()->getContent(), '/'.preg_quote($text, '/').'/', sprintf('response contains "%s"', substr($text, 0, 40)));177 $this->test()->like($this->getResponse()->getContent(), '/'.preg_quote($text, '/').'/', sprintf('response contains "%s"', substr($text, 0, 40))); 175 178 176 179 return $this; … … 187 190 public function isRequestParameter($key, $value) 188 191 { 189 $this->test ->is($this->getRequest()->getParameter($key), $value, sprintf('request parameter "%s" is "%s"', $key, $value));192 $this->test()->is($this->getRequest()->getParameter($key), $value, sprintf('request parameter "%s" is "%s"', $key, $value)); 190 193 191 194 return $this; … … 217 220 } 218 221 219 $this->test ->is($entry->getModuleName(), $moduleName, sprintf('request is forwarded to the "%s" module (%s)', $moduleName, $position));220 $this->test ->is($entry->getActionName(), $actionName, sprintf('request is forwarded to the "%s" action (%s)', $actionName, $position));222 $this->test()->is($entry->getModuleName(), $moduleName, sprintf('request is forwarded to the "%s" module (%s)', $moduleName, $position)); 223 $this->test()->is($entry->getActionName(), $actionName, sprintf('request is forwarded to the "%s" action (%s)', $actionName, $position)); 221 224 222 225 return $this; … … 246 249 } 247 250 248 $this->test ->ok($ok, sprintf('response header "%s" is "%s" (%s)', $key, $value, $this->getResponse()->getHttpHeader($key)));251 $this->test()->ok($ok, sprintf('response header "%s" is "%s" (%s)', $key, $value, $this->getResponse()->getHttpHeader($key))); 249 252 250 253 return $this; … … 260 263 public function isUserCulture($culture) 261 264 { 262 $this->test ->is($this->getContext()->getUser()->getCulture(), $culture, sprintf('user culture is "%s"', $culture));265 $this->test()->is($this->getContext()->getUser()->getCulture(), $culture, sprintf('user culture is "%s"', $culture)); 263 266 264 267 return $this; … … 274 277 public function isRequestFormat($format) 275 278 { 276 $this->test ->is($this->getContext()->getRequest()->getRequestFormat(), $format, sprintf('request format is "%s"', $format));279 $this->test()->is($this->getContext()->getRequest()->getRequestFormat(), $format, sprintf('request format is "%s"', $format)); 277 280 278 281 return $this; … … 301 304 if (false === $value) 302 305 { 303 $this->test ->is(count($values), 0, sprintf('response selector "%s" does not exist', $selector));306 $this->test()->is(count($values), 0, sprintf('response selector "%s" does not exist', $selector)); 304 307 } 305 308 else if (true === $value) 306 309 { 307 $this->test ->cmp_ok(count($values), '>', 0, sprintf('response selector "%s" exists', $selector));310 $this->test()->cmp_ok(count($values), '>', 0, sprintf('response selector "%s" exists', $selector)); 308 311 } 309 312 else if (is_int($value)) 310 313 { 311 $this->test ->is(count($values), $value, sprintf('response selector "%s" matches "%s" times', $selector, $value));314 $this->test()->is(count($values), $value, sprintf('response selector "%s" matches "%s" times', $selector, $value)); 312 315 } 313 316 else if (preg_match('/^(!)?([^a-zA-Z0-9\\\\]).+?\\2[ims]?$/', $value, $match)) … … 316 319 if ($match[1] == '!') 317 320 { 318 $this->test ->unlike(@$values[$position], substr($value, 1), sprintf('response selector "%s" does not match regex "%s"', $selector, substr($value, 1)));321 $this->test()->unlike(@$values[$position], substr($value, 1), sprintf('response selector "%s" does not match regex "%s"', $selector, substr($value, 1))); 319 322 } 320 323 else 321 324 { 322 $this->test ->like(@$values[$position], $value, sprintf('response selector "%s" matches regex "%s"', $selector, $value));325 $this->test()->like(@$values[$position], $value, sprintf('response selector "%s" matches regex "%s"', $selector, $value)); 323 326 } 324 327 } … … 326 329 { 327 330 $position = isset($options['position']) ? $options['position'] : 0; 328 $this->test ->is(@$values[$position], $value, sprintf('response selector "%s" matches "%s"', $selector, $value));331 $this->test()->is(@$values[$position], $value, sprintf('response selector "%s" matches "%s"', $selector, $value)); 329 332 } 330 333 331 334 if (isset($options['count'])) 332 335 { 333 $this->test ->is(count($values), $options['count'], sprintf('response selector "%s" matches "%s" times', $selector, $options['count']));336 $this->test()->is(count($values), $options['count'], sprintf('response selector "%s" matches "%s" times', $selector, $options['count'])); 334 337 } 335 338 … … 351 354 if (null === $e) 352 355 { 353 $this->test ->fail('response returns an exception');356 $this->test()->fail('response returns an exception'); 354 357 } 355 358 else … … 357 360 if (null !== $class) 358 361 { 359 $this->test ->ok($e instanceof $class, sprintf('response returns an exception of class "%s"', $class));362 $this->test()->ok($e instanceof $class, sprintf('response returns an exception of class "%s"', $class)); 360 363 } 361 364 … … 364 367 if ($match[1] == '!') 365 368 { 366 $this->test ->unlike($e->getMessage(), substr($message, 1), sprintf('response exception message does not match regex "%s"', $message));369 $this->test()->unlike($e->getMessage(), substr($message, 1), sprintf('response exception message does not match regex "%s"', $message)); 367 370 } 368 371 else 369 372 { 370 $this->test ->like($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message));373 $this->test()->like($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message)); 371 374 } 372 375 } 373 376 else if (null !== $message) 374 377 { 375 $this->test ->is($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message));378 $this->test()->is($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message)); 376 379 } 377 380 } … … 411 414 if (!$cacheManager) 412 415 { 413 $this->test ->ok(!$boolean, 'cache is disabled');416 $this->test()->ok(!$boolean, 'cache is disabled'); 414 417 415 418 return $this; … … 430 433 if ($cacheManager->withLayout($uri) && !$with_layout) 431 434 { 432 $this->test ->fail('cache without layout');433 $this->test ->skip('cache is not configured properly', 2);435 $this->test()->fail('cache without layout'); 436 $this->test()->skip('cache is not configured properly', 2); 434 437 } 435 438 else if (!$cacheManager->withLayout($uri) && $with_layout) 436 439 { 437 $this->test ->fail('cache with layout');438 $this->test ->skip('cache is not configured properly', 2);440 $this->test()->fail('cache with layout'); 441 $this->test()->skip('cache is not configured properly', 2); 439 442 } 440 443 else 441 444 { 442 $this->test ->pass('cache is configured properly');445 $this->test()->pass('cache is configured properly'); 443 446 444 447 // check page is cached 445 $ret = $this->test ->is($cacheManager->has($uri), $boolean, sprintf('"%s" %s in cache', $type, $boolean ? 'is' : 'is not'));448 $ret = $this->test()->is($cacheManager->has($uri), $boolean, sprintf('"%s" %s in cache', $type, $boolean ? 'is' : 'is not')); 446 449 447 450 // check that the content is ok in cache … … 450 453 if (!$ret) 451 454 { 452 $this->test ->fail('content in cache is ok');455 $this->test()->fail('content in cache is ok'); 453 456 } 454 457 else if ($with_layout) … … 456 459 $response = unserialize($cacheManager->get($uri)); 457 460 $content = $response->getContent(); 458 $this->test ->ok($content == $this->getResponse()->getContent(), 'content in cache is ok');461 $this->test()->ok($content == $this->getResponse()->getContent(), 'content in cache is ok'); 459 462 } 460 463 else … … 462 465 $ret = unserialize($cacheManager->get($uri)); 463 466 $content = $ret['content']; 464 $this->test ->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok');467 $this->test()->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok'); 465 468 } 466 469 }

