Pppery (Code Review)
2017-12-31 15:31:56 UTC
Pppery has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401185 )
Change subject: Add unit tests for changing description and main page of newsletters via API
......................................................................
Add unit tests for changing description and main page of newsletters via API
Bug: T183817
Bug: T183819
Change-Id: I82dc3347b9ba1f7cc7787f85735b6237092f42cc
---
M tests/content/NewsletterAPIEditTest.php
1 file changed, 59 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/85/401185/1
diff --git a/tests/content/NewsletterAPIEditTest.php b/tests/content/NewsletterAPIEditTest.php
index bf5b414..0588b5c 100644
--- a/tests/content/NewsletterAPIEditTest.php
+++ b/tests/content/NewsletterAPIEditTest.php
@@ -51,4 +51,63 @@
$this->assertEquals( $newsletter->getPublishers(), $expectedUsers );
$this->assertEquals( $newsletter->getSubscribers(), $expectedUsers );
}
+
+ public function testUpdateDescription() {
+ # Set up by creating first newsletter
+ $initialDescription = "A description that is at least 30 characters long";
+ $finalDescription = "A description that is still at least 30 characters long";
+ $mainPage = 'UTPage';
+ $mainPageId = Title::newFromText( $mainPage )->getArticleId();
+ $newsletter = new Newsletter( 0, 'Test', $initialDescription, $mainPageId );
+ NewsletterStore::getDefaultInstance()->addNewsletter( $newsletter );
+
+ # Modify the description
+ $newText = "{
+ \"description\": \"$finalDescription\",
+ \"mainpage\": \"$mainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => "Newsletter:Test",
+ 'text' => $newText,
+ ]
+ );
+
+ # Check the description
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertEquals( $newsletter->getDescription(), $finalDescription );
+ }
+
+ public function testUpdateMainPage() {
+ # Set up by creating first newsletter
+ $description = "A description that is at least 30 characters long";
+ $newMainPage = 'UTPage';
+ $newsletter = new Newsletter( 0, 'Test', $description, 0 );
+ NewsletterStore::getDefaultInstance()->addNewsletter( $newsletter );
+
+ # Modify the main page
+ $newText = "{
+ \"description\": \"$description\",
+ \"mainpage\": \"$newMainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => "Newsletter:Test",
+ 'text' => $newText,
+ ]
+ );
+
+ # Check the main page
+ $expectedPageId = Title::newFromText( $newMainPage )->getArticleId();
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertEquals( $newsletter->getPageId(), $expectedPageId );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/401185
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82dc3347b9ba1f7cc7787f85735b6237092f42cc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Pppery <***@olum.org>
Change subject: Add unit tests for changing description and main page of newsletters via API
......................................................................
Add unit tests for changing description and main page of newsletters via API
Bug: T183817
Bug: T183819
Change-Id: I82dc3347b9ba1f7cc7787f85735b6237092f42cc
---
M tests/content/NewsletterAPIEditTest.php
1 file changed, 59 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/85/401185/1
diff --git a/tests/content/NewsletterAPIEditTest.php b/tests/content/NewsletterAPIEditTest.php
index bf5b414..0588b5c 100644
--- a/tests/content/NewsletterAPIEditTest.php
+++ b/tests/content/NewsletterAPIEditTest.php
@@ -51,4 +51,63 @@
$this->assertEquals( $newsletter->getPublishers(), $expectedUsers );
$this->assertEquals( $newsletter->getSubscribers(), $expectedUsers );
}
+
+ public function testUpdateDescription() {
+ # Set up by creating first newsletter
+ $initialDescription = "A description that is at least 30 characters long";
+ $finalDescription = "A description that is still at least 30 characters long";
+ $mainPage = 'UTPage';
+ $mainPageId = Title::newFromText( $mainPage )->getArticleId();
+ $newsletter = new Newsletter( 0, 'Test', $initialDescription, $mainPageId );
+ NewsletterStore::getDefaultInstance()->addNewsletter( $newsletter );
+
+ # Modify the description
+ $newText = "{
+ \"description\": \"$finalDescription\",
+ \"mainpage\": \"$mainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => "Newsletter:Test",
+ 'text' => $newText,
+ ]
+ );
+
+ # Check the description
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertEquals( $newsletter->getDescription(), $finalDescription );
+ }
+
+ public function testUpdateMainPage() {
+ # Set up by creating first newsletter
+ $description = "A description that is at least 30 characters long";
+ $newMainPage = 'UTPage';
+ $newsletter = new Newsletter( 0, 'Test', $description, 0 );
+ NewsletterStore::getDefaultInstance()->addNewsletter( $newsletter );
+
+ # Modify the main page
+ $newText = "{
+ \"description\": \"$description\",
+ \"mainpage\": \"$newMainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => "Newsletter:Test",
+ 'text' => $newText,
+ ]
+ );
+
+ # Check the main page
+ $expectedPageId = Title::newFromText( $newMainPage )->getArticleId();
+ $newsletter = Newsletter::newFromName( "Test" );
+ $this->assertEquals( $newsletter->getPageId(), $expectedPageId );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/401185
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I82dc3347b9ba1f7cc7787f85735b6237092f42cc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Pppery <***@olum.org>