From: Chuck Hagenbuch Date: Sun, 8 Feb 2009 02:41:54 +0000 (-0500) Subject: add tests for date math, date corrections, tokens, and spans X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=25b9e0d407b9702cbd9bba3128fd4a74d05f8e21;p=horde.git add tests for date math, date corrections, tokens, and spans --- diff --git a/framework/Date_Parser/lib/Horde/Date/Parser/Token.php b/framework/Date_Parser/lib/Horde/Date/Parser/Token.php index 679a8f415..9019d258a 100644 --- a/framework/Date_Parser/lib/Horde/Date/Parser/Token.php +++ b/framework/Date_Parser/lib/Horde/Date/Parser/Token.php @@ -13,17 +13,17 @@ class Horde_Date_Parser_Token /** * Tag this token with the specified tag */ - public function tag($new_tag) + public function tag($tag) { - $this->tags[] = $new_tag; + $this->tags[] = $tag; } /** * Remove all tags of the given class */ - public function untag($tag_class) + public function untag($tagClass) { - $this->tags = array_filter($this->tags, create_function('$t', 'return $t instanceof ' . $tag_class . ';')); + $this->tags = array_filter($this->tags, create_function('$t', 'return $t instanceof ' . $tagClass . ';')); } /** @@ -37,9 +37,9 @@ class Horde_Date_Parser_Token /** * Return the Tag that matches the given class */ - public function getTag($tag_class) + public function getTag($tagClass) { - $matches = array_filter($this->tags, create_function('$t', 'return $t instanceof ' . $tag_class . ';')); + $matches = array_filter($this->tags, create_function('$t', 'return $t instanceof ' . $tagClass . ';')); return array_shift($matches); } diff --git a/framework/Date_Parser/test/Horde/Date/DateTest.php b/framework/Date_Parser/test/Horde/Date/DateTest.php new file mode 100644 index 000000000..2f5b0b4dd --- /dev/null +++ b/framework/Date_Parser/test/Horde/Date/DateTest.php @@ -0,0 +1,47 @@ +month -= 2; + $this->assertEquals(2007, $d->year); + + $d = new Horde_Date('2008-01-01 00:00:00'); + $d->day -= 1; + $this->assertEquals(2007, $d->year); + $this->assertEquals(12, $d->month); + + $d = new Horde_Date('2008-01-01 00:00:00'); + $d->day += 370; + $this->assertEquals(2009, $d->year); + $this->assertEquals(1, $d->month); + + $d = new Horde_Date('2008-01-01 00:00:00'); + $d->sec += 14400; + $this->assertEquals(0, $d->sec); + $this->assertEquals(0, $d->min); + $this->assertEquals(4, $d->hour); + } + + public function testDateMath() + { + $d = new Horde_Date('2008-01-01 00:00:00'); + + $this->assertEquals('2007-12-31 00:00:00', (string)$d->sub(array('day' => 1))); + $this->assertEquals('2009-01-01 00:00:00', (string)$d->add(array('year' => 1))); + $this->assertEquals('2008-01-01 04:00:00', (string)$d->add(14400)); + } + +} diff --git a/framework/Date_Parser/test/Horde/Date/Parser/TokenTest.php b/framework/Date_Parser/test/Horde/Date/Parser/TokenTest.php new file mode 100644 index 000000000..71953dc62 --- /dev/null +++ b/framework/Date_Parser/test/Horde/Date/Parser/TokenTest.php @@ -0,0 +1,42 @@ +assertEquals('foo', $token->word); + $this->assertEquals(0, count($token->tags)); + $this->assertFalse($token->tagged()); + + $token->tag(new FooTag('mytag')); + $this->assertEquals(1, count($token->tags)); + $this->assertTrue($token->tagged()); + $this->assertType('FooTag', $token->getTag('FooTag')); + + $token->tag(new BarTag(5)); + $this->assertEquals(2, count($token->tags)); + + $token->untag('FooTag'); + $this->assertEquals(1, count($token->tags)); + } + +} + +class FooTag extends Horde_Date_Parser_Tag +{ +} + +class BarTag extends Horde_Date_Parser_Tag +{ +} diff --git a/framework/Date_Parser/test/Horde/Date/SpanTest.php b/framework/Date_Parser/test/Horde/Date/SpanTest.php new file mode 100644 index 000000000..f0722b71b --- /dev/null +++ b/framework/Date_Parser/test/Horde/Date/SpanTest.php @@ -0,0 +1,30 @@ +assertEquals(60 * 60 * 24, $s->width()); + } + + public function testSpanMath() + { + $s = new Horde_Date_Span(new Horde_Date(1), new Horde_Date(2)); + $this->assertEquals(2, $s->add(1)->begin->timestamp()); + $this->assertEquals(3, $s->add(1)->end->timestamp()); + $this->assertEquals(0, $s->sub(1)->begin->timestamp()); + $this->assertEquals(1, $s->sub(1)->end->timestamp()); + } + +}