Discussion:
[MediaWiki-commits] [Gerrit] mediawiki...Newsletter[master]: Add unit test for adding publishers via API
Pppery (Code Review)
2017-12-31 18:38:31 UTC
Permalink
Pppery has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401189 )

Change subject: Add unit test for adding publishers via API
......................................................................

Add unit test for adding publishers via API

Bug: T183817
Bug: T182820
Change-Id: I1f64494936bfdfb8c46b334f8b38141566bcabca
---
M tests/content/NewsletterAPIEditTest.php
1 file changed, 38 insertions(+), 1 deletion(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/89/401189/1

diff --git a/tests/content/NewsletterAPIEditTest.php b/tests/content/NewsletterAPIEditTest.php
index c7ef3c8..e81f67a 100644
--- a/tests/content/NewsletterAPIEditTest.php
+++ b/tests/content/NewsletterAPIEditTest.php
@@ -10,6 +10,7 @@
protected function setUp() {
parent::setUp();
$this->doLogin();
+ $this->tablesUsed = [ 'nl_newsletters', 'nl_publishers', 'nl_subscriptions' ];
}
public function testCreation() {
$description = "A description that is at least 30 characters long";
@@ -100,7 +101,6 @@
\"description\": \"$description\",
\"mainpage\": \"$newMainPage\",
\"publishers\": [
- \"UTSysop\"
]
}";
$this->doApiRequestWithToken(
@@ -115,4 +115,41 @@
$newsletter = Newsletter::newFromName( "Test" );
$this->assertEquals( $newsletter->getPageId(), $newMainPageId );
}
+ public function testAddPublisher() {
+ # Set up by creating newsletter
+ $description = "A description that is at least 30 characters long";
+ $mainPage = 'UTPage';
+ $mainPageId = Title::newFromText( $mainPage )->getArticleId();
+ $newsletter = new Newsletter( 0, 'Test', $description, $mainPageId );
+ NewsletterStore::getDefaultInstance()->addNewsletter( $newsletter );
+
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertNotNull( $newsletter );
+
+ # Newsletter should initially have no publishers and no subscribers
+ $this->assertEquals( $newsletter->getPublishers(), [] );
+ $this->assertEquals( $newsletter->getSubscribers(), [] );
+
+ # Modify the publishers
+ $newText = "{
+ \"description\": \"$description\",
+ \"mainpage\": \"$mainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => "Newsletter:Test",
+ 'text' => $newText,
+ ]
+ );
+
+ # Check that user was correctly added
+ $expectedUsers = [ User::newFromname( "UTSysop" )->getId() ];
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertEquals( $newsletter->getPublishers(), $expectedUsers );
+ $this->assertEquals( $newsletter->getSubscribers(), $expectedUsers );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/401189
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f64494936bfdfb8c46b334f8b38141566bcabca
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Pppery <***@olum.org>
Loading...