Pppery (Code Review)
2017-12-31 04:32:24 UTC
Pppery has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401115 )
Change subject: Add unit test for creation of newsletters via API
......................................................................
Add unit test for creation of newsletters via API
Bug: T183817
Bug: T183818
Change-Id: If26b408efb9c443f5fe4edb14e1d30652b03c974
---
A tests/content/NewsletterAPIEditTest.php
1 file changed, 52 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/15/401115/1
diff --git a/tests/content/NewsletterAPIEditTest.php b/tests/content/NewsletterAPIEditTest.php
new file mode 100644
index 0000000..b8ad42a
--- /dev/null
+++ b/tests/content/NewsletterAPIEditTest.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @group API
+ * @group Database
+ * @group medium
+*/
+class NewsletterAPIEditTest extends ApiTestCase {
+ protected function setUp() {
+ parent::setUp();
+ $this->doLogin();
+ }
+ public function testCreation() {
+ $description = "A description that is at least 30 characters long";
+ $newsletterTitle = "Newsletter:Test";
+ $mainPage = "UTPage";
+ $text = "{
+ \"description\": \"$description\",
+ \"mainpage\": \"$mainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+
+ # Create the newsletter
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => $newsletterTitle,
+ 'text' => $text,
+ ]
+ );
+
+ $page = new WikiPage( Title::newFromText( $newsletterTitle ) );
+ $content = $page->getContent();
+ $newsletter = NewsletterStore::getDefaultInstance()->getNewsletterFromName( "Test" );
+ $this->assertNotNull( $newsletter );
+
+ # Check description
+ $this->assertEquals( $newsletter->getDescription(), $description );
+ $this->assertEquals( $content->getDescription(), $description );
+
+ # Check main page
+ $expectedPageId = Title::newFromText( $mainPage )->getArticleId();
+ $this->assertEquals( $newsletter->getPageId(), $expectedPageId );
+ $this->assertEquals( $content->getMainPage(), $mainPage );
+
+ # Check publishers and subsrcibers
+ $expectedUsers = [ User::newFromname( "UTSysop" )->getId() ];
+ $this->assertEquals( $newsletter->getPublishers(), $expectedUsers );
+ $this->assertEquals( $newsletter->getSubscribers(), $expectedUsers );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/401115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If26b408efb9c443f5fe4edb14e1d30652b03c974
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Pppery <***@olum.org>
Change subject: Add unit test for creation of newsletters via API
......................................................................
Add unit test for creation of newsletters via API
Bug: T183817
Bug: T183818
Change-Id: If26b408efb9c443f5fe4edb14e1d30652b03c974
---
A tests/content/NewsletterAPIEditTest.php
1 file changed, 52 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Newsletter refs/changes/15/401115/1
diff --git a/tests/content/NewsletterAPIEditTest.php b/tests/content/NewsletterAPIEditTest.php
new file mode 100644
index 0000000..b8ad42a
--- /dev/null
+++ b/tests/content/NewsletterAPIEditTest.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @group API
+ * @group Database
+ * @group medium
+*/
+class NewsletterAPIEditTest extends ApiTestCase {
+ protected function setUp() {
+ parent::setUp();
+ $this->doLogin();
+ }
+ public function testCreation() {
+ $description = "A description that is at least 30 characters long";
+ $newsletterTitle = "Newsletter:Test";
+ $mainPage = "UTPage";
+ $text = "{
+ \"description\": \"$description\",
+ \"mainpage\": \"$mainPage\",
+ \"publishers\": [
+ \"UTSysop\"
+ ]
+ }";
+
+ # Create the newsletter
+ $this->doApiRequestWithToken(
+ [
+ 'action' => 'edit',
+ 'title' => $newsletterTitle,
+ 'text' => $text,
+ ]
+ );
+
+ $page = new WikiPage( Title::newFromText( $newsletterTitle ) );
+ $content = $page->getContent();
+ $newsletter = NewsletterStore::getDefaultInstance()->getNewsletterFromName( "Test" );
+ $this->assertNotNull( $newsletter );
+
+ # Check description
+ $this->assertEquals( $newsletter->getDescription(), $description );
+ $this->assertEquals( $content->getDescription(), $description );
+
+ # Check main page
+ $expectedPageId = Title::newFromText( $mainPage )->getArticleId();
+ $this->assertEquals( $newsletter->getPageId(), $expectedPageId );
+ $this->assertEquals( $content->getMainPage(), $mainPage );
+
+ # Check publishers and subsrcibers
+ $expectedUsers = [ User::newFromname( "UTSysop" )->getId() ];
+ $this->assertEquals( $newsletter->getPublishers(), $expectedUsers );
+ $this->assertEquals( $newsletter->getSubscribers(), $expectedUsers );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/401115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If26b408efb9c443f5fe4edb14e1d30652b03c974
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Pppery <***@olum.org>