[MediaWiki-commits] [Gerrit] mediawiki...EventBus[master]: [Tests] Added several basic tests to static helpers
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/378694 ) Change subject: [Tests] Added several basic tests to static helpers .. [Tests] Added several basic tests to static helpers This doesn't really provide great coverage yet, but it's better then nothing. These tests mostly verify that static helper methods work under normal conditions. Bug: T175958 Change-Id: Id304d449b5c083d965e117acdf7eb3efda9cf02e --- M tests/phpunit/EventBusTest.php 1 file changed, 115 insertions(+), 3 deletions(-) Approvals: Mobrovac: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/phpunit/EventBusTest.php b/tests/phpunit/EventBusTest.php index 74ce178..d3fbbdd 100644 --- a/tests/phpunit/EventBusTest.php +++ b/tests/phpunit/EventBusTest.php @@ -1,8 +1,120 @@ assertTrue( true ); + public function testCreateEvent() { + $event = EventBus::createEvent( + 'http://test.wikipedia.org/wiki/TestPage', + 'test_topic', + [ + 'test_property_string' => 'test_value', + 'test_property_int'=> 42 + ] + ); + + $this->assertNotNull( $event ); + + // Meta property checks + $this->assertNotNull( $event['meta'] ); + $this->assertEquals( 'http://test.wikipedia.org/wiki/TestPage', $event['meta']['uri'] ); + $this->assertEquals( 'test_topic', $event['meta']['topic'] ); + $this->assertNotNull( $event['meta']['request_id'] ); + $this->assertNotNull( $event['meta']['id'] ); + $this->assertNotNull( $event['meta']['dt'] ); + $this->assertNotNull( $event['meta']['domain'] ); + + // Event properties checks + $this->assertEquals( 'test_value', $event['test_property_string'] ); + $this->assertEquals( 42, $event['test_property_int'] ); + } + + public function testGetArticleURL() { + $url = EventBus::getArticleURL( Title::newFromDBkey( 'Main_Page' ) ); + $this->assertStringEndsWith( 'Main_Page', $url ); + } + + public function testCreatePerformerAttrs() { + $user = $this->getTestUser( [ 'testers' ] )->getUser(); + $performerAttrs = EventBus::createPerformerAttrs( $user ); + + $this->assertEquals( $user->getName(), $performerAttrs['user_text'] ); + $this->assertContains( 'testers', $performerAttrs['user_groups'] ); + $this->assertFalse( $performerAttrs['user_is_bot'] ); + $this->assertEquals( 0, $performerAttrs['user_edit_count'] ); + $this->assertEquals( $user->getId(), $performerAttrs['user_id'] ); + } + + function newTestRevision( $text, $title = "Test", + $model = CONTENT_MODEL_WIKITEXT, $format = null + ) { + if ( is_string( $title ) ) { + $title = Title::newFromText( $title ); + } + + $content = ContentHandler::makeContent( $text, $title, $model, $format ); + + $rev = new Revision( + [ + 'id' => 42, + 'page' => 23, + 'title' => $title, + + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", + 'minor_edit' => false, + + 'content_format' => $format, + ] + ); + + return $rev; + } + + public function testCreateRevisionAttrs() { + global $wgDBname; + + $title = Title::newFromText( 'Test' ); + $content = ContentHandler::makeContent( + 'Bla bla bla', + $title, + CONTENT_MODEL_WIKITEXT, + null ); + + $rev = new Revision( + [ + 'id' => 42, + 'page' => 23, + 'title' => $title, + 'rev_user' => $this->getTestUser( [ 'testers' ] ), + + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", + 'minor_edit' => false, + + 'content_format' => null, + ] + ); + + $revisionAttrs = EventBus::createRevisionAttrs( $rev ); + +
[MediaWiki-commits] [Gerrit] mediawiki...EventBus[master]: [Tests] Added several basic tests to static helpers
Ppchelko has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/378694 ) Change subject: [Tests] Added several basic tests to static helpers .. [Tests] Added several basic tests to static helpers This doesn't really provide great coverage yet, but it's better then nothing. These tests mostly verify that static helper methods work under normal conditions. Bug: T175958 Change-Id: Id304d449b5c083d965e117acdf7eb3efda9cf02e --- M tests/phpunit/EventBusTest.php 1 file changed, 116 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/EventBus refs/changes/94/378694/1 diff --git a/tests/phpunit/EventBusTest.php b/tests/phpunit/EventBusTest.php index 74ce178..e05654f 100644 --- a/tests/phpunit/EventBusTest.php +++ b/tests/phpunit/EventBusTest.php @@ -1,8 +1,121 @@ assertTrue( true ); + public function testCreateEvent() { + $event = EventBus::createEvent( + 'http://test.wikipedia.org/wiki/TestPage', + 'test_topic', + array( + 'test_property_string' => 'test_value', + 'test_property_int'=> 42 + ) + ); + + $this->assertNotNull( $event ); + + // Meta property checks + $this->assertNotNull( $event['meta'] ); + $this->assertEquals( 'http://test.wikipedia.org/wiki/TestPage', $event['meta']['uri'] ); + $this->assertEquals( 'test_topic', $event['meta']['topic'] ); + $this->assertNotNull( $event['meta']['request_id'] ); + $this->assertNotNull( $event['meta']['id'] ); + $this->assertNotNull( $event['meta']['dt'] ); + $this->assertNotNull( $event['meta']['domain'] ); + + // Event properties checks + $this->assertEquals('test_value', $event['test_property_string'] ); + $this->assertEquals( 42, $event['test_property_int'] ); + } + + public function testGetArticleURL() { + $url = EventBus::getArticleURL( Title::newFromDBkey('Main_Page') ); + $this->assertStringEndsWith( 'Main_Page', $url ); + } + + public function testCreatePerformerAttrs() { + $user = $this->getTestUser( [ 'testers' ] )->getUser(); + $performerAttrs = EventBus::createPerformerAttrs( $user ); + + $this->assertEquals( $user->getName(), $performerAttrs['user_text'] ); + $this->assertEquals( ['testers','*','user'], $performerAttrs['user_groups'] ); + $this->assertFalse( $performerAttrs['user_is_bot'] ); + $this->assertEquals( 0, $performerAttrs['user_edit_count'] ); + $this->assertEquals( $user->getId(), $performerAttrs['user_id'] ); + } + + + function newTestRevision( $text, $title = "Test", + $model = CONTENT_MODEL_WIKITEXT, $format = null + ) { + if ( is_string( $title ) ) { + $title = Title::newFromText( $title ); + } + + $content = ContentHandler::makeContent( $text, $title, $model, $format ); + + $rev = new Revision( + [ + 'id' => 42, + 'page' => 23, + 'title' => $title, + + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", + 'minor_edit' => false, + + 'content_format' => $format, + ] + ); + + return $rev; + } + + public function testCreateRevisionAttrs() { + global $wgDBname; + + $title = Title::newFromText( 'Test' ); + $content = ContentHandler::makeContent( + 'Bla bla bla', + $title, + CONTENT_MODEL_WIKITEXT, + null ); + + $rev = new Revision( + [ + 'id' => 42, + 'page' => 23, + 'title' => $title, + 'rev_user' => $this->getTestUser([ 'testers' ] ), + + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", + 'minor_edit' => false, + + 'content_format' => null, + ] + ); + + $revisionAttrs =