Permalink
Browse files

Wrote some tests for getMachineTags, fixed truncation offset error

  • Loading branch information...
1 parent 5dfaa07 commit c892ab60520e0178be486750d5e032e084064fd8 @barnabywalters committed Dec 30, 2012
Showing with 78 additions and 1 deletion.
  1. +1 −1 BarnabyWalters/Helpers/Helpers.php
  2. +77 −0 tests/BarnabyWalters/Helpers/HelpersTest.php
@@ -253,7 +253,7 @@ public static function getMachineTags(array $tags, $namespace = null, $trunc = f
$key = array_shift($parts);
if ($namespace !== null and $trunc) {
- $key = substr($key, strlen($namespace));
+ $key = substr($key, strlen($namespace) + 1);
}
$value = implode('=', $parts);
@@ -97,7 +97,84 @@ public function testTagstringToArray() {
$testResult = array('a tag', 'anothertag', '<sometag>');
$this->assertEquals($testResult, H::tagstringToArray($testTagstring));
}
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetMachineTagsIgnoresNonMachineTags() {
+ $arr = [
+ 'machine:tag=yes!',
+ 'non-machine-tag'
+ ];
+
+ $result = H::getMachineTags($arr);
+
+ $this->assertNotContains('non-machine-tag', $result);
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetMachineTagsReturnsAssocArray() {
+ $arr = [
+ 'machine:tag=yes!',
+ 'another:tag=BOO'
+ ];
+
+ $expected = [
+ 'machine:tag' => 'yes!',
+ 'another:tag' => 'BOO'
+ ];
+
+ $result = H::getMachineTags($arr);
+
+ $this->assertEquals($result, $expected);
+ }
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetMachineTagsFiltersByNamespace() {
+ $arr = [
+ 'machine:tag=yes!',
+ 'another:tag=BOO'
+ ];
+
+ $expected = [
+ 'machine:tag' => 'yes!'
+ ];
+
+ $result = H::getMachineTags($arr, 'machine');
+
+ $this->assertEquals($result, $expected);
+ }
+
+ /**
+ * @group unit
+ * @group text
+ * @group helpers
+ */
+ public function testGetMachineTagsTruncatesNamespace() {
+ $arr = [
+ 'machine:tag=yes!',
+ 'another:tag=BOO'
+ ];
+
+ $expected = [
+ 'tag' => 'yes!'
+ ];
+
+ $result = H::getMachineTags($arr, 'machine', true);
+
+ $this->assertEquals($result, $expected);
+ }
+
/**
* @group unit
* @group text

0 comments on commit c892ab6

Please sign in to comment.