From 1a6148f0e41708c32fd410cc7530d9fb1efebcae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 3 Aug 2010 13:41:44 -0700 Subject: [PATCH] initial unit tests for activity generation --- tests/ActivityGenerationTests.php | 182 ++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 tests/ActivityGenerationTests.php diff --git a/tests/ActivityGenerationTests.php b/tests/ActivityGenerationTests.php new file mode 100644 index 0000000000..a2e3c2480a --- /dev/null +++ b/tests/ActivityGenerationTests.php @@ -0,0 +1,182 @@ +author1 = User::register(array('nickname' => $authorNick1, + 'email' => $authorNick1 . '@example.net', + 'email_confirmed' => true)); + + $this->author2 = User::register(array('nickname' => $authorNick2, + 'email' => $authorNick2 . '@example.net', + 'email_confirmed' => true)); + + $this->targetUser1 = User::register(array('nickname' => $targetNick1, + 'email' => $targetNick1 . '@example.net', + 'email_confirmed' => true)); + + $this->targetUser2 = User::register(array('nickname' => $targetNick2, + 'email' => $targetNick2 . '@example.net', + 'email_confirmed' => true)); + + } + + public function testBasicNoticeActivity() + { + $notice = $this->_fakeNotice(); + + $entry = $notice->asAtomEntry(true); + + echo $entry; + + $element = $this->_entryToElement($entry, false); + + $this->assertEquals($notice->uri, ActivityUtils::childContent($element, 'id')); + $this->assertEquals($notice->content, ActivityUtils::childContent($element, 'title')); + $this->assertEquals($notice->rendered, ActivityUtils::childContent($element, 'content')); + $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'published'))); + $this->assertEquals(strtotime($notice->created), strtotime(ActivityUtils::childContent($element, 'updated'))); + $this->assertEquals(ActivityVerb::POST, ActivityUtils::childContent($element, 'verb', Activity::SPEC)); + $this->assertEquals(ActivityObject::NOTE, ActivityUtils::childContent($element, 'object-type', Activity::SPEC)); + } + + public function testNamespaceFlag() + { + $notice = $this->_fakeNotice(); + + $entry = $notice->asAtomEntry(true); + + $element = $this->_entryToElement($entry, false); + + $this->assertTrue($element->hasAttribute('xmlns')); + $this->assertTrue($element->hasAttribute('xmlns:thr')); + $this->assertTrue($element->hasAttribute('xmlns:georss')); + $this->assertTrue($element->hasAttribute('xmlns:activity')); + $this->assertTrue($element->hasAttribute('xmlns:media')); + $this->assertTrue($element->hasAttribute('xmlns:poco')); + $this->assertTrue($element->hasAttribute('xmlns:ostatus')); + $this->assertTrue($element->hasAttribute('xmlns:statusnet')); + + $entry = $notice->asAtomEntry(false); + + $element = $this->_entryToElement($entry, true); + + $this->assertFalse($element->hasAttribute('xmlns')); + $this->assertFalse($element->hasAttribute('xmlns:thr')); + $this->assertFalse($element->hasAttribute('xmlns:georss')); + $this->assertFalse($element->hasAttribute('xmlns:activity')); + $this->assertFalse($element->hasAttribute('xmlns:media')); + $this->assertFalse($element->hasAttribute('xmlns:poco')); + $this->assertFalse($element->hasAttribute('xmlns:ostatus')); + $this->assertFalse($element->hasAttribute('xmlns:statusnet')); + } + + public function testReplyActivity() + { + $this->assertTrue(FALSE); + } + + public function testMultipleReplyActivity() + { + $this->assertTrue(FALSE); + } + + public function testGroupPostActivity() + { + $this->assertTrue(FALSE); + } + + public function testMultipleGroupPostActivity() + { + $this->assertTrue(FALSE); + } + + public function testRepeatActivity() + { + $this->assertTrue(FALSE); + } + + public function testTaggedActivity() + { + $this->assertTrue(FALSE); + } + + public function testGeotaggedActivity() + { + $this->assertTrue(FALSE); + } + + public function tearDown() + { + $this->author1->delete(); + $this->author2->delete(); + $this->targetUser1->delete(); + $this->targetUser2->delete(); + } + + private function _fakeNotice($user = null, $text = null) + { + if (empty($user)) { + $user = $this->author1; + } + + if (empty($text)) { + $text = "fake-o text-o " . common_good_rand(32); + } + + return Notice::saveNew($user->id, $text, 'test', array('uri' => null)); + } + + private function _entryToElement($entry, $namespace = false) + { + $xml = ''."\n\n"; + $xml .= '' . "\n"; + $doc = DOMDocument::loadXML($xml); + $feed = $doc->documentElement; + $entries = $feed->getElementsByTagName('entry'); + + return $entries->item(0); + } +} -- 2.39.5