Browse files

added getFileExtension() and buildPasswordField()

  • Loading branch information...
1 parent 3a025e4 commit 4a646627675c8610cfebd60fe2e9e67780f60491 @toppa committed Aug 12, 2011
Showing with 38 additions and 0 deletions.
  1. +12 −0 ToppaFunctions.php
  2. +16 −0 ToppaHtmlFormField.php
  3. +10 −0 tests/UnitToppaFunctions.php
View
12 ToppaFunctions.php
@@ -71,4 +71,16 @@ public static function throwExceptionIfNotArray($expectedArray) {
public static function path() {
return dirname(__FILE__);
}
+
+ public static function getFileExtension($fileName) {
+ ToppaFunctions::throwExceptionIfNotString($fileName);
+ $fileNameParts = explode('.', $fileName);
+ $lastIndexPosition = count($fileNameParts) - 1;
+
+ if (!$lastIndexPosition) {
+ return null;
+ }
+
+ return $fileNameParts[$lastIndexPosition];
+ }
}
View
16 ToppaHtmlFormField.php
@@ -43,6 +43,9 @@ public function build() {
case 'text':
return $this->buildTextField();
break;
+ case 'password':
+ return $this->buildPasswordField();
+ break;
case 'radio':
return $this->buildRadioGroup();
break;
@@ -87,6 +90,19 @@ private function buildTextField() {
return $this->tag;
}
+ private function buildPasswordField() {
+ $this->startTag('input');
+ $this->addAttribute('type', 'password');
+ $this->addAttribute('name', $this->name);
+ $this->addAttribute('id', $this->id);
+ $this->addAttribute('value', $this->value);
+ $this->addAttribute('size', $this->refData['input']['size']);
+ $this->addAttribute('class', $this->cssClass);
+ $this->addAttribute('maxlength', $this->refData['db']['length']);
+ $this->selfCloseTag();
+ return $this->tag;
+ }
+
private function buildRadioGroup() {
foreach ($this->refData['input']['subgroup'] as $value=>$label) {
$this->startTag('input');
View
10 tests/UnitToppaFunctions.php
@@ -84,4 +84,14 @@ public function testThrowExceptionIfNotArray() {
$this->pass();
}
}
+
+ public function testGetFileExtensionUsingNameWithMultipleDots() {
+ $extension = ToppaFunctions::getFileExtension('video.test.name.mpg');
+ $this->assertEqual('mpg', $extension);
+ }
+
+ public function testGetFileExtensionUsingNameWithNoDots() {
+ $extension = ToppaFunctions::getFileExtension('video');
+ $this->assertEqual(null, $extension);
+ }
}

0 comments on commit 4a64662

Please sign in to comment.