Changeset 2913

Show
Ignore:
Timestamp:
09/19/08 19:16:47 (4 months ago)
Author:
david
Message:

tests for sample app, they work again now after [2904] which merged [2903] (and [2912] / [2911]). this is good fun. refs #859, #861 and #380

Location:
branches/1.0/samples/test/tests
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/samples/test/tests/fragment/SearchEngineSpamActionTest.php

    r2893 r2913  
    33class SearchEngineSpamActionTest extends AgaviActionTestCase 
    44{ 
     5  protected static $products = array( 
     6    array( 
     7      'id'    => 8172401, 
     8      'name'  => 'brains', 
     9      'price' => 0.89, 
     10    ), 
     11    array( 
     12      'id'    => 917246, 
     13      'name'  => 'chainsaws', 
     14      'price' => 129.99, 
     15    ), 
     16    array( 
     17      'id'    => 7856122, 
     18      'name'  => 'mad coding skills', 
     19      'price' => 14599, 
     20    ), 
     21    array( 
     22      'id'    => 123456, 
     23      'name'  => 'nonsense', 
     24      'price' => 3.14, 
     25    ), 
     26    array( 
     27      'id'    => 3165463, 
     28      'name'  => 'viagra', 
     29      'price' => 14.69, 
     30    ), 
     31  ); 
    532   
    633  public function __construct($name = NULL, array $data = array(), $dataName = '') 
     
    1239   
    1340  /** 
    14    * @dataProvider products 
     41   * @dataProvider successViewValidProductsData 
    1542   */ 
    16   public function testSuccessViewValidProducts($productName) 
     43  public function testSuccessViewValidProducts($parameters, $price) 
    1744  { 
    1845    $this->setRequestMethod('read'); 
    19     $this->setArguments($this->createRequestDataHolder(array(AgaviWebRequestDataHolder::SOURCE_PARAMETERS => array('name' => $productName)))); 
    20     $this->performValidation(); 
    21     //$this->assertValidatesArgument('name', 'AgaviStringValidator', array('min' => 5)); 
     46    $this->setArguments($this->createRequestDataHolder(array(AgaviWebRequestDataHolder::SOURCE_PARAMETERS => $parameters))); 
    2247    $this->runAction(); 
    2348    $this->assertViewNameEquals('Success'); 
    2449    $this->assertViewModuleNameEquals('Default'); 
    2550    $this->assertContainerAttributeExists('product_price'); 
    26     $this->assertContainerAttributeEquals($productName, 'product_name'); 
    27      
     51    $this->assertContainerAttributeEquals($price, 'product_price'); 
    2852  } 
    2953   
    30   public function testErrorViewInvalidProduct() 
     54  public function successViewValidProductsData() 
     55  { 
     56    $retval = array(); 
     57    foreach(self::$products as $product) { 
     58      $retval['id only: ' . $product['id']] = array(array('id' => $product['id']), $product['price']); 
     59    } 
     60    foreach(self::$products as $product) { 
     61      $retval['id+name: ' . $product['id'] . '/' . $product['name']] = array(array('id' => $product['id'], 'name' => $product['name']), $product['price']); 
     62    } 
     63    return $retval; 
     64  } 
     65   
     66  /** 
     67   * @dataProvider errorViewInvalidProductsData 
     68   */ 
     69  public function testErrorViewInvalidProducts($parameters) 
    3170  { 
    3271    $this->setRequestMethod('read'); 
    33     $this->setArguments($this->createRequestDataHolder(array(AgaviWebRequestDataHolder::SOURCE_PARAMETERS => array('name' => 'nonexistant product')))); 
     72    $this->setArguments($this->createRequestDataHolder(array(AgaviWebRequestDataHolder::SOURCE_PARAMETERS => $parameters))); 
    3473    $this->runAction(); 
    3574    $this->assertViewNameEquals('Error'); 
    3675    $this->assertViewModuleNameEquals('Default'); 
     76  } 
     77   
     78  public function errorViewInvalidProductsData() 
     79  { 
     80    return array( 
     81      'only product name given' => array(array('name' => 'nonsense')), 
     82      'invalid product id given' => array(array('id' => 81236123)), 
     83      'negative product id given' => array(array('id' => -1)), 
     84      'id and name given, id invalid' => array(array('id' => 123457, 'name' => 'nonsense')), 
     85      'id and name given, name invalid' => array(array('id' => 123456, 'name' => 'nonsenseZOMG')), 
     86      'id and name given, both invalid' => array(array('id' => -1, 'name' => 'nonsenseZOMG')), 
     87    ); 
    3788  } 
    3889   
     
    59110  public function products() 
    60111  { 
     112     
    61113    return array( 
    62114      'brains'    => array('brains'), 
  • branches/1.0/samples/test/tests/unit/PriceFinderModelTest.php

    r2893 r2913  
    44class PriceFinderModelTest extends AgaviUnitTestCase 
    55{ 
     6  protected static $products = array( 
     7    array( 
     8      'id'    => 8172401, 
     9      'name'  => 'brains', 
     10      'price' => 0.89, 
     11    ), 
     12    array( 
     13      'id'    => 917246, 
     14      'name'  => 'chainsaws', 
     15      'price' => 129.99, 
     16    ), 
     17    array( 
     18      'id'    => 7856122, 
     19      'name'  => 'mad coding skills', 
     20      'price' => 14599, 
     21    ), 
     22    array( 
     23      'id'    => 123456, 
     24      'name'  => 'nonsense', 
     25      'price' => 3.14, 
     26    ), 
     27    array( 
     28      'id'    => 3165463, 
     29      'name'  => 'viagra', 
     30      'price' => 14.69, 
     31    ), 
     32  ); 
     33   
    634  /** 
    7    * @dataProvider productPrices 
     35   * @dataProvider productNamePrices 
    836   */ 
    9   public function testValidProductPrices($productName, $price) 
     37  public function testValidProductPricesByName($productName, $price) 
    1038  { 
    1139    $finder = $this->getContext()->getModel('PriceFinder', 'Default'); 
     
    1341  } 
    1442   
    15   public function productPrices() 
     43  public function productNamePrices() 
    1644  { 
    17     return array( 
    18       'brains'    => array('brains', 0.89), 
    19       'chainsaws' => array('chainsaws', 129.99), 
    20       'coding'    => array('mad coding skills', 14599), 
    21       'nonsense'  => array('nonsense', 3.14), 
    22       'viagra'    => array('viagra', 14.69), 
    23     ); 
     45    $retval = array(); 
     46    foreach(self::$products as $product) { 
     47      $retval[$product['name']] = array( 
     48        $product['name'], 
     49        $product['price'], 
     50      ); 
     51    } 
     52    return $retval; 
    2453  } 
    2554   
    26   public function testPriceNullForUnknownProduct() 
     55  /** 
     56   * @dataProvider productIdPrices 
     57   */ 
     58  public function testValidProductPricesById($productId, $price) 
     59  { 
     60    $finder = $this->getContext()->getModel('PriceFinder', 'Default'); 
     61    $this->assertEquals($price, $finder->getPriceByProductId($productId)); 
     62  } 
     63   
     64  public function productIdPrices() 
     65  { 
     66    $retval = array(); 
     67    foreach(self::$products as $product) { 
     68      $retval[$product['name']] = array( 
     69        $product['id'], 
     70        $product['price'], 
     71      ); 
     72    } 
     73    return $retval; 
     74  } 
     75   
     76  /** 
     77   * @dataProvider productInfoPrices 
     78   */ 
     79  public function testValidProductPricesByInfo($productId, $productName, $price) 
     80  { 
     81    $finder = $this->getContext()->getModel('PriceFinder', 'Default'); 
     82    $this->assertEquals($price, $finder->getPriceByProductInfo($productId, $productName)); 
     83  } 
     84   
     85  public function productInfoPrices() 
     86  { 
     87    $retval = array(); 
     88    foreach(self::$products as $product) { 
     89      $retval[$product['name']] = array( 
     90        $product['id'], 
     91        $product['name'], 
     92        $product['price'], 
     93      ); 
     94    } 
     95    return $retval; 
     96  } 
     97   
     98  public function testPriceNullForUnknownProductName() 
    2799  { 
    28100    $this->assertNull($this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductName('unknown product')); 
     101  } 
     102   
     103  public function testPriceNullForUnknownProductId() 
     104  { 
     105    $this->assertNull($this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductId(-1)); 
     106  } 
     107   
     108  public function testPriceNullForUnknownProductInfo() 
     109  { 
     110    $this->assertNull($this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductInfo(-1, 'unknown product')); 
     111  } 
     112   
     113  public function testPriceNullForPartiallyValidProductInfo() 
     114  { 
     115    $this->assertNull($this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductInfo(123456, 'nonsenseZOMG')); 
     116    $this->assertNull($this->getContext()->getModel('PriceFinder', 'Default')->getPriceByProductInfo(1234567, 'nonsense')); 
    29117  } 
    30118}