55 * @package accessibility-checker
66 */
77
8- use PHPUnit \Framework \TestCase ;
98use EqualizeDigital \AccessibilityChecker \Fixes \Fix \AddMissingOrEmptyPageTitleFix ;
10- use EqualizeDigital \AccessibilityChecker \Fixes \FixInterface ;
119
1210require_once __DIR__ . '/FixTestTrait.php ' ;
1311
@@ -26,6 +24,17 @@ class AddMissingOrEmptyPageTitleFixTest extends WP_UnitTestCase {
2624 public function set_up () {
2725 parent ::set_up ();
2826 $ this ->fix = new AddMissingOrEmptyPageTitleFix ();
27+ $ this ->common_setup ();
28+ }
29+
30+ /**
31+ * Clean up after tests.
32+ *
33+ * @return void
34+ */
35+ public function tearDown (): void {
36+ $ this ->common_teardown ();
37+ parent ::tearDown ();
2938 }
3039
3140 /**
@@ -56,104 +65,23 @@ protected function get_fix_class_name(): string {
5665 }
5766
5867 /**
59- * Test get_fields_array returns properly structured array.
60- *
61- * @return void
62- */
63- public function test_get_fields_array () {
64- $ fields = $ this ->fix ->get_fields_array ();
65-
66- $ this ->assertArrayHasKey ( 'edac_fix_add_missing_or_empty_page_title ' , $ fields );
67-
68- $ field = $ fields ['edac_fix_add_missing_or_empty_page_title ' ];
69- $ this ->assertEquals ( 'checkbox ' , $ field ['type ' ] );
70- $ this ->assertEquals ( 'Add Missing Page Title ' , $ field ['label ' ] );
71- $ this ->assertEquals ( 'add_missing_or_empty_page_title ' , $ field ['labelledby ' ] );
72- $ this ->assertEquals ( 'missing_or_empty_page_title ' , $ field ['fix_slug ' ] );
73- $ this ->assertEquals ( 'Add Missing or Empty Page Titles ' , $ field ['group_name ' ] );
74- $ this ->assertEquals ( 8490 , $ field ['help_id ' ] );
75- $ this ->assertStringContainsString ( '<title> ' , $ field ['description ' ] );
76- }
77-
78- /**
79- * Test get_fields_array with pro feature enabled.
80- *
81- * @return void
82- */
83- public function test_get_fields_array_pro_upsell () {
84- // Test without is_pro property (should show upsell).
85- $ fields = $ this ->fix ->get_fields_array ();
86- $ field = $ fields ['edac_fix_add_missing_or_empty_page_title ' ];
87- $ this ->assertTrue ( $ field ['upsell ' ] );
88- }
89-
90- /**
91- * Test get_fields_array with pro feature disabled (default behavior).
92- *
93- * @return void
94- */
95- public function test_get_fields_array_pro_enabled () {
96- // Create an anonymous class that extends the fix to simulate pro version.
97- $ fix = new class () extends AddMissingOrEmptyPageTitleFix {
98- /**
99- * Pro flag for testing.
100- *
101- * @var bool
102- */
103- public $ is_pro = true ;
104- };
105-
106- $ fields = $ fix ->get_fields_array ();
107- $ field = $ fields ['edac_fix_add_missing_or_empty_page_title ' ];
108- $ this ->assertFalse ( $ field ['upsell ' ] );
109- }
110-
111- /**
112- * Test register method adds filter.
113- *
114- * @return void
115- */
116- public function test_register_adds_filter () {
117- $ this ->fix ->register ();
118-
119- // Verify that the filter was added by checking if it has the expected callback.
120- $ this ->assertTrue ( has_filter ( 'edac_filter_fixes_settings_fields ' , [ $ this ->fix , 'get_fields_array ' ] ) !== false );
121- }
122-
123- /**
124- * Test run method does nothing (intentionally empty).
68+ * Test that run method does nothing.
69+ * This fix is pro-only and doesn't implement actual functionality.
12570 *
12671 * @return void
12772 */
12873 public function test_run_does_nothing () {
129- // Since run() is intentionally empty, just ensure it doesn't throw errors.
13074 $ this ->assertNull ( $ this ->fix ->run () );
13175 }
13276
13377 /**
134- * Test field array structure validation .
78+ * Test pro upsell is enabled by default .
13579 *
13680 * @return void
13781 */
138- public function test_field_array_structure () {
82+ public function test_fields_show_pro_upsell () {
13983 $ fields = $ this ->fix ->get_fields_array ();
14084 $ field = $ fields ['edac_fix_add_missing_or_empty_page_title ' ];
141-
142- // Required field properties.
143- $ required_properties = [ 'type ' , 'label ' , 'labelledby ' , 'description ' , 'fix_slug ' , 'group_name ' , 'help_id ' ];
144-
145- foreach ( $ required_properties as $ property ) {
146- $ this ->assertArrayHasKey ( $ property , $ field , "Field missing required property: {$ property }" );
147- }
148-
149- // Validate specific property types.
150- $ this ->assertIsString ( $ field ['type ' ] );
151- $ this ->assertIsString ( $ field ['label ' ] );
152- $ this ->assertIsString ( $ field ['labelledby ' ] );
153- $ this ->assertIsString ( $ field ['description ' ] );
154- $ this ->assertIsString ( $ field ['fix_slug ' ] );
155- $ this ->assertIsString ( $ field ['group_name ' ] );
156- $ this ->assertIsInt ( $ field ['help_id ' ] );
157- $ this ->assertIsBool ( $ field ['upsell ' ] );
85+ $ this ->assertTrue ( $ field ['upsell ' ] );
15886 }
15987}
0 commit comments