From: addshore Date: Mon, 4 Dec 2017 16:09:54 +0000 (+0100) Subject: Tests for WikiPage::insertOn X-Git-Tag: 1.31.0-rc.0~1279 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/Bar?a=commitdiff_plain;h=7a46b709aa5310499c48b4374a53c0b20e4a5bd9;p=lhc%2Fweb%2Fwiklou.git Tests for WikiPage::insertOn Change-Id: I1bf7d19c4baaf0f720fcd6a1d9c16bf7489b5392 --- diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index 1a4b82043d..c4ec4dd5c1 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -1612,4 +1612,87 @@ more stuff $this->assertTrue( $result ); } + /** + * @covers WikiPage::insertOn + */ + public function testInsertOn() { + $title = Title::newFromText( __METHOD__ ); + $page = new WikiPage( $title ); + + $startTimeStamp = wfTimestampNow(); + $result = $page->insertOn( $this->db ); + $endTimeStamp = wfTimestampNow(); + + $this->assertInternalType( 'int', $result ); + $this->assertTrue( $result > 0 ); + + $condition = [ 'page_id' => $result ]; + + // Check the default fields have been filled + $this->assertSelect( + 'page', + [ + 'page_namespace', + 'page_title', + 'page_restrictions', + 'page_is_redirect', + 'page_is_new', + 'page_latest', + 'page_len', + ], + $condition, + [ [ + '0', + __METHOD__, + '', + '0', + '1', + '0', + '0', + ] ] + ); + + // Check the page_random field has been filled + $pageRandom = $this->db->selectField( 'page', 'page_random', $condition ); + $this->assertTrue( (float)$pageRandom < 1 && (float)$pageRandom > 0 ); + + // Assert the touched timestamp in the DB is roughly when we inserted the page + $pageTouched = $this->db->selectField( 'page', 'page_touched', $condition ); + $this->assertTrue( + wfTimestamp( TS_UNIX, $startTimeStamp ) + <= wfTimestamp( TS_UNIX, $pageTouched ) + ); + $this->assertTrue( + wfTimestamp( TS_UNIX, $endTimeStamp ) + >= wfTimestamp( TS_UNIX, $pageTouched ) + ); + + // Try inserting the same page again and checking the result is false (no change) + $result = $page->insertOn( $this->db ); + $this->assertFalse( $result ); + } + + /** + * @covers WikiPage::insertOn + */ + public function testInsertOn_idSpecified() { + $title = Title::newFromText( __METHOD__ ); + $page = new WikiPage( $title ); + $id = 3478952189; + + $result = $page->insertOn( $this->db, $id ); + + $this->assertSame( $id, $result ); + + $condition = [ 'page_id' => $result ]; + + // Check there is actually a row in the db + $this->assertSelect( + 'page', + [ 'page_title' ], + $condition, + [ [ __METHOD__ ] ] + ); + } + }