|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Test Yoast SEO integration. |
| 4 | + * |
| 5 | + * @package Activitypub |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Activitypub\Tests\Integration; |
| 9 | + |
| 10 | +use Activitypub\Integration\Yoast_Seo; |
| 11 | + |
| 12 | +/** |
| 13 | + * Test the Yoast integration. |
| 14 | + * |
| 15 | + * @group integration |
| 16 | + * @coversDefaultClass \Activitypub\Integration\Yoast_Seo |
| 17 | + */ |
| 18 | +class Test_Yoast_Seo extends \WP_UnitTestCase { |
| 19 | + |
| 20 | + /** |
| 21 | + * Test that Yoast SEO integration adds site health tests when attachment is supported. |
| 22 | + */ |
| 23 | + public function test_yoast_seo_site_health_test_registration_with_attachment_support() { |
| 24 | + // Simulate Yoast being active. |
| 25 | + if ( ! defined( 'WPSEO_VERSION' ) ) { |
| 26 | + define( 'WPSEO_VERSION', '20.0' ); |
| 27 | + } |
| 28 | + |
| 29 | + // Add attachment to supported post types. |
| 30 | + \update_option( 'activitypub_support_post_types', array( 'post', 'attachment' ) ); |
| 31 | + |
| 32 | + // Initialize the Yoast integration. |
| 33 | + Yoast_Seo::init(); |
| 34 | + |
| 35 | + // Get site health tests. |
| 36 | + $tests = \apply_filters( 'site_status_tests', array() ); |
| 37 | + |
| 38 | + // Check if our test is registered. |
| 39 | + $this->assertArrayHasKey( 'direct', $tests ); |
| 40 | + $this->assertArrayHasKey( 'activitypub_yoast_seo_media_pages', $tests['direct'] ); |
| 41 | + $this->assertEquals( 'Yoast SEO Media Pages Test', $tests['direct']['activitypub_yoast_seo_media_pages']['label'] ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Test that Yoast SEO integration does not add site health tests when attachment is not supported. |
| 46 | + */ |
| 47 | + public function test_yoast_seo_site_health_test_not_registered_without_attachment_support() { |
| 48 | + // Simulate Yoast being active. |
| 49 | + if ( ! defined( 'WPSEO_VERSION' ) ) { |
| 50 | + define( 'WPSEO_VERSION', '20.0' ); |
| 51 | + } |
| 52 | + |
| 53 | + // Remove attachment from supported post types. |
| 54 | + \update_option( 'activitypub_support_post_types', array( 'post' ) ); |
| 55 | + |
| 56 | + // Initialize the Yoast integration. |
| 57 | + Yoast_Seo::init(); |
| 58 | + |
| 59 | + // Get site health tests. |
| 60 | + $tests = \apply_filters( 'site_status_tests', array( 'direct' => array() ) ); |
| 61 | + |
| 62 | + // Check if our test is NOT registered. |
| 63 | + $this->assertArrayNotHasKey( 'activitypub_yoast_seo_media_pages', $tests['direct'] ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Test media pages disabled check. |
| 68 | + */ |
| 69 | + public function test_is_media_pages_disabled() { |
| 70 | + // Test with media pages enabled (default WordPress behavior). |
| 71 | + \update_option( 'wpseo_titles', array( 'disable-attachment' => false ) ); |
| 72 | + $this->assertFalse( Yoast_Seo::is_media_pages_disabled() ); |
| 73 | + |
| 74 | + // Test with media pages disabled (recommended setting). |
| 75 | + \update_option( 'wpseo_titles', array( 'disable-attachment' => true ) ); |
| 76 | + $this->assertTrue( Yoast_Seo::is_media_pages_disabled() ); |
| 77 | + |
| 78 | + // Test with no Yoast options. |
| 79 | + \delete_option( 'wpseo_titles' ); |
| 80 | + $this->assertFalse( Yoast_Seo::is_media_pages_disabled() ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Test the site health test execution. |
| 85 | + */ |
| 86 | + public function test_yoast_media_pages_site_health_test() { |
| 87 | + // Test when media pages are properly enabled (good status for ActivityPub). |
| 88 | + \update_option( 'wpseo_titles', array( 'disable-attachment' => false ) ); |
| 89 | + $result = Yoast_Seo::test_yoast_seo_media_pages(); |
| 90 | + |
| 91 | + $this->assertEquals( 'good', $result['status'] ); |
| 92 | + $this->assertEquals( 'Yoast SEO media pages are enabled', $result['label'] ); |
| 93 | + $this->assertEquals( 'green', $result['badge']['color'] ); |
| 94 | + |
| 95 | + // Test when media pages are disabled (recommended status to enable them). |
| 96 | + \update_option( 'wpseo_titles', array( 'disable-attachment' => true ) ); |
| 97 | + $result = Yoast_Seo::test_yoast_seo_media_pages(); |
| 98 | + |
| 99 | + $this->assertEquals( 'recommended', $result['status'] ); |
| 100 | + $this->assertEquals( 'Yoast SEO media pages should be enabled', $result['label'] ); |
| 101 | + $this->assertEquals( 'orange', $result['badge']['color'] ); |
| 102 | + $this->assertStringContainsString( 'Yoast SEO > Settings', $result['actions'] ); |
| 103 | + } |
| 104 | +} |
0 commit comments