Add PHPUnit tests for methods in ViewAction::class
authorAlangi Derick <alangiderick@gmail.com>
Tue, 20 Nov 2018 16:35:47 +0000 (17:35 +0100)
committerAlangi Derick <alangiderick@gmail.com>
Tue, 20 Nov 2018 17:13:50 +0000 (18:13 +0100)
* makeViewActionClassFactory() - helper function to create an
  instance of the ViewAction class and return it.
* testGetName() - covers the getName() method in ViewAction class.
* testOnView() - covers the onView() method in ViewAction class.

Change-Id: I1c84c8f51d96386196a1c0b44a209f90ddd8e716

tests/phpunit/includes/actions/ViewActionTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/actions/ViewActionTest.php b/tests/phpunit/includes/actions/ViewActionTest.php
new file mode 100644 (file)
index 0000000..5f659c0
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @covers \ViewAction
+ *
+ * @group Actions
+ *
+ * @author Derick N. Alangi
+ */
+class ViewActionTest extends MediaWikiTestCase {
+       /**
+        * @return ViewAction
+        */
+       private function makeViewActionClassFactory() {
+               $page = new Article( Title::newMainPage() );
+               $context = RequestContext::getMain();
+               $viewAction = new ViewAction( $page, $context );
+
+               return $viewAction;
+       }
+
+       public function testGetName() {
+               $viewAction = $this->makeViewActionClassFactory();
+               $actual = $viewAction->getName();
+
+               $this->assertSame( 'view', $actual );
+       }
+
+       public function testOnView() {
+               $viewAction = $this->makeViewActionClassFactory();
+               $actual = $viewAction->onView();
+
+               $this->assertNull( $actual );
+       }
+}