Show
Ignore:
Timestamp:
09/29/08 09:46:32 (3 months ago)
Author:
felix
Message:

- implemented some more assertions
- adds some comments and better messages

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/felix-testing-implementation/src/testing/AgaviViewTestCase.class.php

    r2941 r2958  
    3636  protected $viewName; 
    3737   
    38    
     38  /** 
     39   * @var        mixed the result of the view execution 
     40   */ 
    3941  protected $viewResult; 
    4042   
     43  /** 
     44   *  creates the view instance for this testcase 
     45   *  
     46   * @return     AgaviView 
     47   *  
     48   * @author     Felix Gilcher <felix.gilcher@bitextender.com> 
     49   * @since      1.0.0 
     50   */ 
    4151  protected function createViewInstance() 
    4252  { 
     
    4858  } 
    4959   
     60  /** 
     61   *  runs the view instance for this testcase 
     62   *  
     63   * @param      string the name of the output type to run the view for 
     64   *                    null for the default output type 
     65   *  
     66   * @author     Felix Gilcher <felix.gilcher@bitextender.com> 
     67   * @since      1.0.0 
     68   */ 
    5069  protected function runView($otName = null) 
    5170  { 
     
    92111  } 
    93112   
    94   protected function assertResponseHasRedirect($expected, $message = '') 
    95   { 
    96      
    97   } 
    98    
    99   protected function assertResponseHasHeader($expected, $expectedValue = null, $message = '') 
    100   { 
    101      
    102   } 
    103    
    104   protected function assertResponseHasHTTPStatus($expected, $message = 'Failed asserting that the respons status is %1$s') 
     113  protected function assertResponseHasRedirect($message = 'Failed asserting that the view redirects') 
     114  { 
     115    $response = $this->container->getResponse(); 
     116    try { 
     117      $this->assertTrue($response->hasRedirect(), $message); 
     118    } catch (AgaviException $e) { 
     119      $this->fail($message); 
     120    } 
     121  } 
     122   
     123  protected function assertResponseHasNoRedirect($message = 'Failed asserting that the view does not redirect') 
     124  { 
     125    $response = $this->container->getResponse(); 
     126    try { 
     127      $this->assertFalse($response->hasRedirect(), $message); 
     128    } catch (AgaviException $e) { 
     129      $this->fail($message); 
     130    } 
     131  } 
     132   
     133  protected function assertResponseRedirectsTo($expected, $message = 'Failed asserting that the view redirects to the given target.') 
     134  { 
     135    $response = $this->container->getResponse(); 
     136    try { 
     137      $this->assertEquals($expected, $response->getRedirect(), $message); 
     138    } catch (AgaviException $e) { 
     139      $this->fail($message); 
     140    } 
     141  } 
     142   
     143  protected function assertResponseHasContentType($expected, $message = 'Failed asserting that the response content type is %1$s.') 
    105144  { 
    106145    $response = $this->container->getResponse(); 
     
    109148      $this->fail(sprintf($message . ' (response is not an AgaviWebResponse)', $expected)); 
    110149    } 
     150    $this->assertEquals($expected, $response->getContentType(), sprintf($message, $expected)); 
     151  } 
     152   
     153  protected function assertResponseHasHeader($expected, $expectedValue = null, $message = 'Failed asserting that the response has a header named <%1$s> with the value <%2$s>') 
     154  { 
     155    $response = $this->container->getResponse(); 
     156     
     157    if(!($response instanceof AgaviWebResponse)) { 
     158      $this->fail(sprintf($message . ' (response is not an AgaviWebResponse)', $expected)); 
     159    } 
     160    $this->assertEquals($expected, $response->getHeader($expected), sprintf($message, $expected, $expectedValue)); 
     161  } 
     162   
     163  protected function assertResponseHasHTTPStatus($expected, $message = 'Failed asserting that the respons status is %1$s.') 
     164  { 
     165    $response = $this->container->getResponse(); 
     166     
     167    if(!($response instanceof AgaviWebResponse)) { 
     168      $this->fail(sprintf($message . ' (response is not an AgaviWebResponse)', $expected)); 
     169    } 
    111170    $this->assertEquals($expected, $response->getHttpStatusCode(), sprintf($message, $expected)); 
    112171  } 
    113172   
    114   protected function assertResponseHasContent($expected, $message = 'Failed asserting that the response has content <%1$s>') 
     173  protected function assertResponseHasContent($expected, $message = 'Failed asserting that the response has content <%1$s>.') 
    115174  { 
    116175    $response = $this->container->getResponse(); 
    117176    $this->assertEquals($expected, $response->getContent(), sprintf($message, $expected)); 
     177  } 
     178   
     179  protected function assertViewResultEquals($expected, $message = 'Failed asserting the expected view result.') 
     180  { 
     181    $this->assertEquals($expected, $this->viewResult, sprintf($message, $expected)); 
    118182  } 
    119183   
     
    122186    if (!($this->viewResult instanceof AgaviExecutionContainer)) 
    123187    { 
    124       $this->fail('Failed asserting that the view result is a forward'); 
     188      $this->fail('Failed asserting that the view result is a forward.'); 
    125189    } 
    126190  } 
     
    133197    if (null == $layer) 
    134198    { 
    135       $this->fail('Failed asserting that the view contains the layer'); 
     199      $this->fail('Failed asserting that the view contains the layer.'); 
    136200    } 
    137201  }