# sanity check, because this test seems to fail for no reason for some people.
$c = $page->getContent();
- $this->assertEquals( 'WikitextContent', get_class( $c ) );
+ $this->assertEquals( WikitextContent::class, get_class( $c ) );
# now, test the actual redirect
$t = $page->getRedirectTarget();
public function testWikiPageFactory() {
$title = Title::makeTitle( NS_FILE, 'Someimage.png' );
$page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiFilePage', get_class( $page ) );
+ $this->assertEquals( WikiFilePage::class, get_class( $page ) );
$title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' );
$page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiCategoryPage', get_class( $page ) );
+ $this->assertEquals( WikiCategoryPage::class, get_class( $page ) );
$title = Title::makeTitle( NS_MAIN, 'SomePage' );
$page = WikiPage::factory( $title );
- $this->assertEquals( 'WikiPage', get_class( $page ) );
+ $this->assertEquals( WikiPage::class, get_class( $page ) );
}
/**
* Most of core checks the page table for redirect status, so we have to be ugly and
* assert a select from the table here.
*/
+ $this->assertRedirectTableCountForPageId( $page->getId(), $expectedRowCount );
+ }
+
+ private function assertRedirectTableCountForPageId( $pageId, $expected ) {
$this->assertSelect(
'redirect',
'COUNT(*)',
+ [ 'rd_from' => $pageId ],
+ [ [ strval( $expected ) ] ]
+ );
+ }
+
+ /**
+ * @covers WikiPage::insertRedirectEntry
+ */
+ public function testInsertRedirectEntry_insertsRedirectEntry() {
+ $page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
+ $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
+
+ $targetTitle = Title::newFromText( 'SomeTarget#Frag' );
+ $targetTitle->mInterwiki = 'eninter';
+ $page->insertRedirectEntry( $targetTitle, null );
+
+ $this->assertSelect(
+ 'redirect',
+ [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
+ [ 'rd_from' => $page->getId() ],
+ [ [
+ strval( $page->getId() ),
+ strval( $targetTitle->getNamespace() ),
+ strval( $targetTitle->getDBkey() ),
+ strval( $targetTitle->getFragment() ),
+ strval( $targetTitle->getInterwiki() ),
+ ] ]
+ );
+ }
+
+ /**
+ * @covers WikiPage::insertRedirectEntry
+ */
+ public function testInsertRedirectEntry_insertsRedirectEntryWithPageLatest() {
+ $page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
+ $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
+
+ $targetTitle = Title::newFromText( 'SomeTarget#Frag' );
+ $targetTitle->mInterwiki = 'eninter';
+ $page->insertRedirectEntry( $targetTitle, $page->getLatest() );
+
+ $this->assertSelect(
+ 'redirect',
+ [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
[ 'rd_from' => $page->getId() ],
- [ [ strval( $expectedRowCount ) ] ]
+ [ [
+ strval( $page->getId() ),
+ strval( $targetTitle->getNamespace() ),
+ strval( $targetTitle->getDBkey() ),
+ strval( $targetTitle->getFragment() ),
+ strval( $targetTitle->getInterwiki() ),
+ ] ]
+ );
+ }
+
+ /**
+ * @covers WikiPage::insertRedirectEntry
+ */
+ public function testInsertRedirectEntry_doesNotInsertIfPageLatestIncorrect() {
+ $page = $this->createPage( Title::newFromText( __METHOD__ ), 'A' );
+ $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
+
+ $targetTitle = Title::newFromText( 'SomeTarget#Frag' );
+ $targetTitle->mInterwiki = 'eninter';
+ $page->insertRedirectEntry( $targetTitle, 215251 );
+
+ $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
+ }
+
+ private function getRow( array $overrides = [] ) {
+ $row = [
+ 'page_id' => '44',
+ 'page_len' => '76',
+ 'page_is_redirect' => '1',
+ 'page_latest' => '99',
+ 'page_namespace' => '3',
+ 'page_title' => 'JaJaTitle',
+ 'page_restrictions' => 'edit=autoconfirmed,sysop:move=sysop',
+ 'page_touched' => '20120101020202',
+ 'page_links_updated' => '20140101020202',
+ ];
+ foreach ( $overrides as $key => $value ) {
+ $row[$key] = $value;
+ }
+ return (object)$row;
+ }
+
+ public function provideNewFromRowSuccess() {
+ yield 'basic row' => [
+ $this->getRow(),
+ function ( WikiPage $wikiPage, self $test ) {
+ $test->assertSame( 44, $wikiPage->getId() );
+ $test->assertSame( 76, $wikiPage->getTitle()->getLength() );
+ $test->assertTrue( $wikiPage->isRedirect() );
+ $test->assertSame( 99, $wikiPage->getLatest() );
+ $test->assertSame( 3, $wikiPage->getTitle()->getNamespace() );
+ $test->assertSame( 'JaJaTitle', $wikiPage->getTitle()->getDBkey() );
+ $test->assertSame(
+ [
+ 'edit' => [ 'autoconfirmed', 'sysop' ],
+ 'move' => [ 'sysop' ],
+ ],
+ $wikiPage->getTitle()->getAllRestrictions()
+ );
+ $test->assertSame( '20120101020202', $wikiPage->getTouched() );
+ $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
+ }
+ ];
+ yield 'different timestamp formats' => [
+ $this->getRow( [
+ 'page_touched' => '2012-01-01 02:02:02',
+ 'page_links_updated' => '2014-01-01 02:02:02',
+ ] ),
+ function ( WikiPage $wikiPage, self $test ) {
+ $test->assertSame( '20120101020202', $wikiPage->getTouched() );
+ $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
+ }
+ ];
+ yield 'no restrictions' => [
+ $this->getRow( [
+ 'page_restrictions' => '',
+ ] ),
+ function ( WikiPage $wikiPage, self $test ) {
+ $test->assertSame(
+ [
+ 'edit' => [],
+ 'move' => [],
+ ],
+ $wikiPage->getTitle()->getAllRestrictions()
+ );
+ }
+ ];
+ yield 'not redirect' => [
+ $this->getRow( [
+ 'page_is_redirect' => '0',
+ ] ),
+ function ( WikiPage $wikiPage, self $test ) {
+ $test->assertFalse( $wikiPage->isRedirect() );
+ }
+ ];
+ }
+
+ /**
+ * @covers WikiPage::newFromRow
+ * @covers WikiPage::loadFromRow
+ * @dataProvider provideNewFromRowSuccess
+ *
+ * @param object $row
+ * @param callable $assertions
+ */
+ public function testNewFromRow( $row, $assertions ) {
+ $page = WikiPage::newFromRow( $row, 'fromdb' );
+ $assertions( $page, $this );
+ }
+
+ public function provideTestNewFromId_returnsNullOnBadPageId() {
+ yield[ 0 ];
+ yield[ -11 ];
+ }
+
+ /**
+ * @covers WikiPage::newFromID
+ * @dataProvider provideTestNewFromId_returnsNullOnBadPageId
+ */
+ public function testNewFromId_returnsNullOnBadPageId( $pageId ) {
+ $this->assertNull( WikiPage::newFromID( $pageId ) );
+ }
+
+ /**
+ * @covers WikiPage::newFromID
+ */
+ public function testNewFromId_appearsToFetchCorrectRow() {
+ $createdPage = $this->createPage( __METHOD__, 'Xsfaij09' );
+ $fetchedPage = WikiPage::newFromID( $createdPage->getId() );
+ $this->assertSame( $createdPage->getId(), $fetchedPage->getId() );
+ $this->assertEquals(
+ $createdPage->getContent()->getNativeData(),
+ $fetchedPage->getContent()->getNativeData()
+ );
+ }
+
+ /**
+ * @covers WikiPage::newFromID
+ */
+ public function testNewFromId_returnsNullOnNonExistingId() {
+ $this->assertNull( WikiPage::newFromID( 73574757437437743743 ) );
+ }
+
+ public function provideTestInsertProtectNullRevision() {
+ // phpcs:disable Generic.Files.LineLength
+ yield [
+ 'goat-message-key',
+ [ 'edit' => 'sysop' ],
+ [ 'edit' => '20200101040404' ],
+ false,
+ 'Goat Reason',
+ true,
+ '(goat-message-key: WikiPageDbTestBase::testInsertProtectNullRevision, UTSysop)(colon-separator)Goat Reason(word-separator)(parentheses: (protect-summary-desc: (restriction-edit), (protect-level-sysop), (protect-expiring: 04:04, 1 (january) 2020, 1 (january) 2020, 04:04)))'
+ ];
+ yield [
+ 'goat-key',
+ [ 'edit' => 'sysop', 'move' => 'something' ],
+ [ 'edit' => '20200101040404', 'move' => '20210101050505' ],
+ false,
+ 'Goat Goat',
+ true,
+ '(goat-key: WikiPageDbTestBase::testInsertProtectNullRevision, UTSysop)(colon-separator)Goat Goat(word-separator)(parentheses: (protect-summary-desc: (restriction-edit), (protect-level-sysop), (protect-expiring: 04:04, 1 (january) 2020, 1 (january) 2020, 04:04))(word-separator)(protect-summary-desc: (restriction-move), (protect-level-something), (protect-expiring: 05:05, 1 (january) 2021, 1 (january) 2021, 05:05)))'
+ ];
+ // phpcs:enable
+ }
+
+ /**
+ * @dataProvider provideTestInsertProtectNullRevision
+ * @covers WikiPage::insertProtectNullRevision
+ * @covers WikiPage::protectDescription
+ *
+ * @param string $revCommentMsg
+ * @param array $limit
+ * @param array $expiry
+ * @param bool $cascade
+ * @param string $reason
+ * @param bool|null $user true if the test sysop should be used, or null
+ * @param string $expectedComment
+ */
+ public function testInsertProtectNullRevision(
+ $revCommentMsg,
+ array $limit,
+ array $expiry,
+ $cascade,
+ $reason,
+ $user,
+ $expectedComment
+ ) {
+ $this->setContentLang( 'qqx' );
+
+ $page = $this->createPage( __METHOD__, 'Goat' );
+
+ $user = $user === null ? $user : $this->getTestSysop()->getUser();
+
+ $result = $page->insertProtectNullRevision(
+ $revCommentMsg,
+ $limit,
+ $expiry,
+ $cascade,
+ $reason,
+ $user
+ );
+
+ $this->assertTrue( $result instanceof Revision );
+ $this->assertSame( $expectedComment, $result->getComment( Revision::RAW ) );
+ }
+
+ /**
+ * @covers WikiPage::updateRevisionOn
+ */
+ public function testUpdateRevisionOn_existingPage() {
+ $user = $this->getTestSysop()->getUser();
+ $page = $this->createPage( __METHOD__, 'StartText' );
+
+ $revision = new Revision(
+ [
+ 'id' => 9989,
+ 'page' => $page->getId(),
+ 'title' => $page->getTitle(),
+ 'comment' => __METHOD__,
+ 'minor_edit' => true,
+ 'text' => __METHOD__ . '-text',
+ 'len' => strlen( __METHOD__ . '-text' ),
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => '20170707040404',
+ 'content_model' => CONTENT_MODEL_WIKITEXT,
+ 'content_format' => CONTENT_FORMAT_WIKITEXT,
+ ]
+ );
+
+ $result = $page->updateRevisionOn( $this->db, $revision );
+ $this->assertTrue( $result );
+ $this->assertSame( 9989, $page->getLatest() );
+ $this->assertEquals( $revision, $page->getRevision() );
+ }
+
+ /**
+ * @covers WikiPage::updateRevisionOn
+ */
+ public function testUpdateRevisionOn_NonExistingPage() {
+ $user = $this->getTestSysop()->getUser();
+ $page = $this->createPage( __METHOD__, 'StartText' );
+ $page->doDeleteArticle( 'reason' );
+
+ $revision = new Revision(
+ [
+ 'id' => 9989,
+ 'page' => $page->getId(),
+ 'title' => $page->getTitle(),
+ 'comment' => __METHOD__,
+ 'minor_edit' => true,
+ 'text' => __METHOD__ . '-text',
+ 'len' => strlen( __METHOD__ . '-text' ),
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => '20170707040404',
+ 'content_model' => CONTENT_MODEL_WIKITEXT,
+ 'content_format' => CONTENT_FORMAT_WIKITEXT,
+ ]
+ );
+
+ $result = $page->updateRevisionOn( $this->db, $revision );
+ $this->assertFalse( $result );
+ }
+
+ /**
+ * @covers WikiPage::updateIfNewerOn
+ */
+ public function testUpdateIfNewerOn_olderRevision() {
+ $user = $this->getTestSysop()->getUser();
+ $page = $this->createPage( __METHOD__, 'StartText' );
+ $initialRevision = $page->getRevision();
+
+ $olderTimeStamp = wfTimestamp(
+ TS_MW,
+ wfTimestamp( TS_UNIX, $initialRevision->getTimestamp() ) - 1
+ );
+
+ $olderRevison = new Revision(
+ [
+ 'id' => 9989,
+ 'page' => $page->getId(),
+ 'title' => $page->getTitle(),
+ 'comment' => __METHOD__,
+ 'minor_edit' => true,
+ 'text' => __METHOD__ . '-text',
+ 'len' => strlen( __METHOD__ . '-text' ),
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => $olderTimeStamp,
+ 'content_model' => CONTENT_MODEL_WIKITEXT,
+ 'content_format' => CONTENT_FORMAT_WIKITEXT,
+ ]
+ );
+
+ $result = $page->updateIfNewerOn( $this->db, $olderRevison );
+ $this->assertFalse( $result );
+ }
+
+ /**
+ * @covers WikiPage::updateIfNewerOn
+ */
+ public function testUpdateIfNewerOn_newerRevision() {
+ $user = $this->getTestSysop()->getUser();
+ $page = $this->createPage( __METHOD__, 'StartText' );
+ $initialRevision = $page->getRevision();
+
+ $newerTimeStamp = wfTimestamp(
+ TS_MW,
+ wfTimestamp( TS_UNIX, $initialRevision->getTimestamp() ) + 1
+ );
+
+ $newerRevision = new Revision(
+ [
+ 'id' => 9989,
+ 'page' => $page->getId(),
+ 'title' => $page->getTitle(),
+ 'comment' => __METHOD__,
+ 'minor_edit' => true,
+ 'text' => __METHOD__ . '-text',
+ 'len' => strlen( __METHOD__ . '-text' ),
+ 'user' => $user->getId(),
+ 'user_text' => $user->getName(),
+ 'timestamp' => $newerTimeStamp,
+ 'content_model' => CONTENT_MODEL_WIKITEXT,
+ 'content_format' => CONTENT_FORMAT_WIKITEXT,
+ ]
+ );
+ $result = $page->updateIfNewerOn( $this->db, $newerRevision );
+ $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 = 1478952189;
+
+ $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__ ] ]
+ );
+ }
+
+ public function provideTestDoUpdateRestrictions_setBasicRestrictions() {
+ // Note: Once the current dates passes the date in these tests they will fail.
+ yield 'move something' => [
+ true,
+ [ 'move' => 'something' ],
+ [],
+ [ 'edit' => [], 'move' => [ 'something' ] ],
+ [],
+ ];
+ yield 'move something, edit blank' => [
+ true,
+ [ 'move' => 'something', 'edit' => '' ],
+ [],
+ [ 'edit' => [], 'move' => [ 'something' ] ],
+ [],
+ ];
+ yield 'edit sysop, with expiry' => [
+ true,
+ [ 'edit' => 'sysop' ],
+ [ 'edit' => '21330101020202' ],
+ [ 'edit' => [ 'sysop' ], 'move' => [] ],
+ [ 'edit' => '21330101020202' ],
+ ];
+ yield 'move and edit, move with expiry' => [
+ true,
+ [ 'move' => 'something', 'edit' => 'another' ],
+ [ 'move' => '22220202010101' ],
+ [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
+ [ 'move' => '22220202010101' ],
+ ];
+ yield 'move and edit, edit with infinity expiry' => [
+ true,
+ [ 'move' => 'something', 'edit' => 'another' ],
+ [ 'edit' => 'infinity' ],
+ [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
+ [ 'edit' => 'infinity' ],
+ ];
+ yield 'non existing, create something' => [
+ false,
+ [ 'create' => 'something' ],
+ [],
+ [ 'create' => [ 'something' ] ],
+ [],
+ ];
+ yield 'non existing, create something with expiry' => [
+ false,
+ [ 'create' => 'something' ],
+ [ 'create' => '23451212112233' ],
+ [ 'create' => [ 'something' ] ],
+ [ 'create' => '23451212112233' ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideTestDoUpdateRestrictions_setBasicRestrictions
+ * @covers WikiPage::doUpdateRestrictions
+ */
+ public function testDoUpdateRestrictions_setBasicRestrictions(
+ $pageExists,
+ array $limit,
+ array $expiry,
+ array $expectedRestrictions,
+ array $expectedRestrictionExpiries
+ ) {
+ if ( $pageExists ) {
+ $page = $this->createPage( __METHOD__, 'ABC' );
+ } else {
+ $page = new WikiPage( Title::newFromText( __METHOD__ . '-nonexist' ) );
+ }
+ $user = $this->getTestSysop()->getUser();
+ $cascade = false;
+
+ $status = $page->doUpdateRestrictions( $limit, $expiry, $cascade, 'aReason', $user, [] );
+
+ $logId = $status->getValue();
+ $allRestrictions = $page->getTitle()->getAllRestrictions();
+
+ $this->assertTrue( $status->isGood() );
+ $this->assertInternalType( 'int', $logId );
+ $this->assertSame( $expectedRestrictions, $allRestrictions );
+ foreach ( $expectedRestrictionExpiries as $key => $value ) {
+ $this->assertSame( $value, $page->getTitle()->getRestrictionExpiry( $key ) );
+ }
+
+ // Make sure the log entry looks good
+ // log_params is not checked here
+ $this->assertSelect(
+ 'logging',
+ [
+ 'log_comment',
+ 'log_user',
+ 'log_user_text',
+ 'log_namespace',
+ 'log_title',
+ ],
+ [ 'log_id' => $logId ],
+ [ [
+ 'aReason',
+ (string)$user->getId(),
+ $user->getName(),
+ (string)$page->getTitle()->getNamespace(),
+ $page->getTitle()->getDBkey(),
+ ] ]
+ );
+ }
+
+ /**
+ * @covers WikiPage::doUpdateRestrictions
+ */
+ public function testDoUpdateRestrictions_failsOnReadOnly() {
+ $page = $this->createPage( __METHOD__, 'ABC' );
+ $user = $this->getTestSysop()->getUser();
+ $cascade = false;
+
+ // Set read only
+ $readOnly = $this->getMockBuilder( ReadOnlyMode::class )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'isReadOnly', 'getReason' ] )
+ ->getMock();
+ $readOnly->expects( $this->once() )
+ ->method( 'isReadOnly' )
+ ->will( $this->returnValue( true ) );
+ $readOnly->expects( $this->once() )
+ ->method( 'getReason' )
+ ->will( $this->returnValue( 'Some Read Only Reason' ) );
+ $this->setService( 'ReadOnlyMode', $readOnly );
+
+ $status = $page->doUpdateRestrictions( [], [], $cascade, 'aReason', $user, [] );
+ $this->assertFalse( $status->isOK() );
+ $this->assertSame( 'readonlytext', $status->getMessage()->getKey() );
+ }
+
+ /**
+ * @covers WikiPage::doUpdateRestrictions
+ */
+ public function testDoUpdateRestrictions_returnsGoodIfNothingChanged() {
+ $page = $this->createPage( __METHOD__, 'ABC' );
+ $user = $this->getTestSysop()->getUser();
+ $cascade = false;
+ $limit = [ 'edit' => 'sysop' ];
+
+ $status = $page->doUpdateRestrictions(
+ $limit,
+ [],
+ $cascade,
+ 'aReason',
+ $user,
+ []
+ );
+
+ // The first entry should have a logId as it did something
+ $this->assertTrue( $status->isGood() );
+ $this->assertInternalType( 'int', $status->getValue() );
+
+ $status = $page->doUpdateRestrictions(
+ $limit,
+ [],
+ $cascade,
+ 'aReason',
+ $user,
+ []
+ );
+
+ // The second entry should not have a logId as nothing changed
+ $this->assertTrue( $status->isGood() );
+ $this->assertNull( $status->getValue() );
+ }
+
+ /**
+ * @covers WikiPage::doUpdateRestrictions
+ */
+ public function testDoUpdateRestrictions_logEntryTypeAndAction() {
+ $page = $this->createPage( __METHOD__, 'ABC' );
+ $user = $this->getTestSysop()->getUser();
+ $cascade = false;
+
+ // Protect the page
+ $status = $page->doUpdateRestrictions(
+ [ 'edit' => 'sysop' ],
+ [],
+ $cascade,
+ 'aReason',
+ $user,
+ []
+ );
+ $this->assertTrue( $status->isGood() );
+ $this->assertInternalType( 'int', $status->getValue() );
+ $this->assertSelect(
+ 'logging',
+ [ 'log_type', 'log_action' ],
+ [ 'log_id' => $status->getValue() ],
+ [ [ 'protect', 'protect' ] ]
+ );
+
+ // Modify the protection
+ $status = $page->doUpdateRestrictions(
+ [ 'edit' => 'somethingElse' ],
+ [],
+ $cascade,
+ 'aReason',
+ $user,
+ []
+ );
+ $this->assertTrue( $status->isGood() );
+ $this->assertInternalType( 'int', $status->getValue() );
+ $this->assertSelect(
+ 'logging',
+ [ 'log_type', 'log_action' ],
+ [ 'log_id' => $status->getValue() ],
+ [ [ 'protect', 'modify' ] ]
+ );
+
+ // Remove the protection
+ $status = $page->doUpdateRestrictions(
+ [],
+ [],
+ $cascade,
+ 'aReason',
+ $user,
+ []
+ );
+ $this->assertTrue( $status->isGood() );
+ $this->assertInternalType( 'int', $status->getValue() );
+ $this->assertSelect(
+ 'logging',
+ [ 'log_type', 'log_action' ],
+ [ 'log_id' => $status->getValue() ],
+ [ [ 'protect', 'unprotect' ] ]
);
}