MediaWiki  1.27.2
WatchedItemIntegrationTest.php
Go to the documentation of this file.
1 <?php
2 
11 
12  public function setUp() {
13  parent::setUp();
14  self::$users['WatchedItemIntegrationTestUser']
15  = new TestUser( 'WatchedItemIntegrationTestUser' );
16  }
17 
18  private function getUser() {
19  return self::$users['WatchedItemIntegrationTestUser']->getUser();
20  }
21 
22  public function testWatchAndUnWatchItem() {
23  $user = $this->getUser();
24  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
25  // Cleanup after previous tests
26  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
27 
28  $this->assertFalse(
29  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
30  'Page should not initially be watched'
31  );
32  WatchedItem::fromUserTitle( $user, $title )->addWatch();
33  $this->assertTrue(
34  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
35  'Page should be watched'
36  );
37  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
38  $this->assertFalse(
39  WatchedItem::fromUserTitle( $user, $title )->isWatched(),
40  'Page should be unwatched'
41  );
42  }
43 
45  $user = $this->getUser();
46  $otherUser = ( new TestUser( 'WatchedItemIntegrationTestUser_otherUser' ) )->getUser();
47  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
48  WatchedItem::fromUserTitle( $user, $title )->addWatch();
49  $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
50 
51  EmailNotification::updateWatchlistTimestamp( $otherUser, $title, '20150202010101' );
52  $this->assertEquals(
53  '20150202010101',
54  WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
55  );
56 
57  WatchedItem::fromUserTitle( $user, $title )->resetNotificationTimestamp();
58  $this->assertNull( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
59  }
60 
62  $user = $this->getUser();
63  $titleOld = Title::newFromText( 'WatchedItemIntegrationTestPageOld' );
64  $titleNew = Title::newFromText( 'WatchedItemIntegrationTestPageNew' );
65  WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->addWatch();
66  WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->addWatch();
67  // Cleanup after previous tests
68  WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->removeWatch();
69  WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->removeWatch();
70 
71  WatchedItem::duplicateEntries( $titleOld, $titleNew );
72 
73  $this->assertTrue(
74  WatchedItem::fromUserTitle( $user, $titleOld->getSubjectPage() )->isWatched()
75  );
76  $this->assertTrue(
77  WatchedItem::fromUserTitle( $user, $titleOld->getTalkPage() )->isWatched()
78  );
79  $this->assertTrue(
80  WatchedItem::fromUserTitle( $user, $titleNew->getSubjectPage() )->isWatched()
81  );
82  $this->assertTrue(
83  WatchedItem::fromUserTitle( $user, $titleNew->getTalkPage() )->isWatched()
84  );
85  }
86 
87  public function testIsWatched_falseOnNotAllowed() {
88  $user = $this->getUser();
89  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
90  WatchedItem::fromUserTitle( $user, $title )->addWatch();
91 
92  $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
93  $user->mRights = [];
94  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
95  }
96 
98  $user = $this->getUser();
99  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
100  WatchedItem::fromUserTitle( $user, $title )->addWatch();
101  WatchedItem::fromUserTitle( $user, $title )->resetNotificationTimestamp();
102 
103  $this->assertEquals(
104  null,
105  WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp()
106  );
107  $user->mRights = [];
108  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
109  }
110 
112  $user = $this->getUser();
113  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
114  WatchedItem::fromUserTitle( $user, $title )->addWatch();
115 
116  $previousRights = $user->mRights;
117  $user->mRights = [];
118  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->removeWatch() );
119  $user->mRights = $previousRights;
120  $this->assertTrue( WatchedItem::fromUserTitle( $user, $title )->removeWatch() );
121  }
122 
124  $user = $this->getUser();
125  $title = Title::newFromText( 'WatchedItemIntegrationTestPage' );
126 
127  WatchedItem::fromUserTitle( $user, $title )->removeWatch();
128  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->isWatched() );
129 
130  $this->assertFalse( WatchedItem::fromUserTitle( $user, $title )->getNotificationTimestamp() );
131  }
132 
133 }
static updateWatchlistTimestamp(User $editor, LinkTarget $linkTarget, $timestamp)
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
static duplicateEntries(Title $oldTitle, Title $newTitle)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:7
static fromUserTitle($user, $title, $checkRights=User::CHECK_USER_RIGHTS)