Changeset 2913
- Timestamp:
- 09/19/08 19:16:47 (4 months ago)
- Location:
- branches/1.0/samples/test/tests
- Files:
-
- 2 modified
-
fragment/SearchEngineSpamActionTest.php (modified) (3 diffs)
-
unit/PriceFinderModelTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/samples/test/tests/fragment/SearchEngineSpamActionTest.php
r2893 r2913 3 3 class SearchEngineSpamActionTest extends AgaviActionTestCase 4 4 { 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 ); 5 32 6 33 public function __construct($name = NULL, array $data = array(), $dataName = '') … … 12 39 13 40 /** 14 * @dataProvider products41 * @dataProvider successViewValidProductsData 15 42 */ 16 public function testSuccessViewValidProducts($p roductName)43 public function testSuccessViewValidProducts($parameters, $price) 17 44 { 18 45 $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))); 22 47 $this->runAction(); 23 48 $this->assertViewNameEquals('Success'); 24 49 $this->assertViewModuleNameEquals('Default'); 25 50 $this->assertContainerAttributeExists('product_price'); 26 $this->assertContainerAttributeEquals($productName, 'product_name'); 27 51 $this->assertContainerAttributeEquals($price, 'product_price'); 28 52 } 29 53 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) 31 70 { 32 71 $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))); 34 73 $this->runAction(); 35 74 $this->assertViewNameEquals('Error'); 36 75 $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 ); 37 88 } 38 89 … … 59 110 public function products() 60 111 { 112 61 113 return array( 62 114 'brains' => array('brains'), -
branches/1.0/samples/test/tests/unit/PriceFinderModelTest.php
r2893 r2913 4 4 class PriceFinderModelTest extends AgaviUnitTestCase 5 5 { 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 6 34 /** 7 * @dataProvider product Prices35 * @dataProvider productNamePrices 8 36 */ 9 public function testValidProductPrices ($productName, $price)37 public function testValidProductPricesByName($productName, $price) 10 38 { 11 39 $finder = $this->getContext()->getModel('PriceFinder', 'Default'); … … 13 41 } 14 42 15 public function product Prices()43 public function productNamePrices() 16 44 { 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; 24 53 } 25 54 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() 27 99 { 28 100 $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')); 29 117 } 30 118 }

