From fbc7d258163100b7de1b7175b6b907b9c91a77cf Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Tue, 28 Jun 2022 18:13:44 -0700
Subject: [PATCH] Test coverage

---
 phpunit.xml                                 |  3 +-
 tests/bootstrap.php                         |  2 +-
 tests/test-automatically-paginate-posts.php | 59 +++++++++++++++++++++
 tests/test-sample.php                       | 20 -------
 4 files changed, 61 insertions(+), 23 deletions(-)
 create mode 100755 tests/test-automatically-paginate-posts.php
 delete mode 100755 tests/test-sample.php

diff --git a/phpunit.xml b/phpunit.xml
index 16a3902..3dca2e0 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -8,9 +8,8 @@
 	convertWarningsToExceptions="true"
 	>
 	<testsuites>
-		<testsuite>
+		<testsuite name="Autopaging">
 			<directory prefix="test-" suffix=".php">./tests/</directory>
-			<exclude>./tests/test-sample.php</exclude>
 		</testsuite>
 	</testsuites>
 </phpunit>
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 8ce7872..db83740 100755
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -5,7 +5,7 @@
  * @package Automatically_Paginate_Posts
  */
 
-$autopaging_tests_dir = getenv( 'WPautopaging_tests_dir' );
+$autopaging_tests_dir = getenv( 'WP_TESTS_DIR' );
 
 if ( ! $autopaging_tests_dir ) {
 	$autopaging_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
diff --git a/tests/test-automatically-paginate-posts.php b/tests/test-automatically-paginate-posts.php
new file mode 100755
index 0000000..31b1b28
--- /dev/null
+++ b/tests/test-automatically-paginate-posts.php
@@ -0,0 +1,59 @@
+<?php
+/**
+ * Test main plugin class.
+ *
+ * @package Automatically_Paginate_Posts
+ */
+
+/**
+ * @coversDefaultClass Automatically_Paginate_Posts
+ */
+class SampleTest extends WP_UnitTestCase {
+	protected $_instance;
+
+	public function set_up() {
+		parent::set_up();
+
+		$this->_instance = new Automatically_Paginate_Posts();
+	}
+
+	/**
+	 * @covers ::__get()
+	 */
+	public function test___get() {
+		$this->assertEquals(
+			'_disable_autopaging',
+			$this->_instance->meta_key,
+			'Failed to assert meta key matched expected value.'
+		);
+
+		// TODO: consider testing `post_types` along with a filter.
+
+		$this->assertNull(
+			$this->_instance->unit_test,
+			'Failed to assert that unsupported key returns null.'
+		);
+	}
+
+	/**
+	 * @covers ::filter_plugin_action_links()
+	 */
+	public function test_filter_plugin_action_links() {
+		$this->assertEmpty(
+			$this->_instance->filter_plugin_action_links(
+				array(),
+				'unit-test.php'
+			),
+			'Failed to assert that no change is made for other plugins..'
+		);
+
+		$this->assertArrayHasKey(
+			'settings',
+			$this->_instance->filter_plugin_action_links(
+				array(),
+				'automatically-paginate-posts/automatically-paginate-posts.php'
+			),
+			'Failed to assert that settings link is added for this plugin.'
+		);
+	}
+}
diff --git a/tests/test-sample.php b/tests/test-sample.php
deleted file mode 100755
index 1694274..0000000
--- a/tests/test-sample.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * Class SampleTest
- *
- * @package Automatically_Paginate_Posts
- */
-
-/**
- * Sample test case.
- */
-class SampleTest extends WP_UnitTestCase {
-
-	/**
-	 * A single example test.
-	 */
-	public function test_sample() {
-		// Replace this with some actual testing code.
-		$this->assertTrue( true );
-	}
-}
-- 
GitLab