| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/cli/src/lmbCliOption.class.php'); 10 11 12 class lmbCliOptionTest extends UnitTestCase 13 { 14 function testCreateException() 15 { 16 try 17 { 18 $opt = new lmbCliOption('foo', 'f'); 19 $this->assertTrue(false); 20 } 21 catch(lmbCliException $e){} 22 } 23 24 function testCreateWithShortNameOnly() 25 { 26 $opt = new lmbCliOption('s', lmbCliOption :: VALUE_REQ); 27 $this->assertNull($opt->getLongName()); 28 $this->assertEqual($opt->getShortName(), 's'); 29 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_REQ); 30 $this->assertEqual($opt->toString(), '-s'); 31 } 32 33 function testCreateWithLongNameOnly() 34 { 35 $opt = new lmbCliOption('foo', lmbCliOption :: VALUE_REQ); 36 $this->assertNull($opt->getShortName()); 37 $this->assertEqual($opt->getLongName(), 'foo'); 38 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_REQ); 39 $this->assertEqual($opt->toString(), '--foo'); 40 } 41 42 function testCreateWithBothNames() 43 { 44 $opt = new lmbCliOption('f', 'foo', lmbCliOption :: VALUE_REQ); 45 $this->assertEqual($opt->getShortName(), 'f'); 46 $this->assertEqual($opt->getLongName(), 'foo'); 47 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_REQ); 48 $this->assertEqual($opt->toString(), '-f|--foo'); 49 } 50 51 function testDefaultValueMode() 52 { 53 $opt = new lmbCliOption('s'); 54 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_NO); 55 56 $opt = new lmbCliOption('foo'); 57 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_NO); 58 59 $opt = new lmbCliOption('f', 'foo'); 60 $this->assertEqual($opt->getValueMode(), lmbCliOption :: VALUE_NO); 61 } 62 63 function testValueMode() 64 { 65 $opt = new lmbCliOption('s'); 66 $this->assertTrue($opt->isValueForbidden()); 67 68 $opt = new lmbCliOption('s', lmbCliOption :: VALUE_REQ); 69 $this->assertTrue($opt->isValueRequired()); 70 71 $opt = new lmbCliOption('s', lmbCliOption :: VALUE_OPT); 72 $this->assertTrue($opt->isValueOptional()); 73 } 74 75 function testMatchSingleName() 76 { 77 $opt = new lmbCliOption('s'); 78 $this->assertTrue($opt->match('s')); 79 $this->assertFalse($opt->match('b')); 80 81 $opt = new lmbCliOption('foo'); 82 $this->assertTrue($opt->match('foo')); 83 $this->assertFalse($opt->match('aaa')); 84 } 85 86 function testMatchAnyName() 87 { 88 $opt = new lmbCliOption('f', 'foo'); 89 $this->assertTrue($opt->match('foo')); 90 $this->assertTrue($opt->match('f')); 91 } 92 93 function testGetSetValue() 94 { 95 $opt = new lmbCliOption('f'); 96 97 $this->assertNull($opt->getValue()); 98 99 $opt->setValue('wow'); 100 $this->assertEqual($opt->getValue(), 'wow'); 101 } 102 103 function testIsPresent() 104 { 105 $opt = new lmbCliOption('f'); 106 $this->assertFalse($opt->isPresent()); 107 108 $opt->touch(); 109 $this->assertTrue($opt->isPresent()); 110 } 111 112 function testIsPresentAfterSettingValue() 113 { 114 $opt = new lmbCliOption('f'); 115 $this->assertFalse($opt->isPresent()); 116 117 $opt->setValue(1); 118 $this->assertTrue($opt->isPresent()); 119 } 120 121 function testValidateRequiredValue() 122 { 123 $opt = new lmbCliOption('f', lmbCliOption :: VALUE_REQ); 124 125 try 126 { 127 $opt->validate(); 128 $this->assertTrue(false); 129 } 130 catch(lmbCliException $e){} 131 } 132 133 function testValidateForbiddenValue() 134 { 135 $opt = new lmbCliOption('f', lmbCliOption :: VALUE_NO); 136 $opt->validate(); //should pass 137 138 $opt->setValue(1); 139 140 try 141 { 142 $opt->validate(); 143 $this->assertTrue(false); 144 } 145 catch(lmbCliException $e){} 146 } 147 148 } 149 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Sep 6 04:46:52 2008 | Cross-referenced by PHPXref 0.7 |