Skip to content

Commit

Permalink
added getFileExtension() and buildPasswordField()
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Toppa committed Aug 13, 2011
1 parent 3a025e4 commit 4a64662
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ToppaFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
16 changes: 16 additions & 0 deletions ToppaHtmlFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
10 changes: 10 additions & 0 deletions tests/UnitToppaFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.