1313 * Test class for Activitypub Options.
1414 */
1515class Test_Options extends \WP_UnitTestCase {
16+ /**
17+ * Set up the test.
18+ */
19+ public function set_up () {
20+ parent ::set_up ();
21+
22+ // Initialize Options to register hooks after storing original values.
23+ \Activitypub \Options::init ();
24+ }
25+
26+ /**
27+ * Tear down the test.
28+ */
29+ public function tear_down () {
30+ // Clean up relay-specific options.
31+ \delete_option ( 'activitypub_relay_previous_blog_identifier ' );
32+ \delete_option ( 'activitypub_relay_previous_actor_mode ' );
33+ \delete_option ( 'activitypub_relay_mode ' );
34+ \delete_option ( 'activitypub_blog_identifier ' );
35+ \delete_option ( 'activitypub_actor_mode ' );
36+
37+ parent ::tear_down ();
38+ }
39+
1640 /**
1741 * Test that delete() removes all options with the activitypub_ prefix.
1842 */
@@ -36,4 +60,52 @@ public function test_delete_removes_all_activitypub_options() {
3660 $ this ->assertFalse ( \get_option ( 'activitypub_test_option_3 ' , false ) );
3761 $ this ->assertEquals ( 'value4 ' , \get_option ( 'no_activitypub_test_option ' ) );
3862 }
63+
64+ /**
65+ * Test enabling relay mode changes settings.
66+ *
67+ * @covers \Activitypub\Options::relay_mode_changed
68+ */
69+ public function test_enabling_relay_mode () {
70+ // Set initial values.
71+ \update_option ( 'activitypub_blog_identifier ' , 'myblog ' );
72+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_AND_BLOG_MODE );
73+ \update_option ( 'activitypub_relay_mode ' , '0 ' );
74+
75+ // Enable relay mode.
76+ \update_option ( 'activitypub_relay_mode ' , '1 ' );
77+
78+ // Verify blog identifier changed to 'relay'.
79+ $ this ->assertEquals ( 'relay ' , \get_option ( 'activitypub_blog_identifier ' ) );
80+
81+ // Verify actor mode changed to blog-only.
82+ $ this ->assertEquals ( ACTIVITYPUB_BLOG_MODE , \get_option ( 'activitypub_actor_mode ' ) );
83+
84+ // Verify previous values were stored.
85+ $ this ->assertEquals ( 'myblog ' , \get_option ( 'activitypub_relay_previous_blog_identifier ' ) );
86+ $ this ->assertEquals ( ACTIVITYPUB_ACTOR_AND_BLOG_MODE , \get_option ( 'activitypub_relay_previous_actor_mode ' ) );
87+ }
88+
89+ /**
90+ * Test disabling relay mode restores settings.
91+ *
92+ * @covers \Activitypub\Options::relay_mode_changed
93+ */
94+ public function test_disabling_relay_mode () {
95+ // Enable relay mode first.
96+ \update_option ( 'activitypub_blog_identifier ' , 'myblog ' );
97+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_AND_BLOG_MODE );
98+ \update_option ( 'activitypub_relay_mode ' , '1 ' );
99+
100+ // Now disable it.
101+ \update_option ( 'activitypub_relay_mode ' , '0 ' );
102+
103+ // Verify settings were restored.
104+ $ this ->assertEquals ( 'myblog ' , \get_option ( 'activitypub_blog_identifier ' ) );
105+ $ this ->assertEquals ( ACTIVITYPUB_ACTOR_AND_BLOG_MODE , \get_option ( 'activitypub_actor_mode ' ) );
106+
107+ // Verify previous value options were deleted.
108+ $ this ->assertFalse ( \get_option ( 'activitypub_relay_previous_blog_identifier ' , false ) );
109+ $ this ->assertFalse ( \get_option ( 'activitypub_relay_previous_actor_mode ' , false ) );
110+ }
39111}
0 commit comments