From 7b2dfa793a3e984f5286ba3e5c38db0664b43161 Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Fri, 11 Jul 2025 12:12:35 +0600 Subject: [PATCH 1/2] Feat: added importer unit test --- tests/phpunit/tutor-pro/ImporterTest.php | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/phpunit/tutor-pro/ImporterTest.php diff --git a/tests/phpunit/tutor-pro/ImporterTest.php b/tests/phpunit/tutor-pro/ImporterTest.php new file mode 100644 index 0000000000..09a7438df7 --- /dev/null +++ b/tests/phpunit/tutor-pro/ImporterTest.php @@ -0,0 +1,69 @@ +importer = new \TutorPro\Tools\Importer(); + wp_set_current_user( 1 ); + } + + protected function tearDown(): void { + unset( $this->importer ); + + parent::tearDown(); + } + + + public function test_import_json_content() { + $json_data = file_get_contents( '' ); // file path. + + $response = $this->importer->import_contents( $json_data ); + + $this->assertFalse( is_wp_error( $response ) ); + } +} \ No newline at end of file From ad33b927f49127d41238e3a8eb277aee0009e74f Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Tue, 15 Jul 2025 11:31:22 +0600 Subject: [PATCH 2/2] phpcs fix --- tests/phpunit/tutor-pro/ImporterTest.php | 42 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tutor-pro/ImporterTest.php b/tests/phpunit/tutor-pro/ImporterTest.php index 09a7438df7..121f154fe6 100644 --- a/tests/phpunit/tutor-pro/ImporterTest.php +++ b/tests/phpunit/tutor-pro/ImporterTest.php @@ -9,12 +9,29 @@ namespace TutorTest; +/** + * Importer Test Class + */ class ImporterTest extends \PHPUnit\Framework\TestCase { + /** + * Importer instance + * + * @since 3.6.0 + * + * @var object + */ private $importer; const TUTOR_TEST_PRO_DIRECTORY = ''; + /** + * Setup function that runs before the test case runs. + * + * @since 3.6.0 + * + * @return void + */ protected function setUp(): void { global $current_user; parent::setUp(); @@ -27,38 +44,51 @@ protected function setUp(): void { if ( file_exists( $importer_path ) ) { require_once $importer_path; } else { - echo $importer_path . ' ' . 'does not exists.'; + echo esc_html( $importer_path . ' does not exists.' ); } if ( file_exists( $course_importer_path ) ) { require_once $course_importer_path; } else { - echo $course_importer_path . ' ' . 'does not exists.'; + echo esc_html( $course_importer_path . ' does not exists.' ); } if ( file_exists( $assignment_importer_path ) ) { require_once $assignment_importer_path; } else { - echo $assignment_importer_path . ' ' . 'does not exists.'; + echo esc_html( $assignment_importer_path . ' does not exists.' ); } if ( file_exists( $quiz_importer_path ) ) { require_once $quiz_importer_path; } else { - echo $quiz_importer_path . ' ' . 'does not exists.'; + echo esc_html( $quiz_importer_path . ' does not exists.' ); } $this->importer = new \TutorPro\Tools\Importer(); wp_set_current_user( 1 ); } + /** + * Teardown function that runs after the test has ran. + * + * @since 3.6.0 + * + * @return void + */ protected function tearDown(): void { unset( $this->importer ); parent::tearDown(); } - + /** + * Test importing json content with importer. + * + * @since 3.6.0 + * + * @return void + */ public function test_import_json_content() { $json_data = file_get_contents( '' ); // file path. @@ -66,4 +96,4 @@ public function test_import_json_content() { $this->assertFalse( is_wp_error( $response ) ); } -} \ No newline at end of file +}