Development

Changeset 11917

You must first sign up to be able to contribute.

Changeset 11917

Show
Ignore:
Timestamp:
10/02/08 18:35:40 (6 years ago)
Author:
fabien
Message:

[1.2] added sfTesterForm

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r11907 r11917  
    833833with JavaScript. 
    834834 
     835### Forms 
     836 
     837If you use the new form framework, you can now test the errors generated 
     838by the submitted form: 
     839 
     840    [php] 
     841    $browser-> 
     842      click('save', array(...))-> 
     843      with('form')->begin()-> 
     844        hasErrors()-> 
     845        isError('name', 'Required.')-> 
     846        isError('name', '/Required/')-> 
     847        isError('name', '!/Invalid/')-> 
     848        isError('name')-> 
     849        isError('name', 1)-> 
     850      end() 
     851    ; 
     852 
     853You can also debug a form with the `debug()` method: 
     854 
     855    [php] 
     856    $browser-> 
     857      click('save', array(...))-> 
     858      with('form')->debug()-> 
     859      // some tests that won't be executed 
     860    ; 
     861 
     862It will output the submitted values and all the errors if any. 
     863 
    835864YAML 
    836865---- 
  • branches/1.2/lib/autoload/sfCoreAutoload.class.php

    r11898 r11917  
    375375  'sfTestFunctionalBase' => 'test', 
    376376  'sfTester' => 'test', 
     377  'sfTesterForm' => 'test', 
    377378  'sfTesterRequest' => 'test', 
    378379  'sfTesterResponse' => 'test', 
  • branches/1.2/lib/form/sfForm.class.php

    r11814 r11917  
    233233 
    234234  /** 
     235   * Returns the submitted tainted values. 
     236   * 
     237   * @return array An array of tainted values 
     238   */ 
     239  public function getTaintedValues() 
     240  { 
     241    if (!$this->isBound) 
     242    { 
     243      return array(); 
     244    } 
     245 
     246    return $this->taintedValues; 
     247  } 
     248 
     249  /** 
    235250   * Returns true if the form is valid. 
    236251   * 
  • branches/1.2/lib/test/sfTestFunctional.class.php

    r11898 r11917  
    2828  { 
    2929    $testers['view_cache'] = 'sfTesterViewCache'; 
     30    $testers['form'] = 'sfTesterForm'; 
    3031 
    3132    parent::__construct($browser, $lime, $testers); 
  • branches/1.2/lib/test/sfTestFunctionalBase.class.php

    r11908 r11917  
    234234    $this->test()->comment(sprintf('%s %s', strtolower($method), $uri)); 
    235235 
     236    foreach ($this->testers as $tester) 
     237    { 
     238      $tester->prepare(); 
     239    } 
     240 
    236241    $this->browser->call($uri, $method, $parameters, $changeStack); 
    237242 
  • branches/1.2/lib/test/sfTester.class.php

    r11898 r11917  
    3535    $this->tester  = $tester; 
    3636  } 
     37 
     38  /** 
     39   * Prepares the tester. 
     40   */ 
     41  abstract public function prepare(); 
    3742 
    3843  /** 
  • branches/1.2/lib/test/sfTesterRequest.class.php

    r11898 r11917  
    2020{ 
    2121  protected $request; 
     22 
     23  /** 
     24   * Prepares the tester. 
     25   */ 
     26  public function prepare() 
     27  { 
     28  } 
    2229 
    2330  /** 
  • branches/1.2/lib/test/sfTesterResponse.class.php

    r11907 r11917  
    2525 
    2626  /** 
     27   * Prepares the tester. 
     28   */ 
     29  public function prepare() 
     30  { 
     31  } 
     32 
     33  /** 
    2734   * Initializes the tester. 
    2835   */ 
     
    189196  } 
    190197 
     198  /** 
     199   * Outputs some debug information about the current response. 
     200   */ 
    191201  public function debug() 
    192202  { 
     203    print $this->tester->error('Response debug'); 
     204 
    193205    printf("HTTP/1.X %s\n", $this->response->getStatusCode()); 
    194206 
  • branches/1.2/lib/test/sfTesterUser.class.php

    r11898 r11917  
    2020{ 
    2121  protected $user; 
     22 
     23  /** 
     24   * Prepares the tester. 
     25   */ 
     26  public function prepare() 
     27  { 
     28  } 
    2229 
    2330  /** 
  • branches/1.2/lib/test/sfTesterViewCache.class.php

    r11898 r11917  
    2323    $response         = null, 
    2424    $routing          = null; 
     25 
     26  /** 
     27   * Prepares the tester. 
     28   */ 
     29  public function prepare() 
     30  { 
     31  } 
    2532 
    2633  /** 
  • branches/1.2/lib/util/sfBrowser.class.php

    r11467 r11917  
    2020{ 
    2121  protected 
    22     $context = null; 
     22    $listeners = array(), 
     23    $context   = null; 
    2324 
    2425  /** 
     
    6869        $currentConfiguration = $this->context->getConfiguration(); 
    6970        $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug()); 
    70         $configuration->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException')); 
    7171        $this->context = sfContext::createInstance($configuration); 
    7272        unset($currentConfiguration); 
     
    7676        $this->context = sfContext::getInstance(); 
    7777        $this->context->initialize($this->context->getConfiguration()); 
    78         $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException')); 
     78      } 
     79 
     80      $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException')); 
     81      foreach ($this->listeners as $name => $listener) 
     82      { 
     83        $this->context->getEventDispatcher()->connect($name, $listener); 
    7984      } 
    8085    } 
    8186 
    8287    return $this->context; 
     88  } 
     89 
     90  public function addListener($name, $listener) 
     91  { 
     92    $this->listeners[$name] = $listener; 
    8393  } 
    8494