[MediaWiki-commits] [Gerrit] Add fromStorageRow - toStorageRow roundtrip test - change (mediawiki...Flow)
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 000..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 000..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' =
[MediaWiki-commits] [Gerrit] Add fromStorageRow - toStorageRow roundtrip test - change (mediawiki...Flow)
jenkins-bot has submitted this change and it was merged. 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, 122 insertions(+), 0 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified 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 000..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 000..2c36a3d --- /dev/null +++ b/tests/PostRevisionTestCase.php @@ -0,0 +1,94 @@ +?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; + + /** +* 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(), +