1010// If specific mocks are needed, they should be handled by WP_Mock or filters if possible.
1111// Removing global shims as they likely cause conflicts with the CI's WordPress environment.
1212
13- // Mock Pro class definitions will be moved inside the specific tests that need them
14- // to ensure they are only defined within an isolated process.
13+ // Mock Pro classes if they don't exist - this is for local testing if Pro plugin isn't present.
14+ // These are defined at the top level, guarded by class_exists, and tests using them
15+ // for aliasing run in separate processes.
16+ if ( ! class_exists ( 'MockEDACPSettings ' , false ) ) {
17+ class MockEDACPSettings {
18+ public static $ returnValue = ['post ' , 'page ' , 'custom_pro_type ' ];
19+ public static function get_scannable_post_types () {
20+ return self ::$ returnValue ;
21+ }
22+ }
23+ }
24+ if ( ! class_exists ( 'MockEqualizeDigitalAccessibilityCheckerProAdminSettings ' , false ) ) {
25+ class MockEqualizeDigitalAccessibilityCheckerProAdminSettings {
26+ public static $ returnValue = ['post ' , 'page ' , 'new_custom_pro_type ' ];
27+ public static function get_scannable_post_types () {
28+ return self ::$ returnValue ;
29+ }
30+ }
31+ }
1532
1633class SettingsTest extends WP_UnitTestCase {
1734
@@ -148,32 +165,20 @@ public function test_get_scannable_post_types_free_version_option_returns_string
148165 * @preserveGlobalState disabled
149166 */
150167 public function test_get_scannable_post_types_pro_version_edacp_settings_exists () {
151- // Define mock class here to ensure it's only for this process
152- if ( ! class_exists ( 'MockEDACPSettingsForTest ' , false ) ) {
153- class MockEDACPSettingsForTest {
154- public static $ returnValue = ['post ' , 'page ' , 'custom_pro_type_edacp ' ];
155- public static function get_scannable_post_types () {
156- return self ::$ returnValue ;
157- }
158- }
159- }
160-
161- if (!class_exists ('EDACP\Settings ' )) {
162- class_alias ('MockEDACPSettingsForTest ' , 'EDACP\Settings ' );
163- } elseif (!is_a ('EDACP\Settings ' , 'MockEDACPSettingsForTest ' , true )) {
168+ // Aliasing to the globally defined (but guarded) mock classes.
169+ if (!class_exists ('EDACP\Settings ' , false )) {
170+ class_alias ('MockEDACPSettings ' , 'EDACP\Settings ' );
171+ } elseif (!is_a ('EDACP\Settings ' , 'MockEDACPSettings ' , true )) {
164172 $ this ->markTestSkipped ('Original EDACP\Settings class is present and not the mock. Cannot reliably test this scenario. ' );
165173 }
166174
167175 // Ensure the newer Pro settings class does NOT exist or is not our mock for it for this specific test.
168- // If EqualizeDigital\AccessibilityCheckerPro\Admin\Settings exists and is the REAL one, this test is not valid.
169176 if (class_exists ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , false ) &&
170- !is_a ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , 'MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest ' , true ) ) {
171- // This is complex; ideally, we'd ensure it's not loaded.
172- // For now, if the real class exists, this test for the older pro class might be skewed.
173- // Consider if this scenario (real new pro class + mock old pro class) is truly testable/needed.
177+ !is_a ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , 'MockEqualizeDigitalAccessibilityCheckerProAdminSettings ' , true ) ) {
178+ // If the real new pro class exists, this test for the older pro class might be skewed.
174179 }
175180
176- $ expected_types = \MockEDACPSettingsForTest ::$ returnValue ;
181+ $ expected_types = \MockEDACPSettings ::$ returnValue ;
177182 $ post_types = Settings::get_scannable_post_types ();
178183 $ this ->assertEquals ( $ expected_types , $ post_types );
179184 }
@@ -183,39 +188,21 @@ class_alias('MockEDACPSettingsForTest', 'EDACP\Settings');
183188 * @preserveGlobalState disabled
184189 */
185190 public function test_get_scannable_post_types_pro_version_new_settings_class_exists () {
186- // Define mock classes here
187- if ( ! class_exists ( 'MockEDACPSettingsForTestNew ' , false ) ) {
188- class MockEDACPSettingsForTestNew { // Different name to avoid conflict if somehow same process
189- public static $ returnValue = ['post ' , 'page ' , 'custom_pro_type_edacp_old_for_new_test ' ];
190- public static function get_scannable_post_types () {
191- return self ::$ returnValue ;
192- }
193- }
194- }
195- if ( ! class_exists ( 'MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest ' , false ) ) {
196- class MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest {
197- public static $ returnValue = ['post ' , 'page ' , 'new_custom_pro_type_new ' ];
198- public static function get_scannable_post_types () {
199- return self ::$ returnValue ;
200- }
201- }
202- }
203-
204- // Mock new settings class to exist
205- if (!class_exists ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' )) {
206- class_alias ('MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest ' , 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' );
207- } elseif (!is_a ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , 'MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest ' , true )) {
191+ // Aliasing to the globally defined (but guarded) mock classes.
192+ if (!class_exists ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , false )) {
193+ class_alias ('MockEqualizeDigitalAccessibilityCheckerProAdminSettings ' , 'EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' );
194+ } elseif (!is_a ('EqualizeDigital\AccessibilityCheckerPro\Admin\Settings ' , 'MockEqualizeDigitalAccessibilityCheckerProAdminSettings ' , true )) {
208195 $ this ->markTestSkipped ('Original EqualizeDigital\AccessibilityCheckerPro\Admin\Settings class is present and not the mock. ' );
209196 }
210197
211198 // Also ensure the older EDACP\Settings exists (as our mock) to test precedence
212- if (!class_exists ('EDACP\Settings ' )) {
213- class_alias ('MockEDACPSettingsForTestNew ' , 'EDACP\Settings ' );
214- } elseif (!is_a ('EDACP\Settings ' , 'MockEDACPSettingsForTestNew ' , true ) ){
215- // This indicates the actual EDACP\Settings might be loaded and isn't our mock for this specific test run .
199+ if (!class_exists ('EDACP\Settings ' , false )) {
200+ class_alias ('MockEDACPSettings ' , 'EDACP\Settings ' );
201+ } elseif (!is_a ('EDACP\Settings ' , 'MockEDACPSettings ' , true ) ){
202+ // This indicates the actual EDACP\Settings might be loaded and isn't our mock.
216203 }
217204
218- $ expected_types = \MockEqualizeDigitalAccessibilityCheckerProAdminSettingsForTest ::$ returnValue ;
205+ $ expected_types = \MockEqualizeDigitalAccessibilityCheckerProAdminSettings ::$ returnValue ;
219206 $ post_types = Settings::get_scannable_post_types ();
220207 $ this ->assertEquals ( $ expected_types , $ post_types );
221208 }
0 commit comments