Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/107560
Change subject: Add fromStorageRow -> toStorageRow roundtrip test ...................................................................... Add fromStorageRow -> toStorageRow roundtrip test Meanwhile added a helper testcase that will generate a $this->revision so we don't have to manually build revision objects in new tests. Change-Id: Ib058c67fdc844b3162d0f31ff2c0db587971c09f --- M Flow.php A tests/PostRevisionTest.php A tests/PostRevisionTestCase.php 3 files changed, 136 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/60/107560/1 diff --git a/Flow.php b/Flow.php index 551538b..61615a8 100755 --- a/Flow.php +++ b/Flow.php @@ -152,6 +152,9 @@ $wgAutoloadClasses['Flow\Block\TopicBlock'] = $dir . 'includes/Block/Topic.php'; $wgAutoloadClasses['Flow\Block\TopicView'] = $dir . 'includes/Block/Topic.php'; +// phpunit helper +$wgAutoloadClasses['Flow\Tests\PostRevisionTestCase'] = $dir . 'tests/PostRevisionTestCase.php'; + // API modules $wgAutoloadClasses['ApiQueryFlow'] = "$dir/includes/api/ApiQueryFlow.php"; $wgAutoloadClasses['ApiParsoidUtilsFlow'] = "$dir/includes/api/ApiParsoidUtilsFlow.php"; diff --git a/tests/PostRevisionTest.php b/tests/PostRevisionTest.php new file mode 100644 index 0000000..6f8130a --- /dev/null +++ b/tests/PostRevisionTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Flow\Tests; + +use Flow\Model\PostRevision; + +class PostRevisionTest extends PostRevisionTestCase { + /** + * Tests that a PostRevision::fromStorageRow & ::toStorageRow roundtrip + * returns the same DB data. + */ + public function testRoundtrip() { + $row = $this->generateRow(); + $object = PostRevision::fromStorageRow( $row ); + + // toStorageRow will add a bogus column 'rev_content_url' - that's ok. + // It'll be caught in code to distinguish between external content and + // content to be saved in rev_content, and, before inserting into DB, + // it'll be unset. We'll ignore this column here. + $roundtripRow = PostRevision::toStorageRow( $object ); + unset( $roundtripRow['rev_content_url'] ); + + $this->assertEquals( $roundtripRow, $row ); + } +} diff --git a/tests/PostRevisionTestCase.php b/tests/PostRevisionTestCase.php new file mode 100644 index 0000000..95a2894 --- /dev/null +++ b/tests/PostRevisionTestCase.php @@ -0,0 +1,108 @@ +<?php + +namespace Flow\Tests; + +use Flow\Model\PostRevision; +use Flow\Model\UUID; +use User; + +class PostRevisionTestCase extends \MediaWikiTestCase { + /** + * PostRevision object, created from $this->generatePost() + * + * @var PostRevision + */ + protected $revision; + + public function testRoundtrip() { + $row = $this->generateRow(); + $object = PostRevision::fromStorageRow( $row ); + + // toStorageRow will add a bogus column 'rev_content_url' - that's ok. + // It'll be caught in code to distinguish between external content and + // content to be saved in rev_content, and, before inserting into DB, + // it'll be unset. We'll ignore this column here. + $roundtripRow = PostRevision::toStorageRow( $object ); + unset( $roundtripRow['rev_content_url'] ); + + $this->assertEquals( $roundtripRow, $row ); + } + + /** + * Creates a $this->revision object, for use in classes that extend this one. + */ + protected function setUp() { + parent::setUp(); + + $this->revision = $this->generateObject(); + } + + /** + * Returns an array, representing flow_revision & flow_tree_revision db + * columns. + * + * You can pass in arguments to override default data. + * With no arguments tossed in, default data (resembling a newly-created + * topic title) will be returned. + * + * @param array[optional] $row DB row data (only specify override columns) + * @return array + */ + protected function generateRow( array $row = array() ) { + $uuidPost = UUID::create(); + $uuidRevision = UUID::create(); + + $user = User::newFromName( 'UTSysop' ); + list( $userId, $userIp ) = PostRevision::userFields( $user ); + + return $row + array( + // flow_revision + 'rev_id' => $uuidRevision->getBinary(), + 'rev_type' => 'post', + 'rev_user_id' => $userId, + 'rev_user_ip' => $userIp, + 'rev_parent_id' => null, + 'rev_flags' => 'html', + 'rev_content' => 'test content', + 'rev_change_type' => 'new-post', + 'rev_mod_state' => null, + 'rev_mod_user_id' => null, + 'rev_mod_user_ip' => null, + 'rev_mod_timestamp' => null, + 'rev_mod_reason' => null, + 'rev_last_edit_id' => null, + 'rev_edit_user_id' => null, + 'rev_edit_user_ip' => null, + + // flow_tree_revision + 'tree_rev_descendant_id' => $uuidPost->getBinary(), + 'tree_rev_id' => $uuidRevision->getBinary(), + 'tree_orig_create_time' => wfTimestampNow(), + 'tree_orig_user_id' => $userId, + 'tree_orig_user_ip' => $userIp, + 'tree_parent_id' => null, + ); + } + + /** + * Returns a PostRevision object. + * + * You can pass in arguments to override default data. + * With no arguments tossed in, a default revision (resembling a newly- + * created topic title) will be returned. + * + * @param array[optional] $row DB row data (only specify override columns) + * @param array[optional] $children Array of child PostRevision objects + * @param int[optional] $depth Depth of the PostRevision object + * @return PostRevision + */ + protected function generateObject( array $row = array(), $children = array(), $depth = 0 ) { + $row = $this->generateRow( $row ); + + $revision = PostRevision::fromStorageRow( $row ); + $revision->setChildren( $children ); + $revision->setDepth( $depth ); + + return $revision; + } +} -- To view, visit https://gerrit.wikimedia.org/r/107560 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib058c67fdc844b3162d0f31ff2c0db587971c09f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits