Development

Changeset 8495

You must first sign up to be able to contribute.

Changeset 8495

Show
Ignore:
Timestamp:
04/17/08 05:40:07 (1 year ago)
Author:
fabien
Message:

fixed sfTestBrowser doesn't play nicely when it is instantiated more than once in one test (closes #3246 - patch from l2k)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/test/sfTestBrowser.class.php

    r8462 r8495  
    2121class sfTestBrowser extends sfBrowser 
    2222{ 
    23   protected 
     23  protected static 
    2424    $test = null; 
    2525 
     
    3737    $output = isset($options['output']) ? $options['output'] : new lime_output_color(); 
    3838 
    39     $this->test = new lime_test(null, $output); 
     39    if (is_null(self::$test)) 
     40    { 
     41      self::$test = new lime_test(null, $output); 
     42    } 
    4043  } 
    4144 
     
    4750  public function test() 
    4851  { 
    49     return $this->test; 
     52    return self::$test; 
    5053  } 
    5154 
     
    7982    $uri = $this->fixUri($uri); 
    8083 
    81     $this->test->comment(sprintf('%s %s', strtolower($method), $uri)); 
     84    $this->test()->comment(sprintf('%s %s', strtolower($method), $uri)); 
    8285 
    8386    return parent::call($uri, $method, $parameters, $changeStack); 
     
    9194  public function back() 
    9295  { 
    93     $this->test->comment('back'); 
     96    $this->test()->comment('back'); 
    9497 
    9598    return parent::back(); 
     
    103106  public function forward() 
    104107  { 
    105     $this->test->comment('forward'); 
     108    $this->test()->comment('forward'); 
    106109 
    107110    return parent::forward(); 
     
    119122    if ($location = $this->context->getResponse()->getHttpHeader('location')) 
    120123    { 
    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)); 
    122125    } 
    123126    else 
    124127    { 
    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'); 
    126129    } 
    127130 
     
    158161  public function isStatusCode($statusCode = 200) 
    159162  { 
    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)); 
    161164 
    162165    return $this; 
     
    172175  public function responseContains($text) 
    173176  { 
    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))); 
    175178 
    176179    return $this; 
     
    187190  public function isRequestParameter($key, $value) 
    188191  { 
    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)); 
    190193 
    191194    return $this; 
     
    217220    } 
    218221 
    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)); 
    221224 
    222225    return $this; 
     
    246249    } 
    247250 
    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))); 
    249252 
    250253    return $this; 
     
    260263  public function isUserCulture($culture) 
    261264  { 
    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)); 
    263266 
    264267    return $this; 
     
    274277  public function isRequestFormat($format) 
    275278  { 
    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)); 
    277280 
    278281    return $this; 
     
    301304    if (false === $value) 
    302305    { 
    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)); 
    304307    } 
    305308    else if (true === $value) 
    306309    { 
    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)); 
    308311    } 
    309312    else if (is_int($value)) 
    310313    { 
    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)); 
    312315    } 
    313316    else if (preg_match('/^(!)?([^a-zA-Z0-9\\\\]).+?\\2[ims]?$/', $value, $match)) 
     
    316319      if ($match[1] == '!') 
    317320      { 
    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))); 
    319322      } 
    320323      else 
    321324      { 
    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)); 
    323326      } 
    324327    } 
     
    326329    { 
    327330      $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)); 
    329332    } 
    330333 
    331334    if (isset($options['count'])) 
    332335    { 
    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'])); 
    334337    } 
    335338 
     
    351354    if (null === $e) 
    352355    { 
    353       $this->test->fail('response returns an exception'); 
     356      $this->test()->fail('response returns an exception'); 
    354357    } 
    355358    else 
     
    357360      if (null !== $class) 
    358361      { 
    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)); 
    360363      } 
    361364 
     
    364367        if ($match[1] == '!') 
    365368        { 
    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)); 
    367370        } 
    368371        else 
    369372        { 
    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)); 
    371374        } 
    372375      } 
    373376      else if (null !== $message) 
    374377      { 
    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)); 
    376379      } 
    377380    } 
     
    411414    if (!$cacheManager) 
    412415    { 
    413       $this->test->ok(!$boolean, 'cache is disabled'); 
     416      $this->test()->ok(!$boolean, 'cache is disabled'); 
    414417 
    415418      return $this; 
     
    430433    if ($cacheManager->withLayout($uri) && !$with_layout) 
    431434    { 
    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); 
    434437    } 
    435438    else if (!$cacheManager->withLayout($uri) && $with_layout) 
    436439    { 
    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); 
    439442    } 
    440443    else 
    441444    { 
    442       $this->test->pass('cache is configured properly'); 
     445      $this->test()->pass('cache is configured properly'); 
    443446 
    444447      // 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')); 
    446449 
    447450      // check that the content is ok in cache 
     
    450453        if (!$ret) 
    451454        { 
    452           $this->test->fail('content in cache is ok'); 
     455          $this->test()->fail('content in cache is ok'); 
    453456        } 
    454457        else if ($with_layout) 
     
    456459          $response = unserialize($cacheManager->get($uri)); 
    457460          $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'); 
    459462        } 
    460463        else 
     
    462465          $ret = unserialize($cacheManager->get($uri)); 
    463466          $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'); 
    465468        } 
    466469      } 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.