|
5 | 5 | * @package Activitypub |
6 | 6 | */ |
7 | 7 |
|
8 | | -namespace Activitypub\Activity; |
| 8 | +namespace Activitypub\Tests\Activity; |
9 | 9 |
|
| 10 | +use Activitypub\Activity\Base_Object; |
| 11 | +use Activitypub\Activity\Generic_Object; |
10 | 12 | use WP_UnitTestCase; |
11 | 13 |
|
12 | 14 | /** |
@@ -117,4 +119,79 @@ public function test_to_array() { |
117 | 119 | $this->assertEquals( $test_data['inReplyTo'], $array['inReplyTo'] ); |
118 | 120 | $this->assertEquals( $test_data['mediaType'], $array['mediaType'] ); |
119 | 121 | } |
| 122 | + |
| 123 | + /** |
| 124 | + * Test if init_from_array correctly handles quote property. |
| 125 | + * |
| 126 | + * Tests that the quote property can be set from array. |
| 127 | + * Uses Base_Object which has the quote property defined. |
| 128 | + * |
| 129 | + * @covers Activitypub\Activity\Generic_Object::init_from_array |
| 130 | + */ |
| 131 | + public function test_init_from_array_quote_property() { |
| 132 | + $test_data = array( |
| 133 | + 'id' => 'https://example.com/note/123', |
| 134 | + 'type' => 'Note', |
| 135 | + 'quote' => 'https://example.com/post/456', |
| 136 | + ); |
| 137 | + |
| 138 | + $object = Base_Object::init_from_array( $test_data ); |
| 139 | + |
| 140 | + // Verify quote property is accessible. |
| 141 | + $this->assertEquals( $test_data['quote'], $object->get_quote() ); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Test if init_from_array correctly handles underscore-prefixed properties. |
| 146 | + * |
| 147 | + * Uses Base_Object which has the _misskey_quote property defined. |
| 148 | + * |
| 149 | + * @covers Activitypub\Activity\Generic_Object::init_from_array |
| 150 | + */ |
| 151 | + public function test_init_from_array_underscore_properties() { |
| 152 | + $test_data = array( |
| 153 | + 'id' => 'https://example.com/note/123', |
| 154 | + 'type' => 'Note', |
| 155 | + '_misskey_quote' => 'https://example.com/post/789', |
| 156 | + ); |
| 157 | + |
| 158 | + $object = Base_Object::init_from_array( $test_data ); |
| 159 | + |
| 160 | + // Test that underscore property is accessible. |
| 161 | + $this->assertEquals( $test_data['_misskey_quote'], $object->get__misskey_quote() ); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Test quote properties round-trip through set/get. |
| 166 | + * |
| 167 | + * Uses Base_Object to verify quote properties can be set and retrieved. |
| 168 | + * |
| 169 | + * @covers Activitypub\Activity\Generic_Object::__call |
| 170 | + */ |
| 171 | + public function test_quote_properties_set_and_get() { |
| 172 | + $object = new Base_Object(); |
| 173 | + |
| 174 | + $object->set_quote( 'https://example.com/post/456' ); |
| 175 | + $object->set_quote_url( 'https://example.com/post/789' ); |
| 176 | + $object->set_quote_uri( 'https://example.com/post/101' ); |
| 177 | + |
| 178 | + $this->assertEquals( 'https://example.com/post/456', $object->get_quote() ); |
| 179 | + $this->assertEquals( 'https://example.com/post/789', $object->get_quote_url() ); |
| 180 | + $this->assertEquals( 'https://example.com/post/101', $object->get_quote_uri() ); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Test underscore-prefixed properties round-trip through set/get. |
| 185 | + * |
| 186 | + * Uses Base_Object to verify _misskey_quote property can be set and retrieved. |
| 187 | + * |
| 188 | + * @covers Activitypub\Activity\Generic_Object::__call |
| 189 | + */ |
| 190 | + public function test_underscore_properties_set_and_get() { |
| 191 | + $object = new Base_Object(); |
| 192 | + |
| 193 | + $object->set__misskey_quote( 'https://example.com/post/789' ); |
| 194 | + |
| 195 | + $this->assertEquals( 'https://example.com/post/789', $object->get__misskey_quote() ); |
| 196 | + } |
120 | 197 | } |
0 commit comments