| | 175 | |
| | 176 | /** |
| | 177 | * @ticket 22960 |
| | 178 | */ |
| | 179 | function test_get_attached_images() { |
| | 180 | $post_id = $this->factory->post->create(); |
| | 181 | $attachment_id = $this->factory->attachment->create_object( $this->img_name, $post_id, array( |
| | 182 | 'post_mime_type' => 'image/jpeg', |
| | 183 | 'post_type' => 'attachment' |
| | 184 | ) ); |
| | 185 | |
| | 186 | $images = get_attached_images( $post_id ); |
| | 187 | $this->assertEquals( $images, array( $attachment_id => get_post( $attachment_id ) ) ); |
| | 188 | } |
| | 189 | |
| | 190 | /** |
| | 191 | * @ticket 22960 |
| | 192 | */ |
| | 193 | function test_get_attached_image_srcs() { |
| | 194 | $post_id = $this->factory->post->create(); |
| | 195 | $this->factory->attachment->create_object( $this->img_name, $post_id, array( |
| | 196 | 'post_mime_type' => 'image/jpeg', |
| | 197 | 'post_type' => 'attachment' |
| | 198 | ) ); |
| | 199 | |
| | 200 | $images = get_attached_image_srcs( $post_id ); |
| | 201 | $this->assertEquals( $images, array( $this->img_url ) ); |
| | 202 | } |
| | 203 | |
| | 204 | /** |
| | 205 | * @ticket 22960 |
| | 206 | */ |
| | 207 | function test_content_images() { |
| | 208 | $blob =<<<BLOB |
| | 209 | This is a sentence that will all of a sudden contain <img src="{$this->img_url}"/> |
| | 210 | BLOB; |
| | 211 | |
| | 212 | $images = get_content_images( $blob ); |
| | 213 | $this->assertEquals( $images, array( $this->img_url ) ); |
| | 214 | } |
| | 215 | |
| | 216 | /** |
| | 217 | * @ticket 22960 |
| | 218 | */ |
| | 219 | function test_content_image() { |
| | 220 | $blob =<<<BLOB |
| | 221 | This is a sentence that will all of a sudden contain <img src="{$this->img_url}"/> |
| | 222 | BLOB; |
| | 223 | |
| | 224 | $image = get_content_image( $blob ); |
| | 225 | $this->assertEquals( $image, $this->img_url ); |
| | 226 | } |
| | 227 | |
| | 228 | /** |
| | 229 | * @ticket 22960 |
| | 230 | */ |
| | 231 | function test_content_galleries() { |
| | 232 | $ids1 = array(); |
| | 233 | $ids1_srcs = array(); |
| | 234 | foreach ( range( 1, 3 ) as $i ) { |
| | 235 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 236 | 'post_mime_type' => 'image/jpeg', |
| | 237 | 'post_type' => 'attachment' |
| | 238 | ) ); |
| | 239 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 240 | $ids1[] = $attachment_id; |
| | 241 | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 242 | } |
| | 243 | |
| | 244 | $ids2 = array(); |
| | 245 | $ids2_srcs = array(); |
| | 246 | foreach ( range( 4, 6 ) as $i ) { |
| | 247 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 248 | 'post_mime_type' => 'image/jpeg', |
| | 249 | 'post_type' => 'attachment' |
| | 250 | ) ); |
| | 251 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 252 | $ids2[] = $attachment_id; |
| | 253 | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 254 | } |
| | 255 | |
| | 256 | $ids1_joined = join( ',', $ids1 ); |
| | 257 | $ids2_joined = join( ',', $ids2 ); |
| | 258 | |
| | 259 | $blob =<<<BLOB |
| | 260 | [gallery ids="$ids1_joined"] |
| | 261 | |
| | 262 | [gallery ids="$ids2_joined"] |
| | 263 | BLOB; |
| | 264 | |
| | 265 | $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
| | 266 | $galleries = get_content_galleries( get_post_field( 'post_content', $post_id ) ); |
| | 267 | $expected = array( |
| | 268 | array( 'ids' => $ids1_joined, 'src' => $ids1_srcs ), |
| | 269 | array( 'ids' => $ids2_joined, 'src' => $ids2_srcs ) |
| | 270 | ); |
| | 271 | $this->assertEquals( $galleries, $expected ); |
| | 272 | } |
| | 273 | |
| | 274 | /** |
| | 275 | * @ticket 22960 |
| | 276 | */ |
| | 277 | function test_post_galleries_images() { |
| | 278 | $ids1 = array(); |
| | 279 | $ids1_srcs = array(); |
| | 280 | foreach ( range( 1, 3 ) as $i ) { |
| | 281 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 282 | 'post_mime_type' => 'image/jpeg', |
| | 283 | 'post_type' => 'attachment' |
| | 284 | ) ); |
| | 285 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 286 | $ids1[] = $attachment_id; |
| | 287 | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 288 | } |
| | 289 | |
| | 290 | $ids2 = array(); |
| | 291 | $ids2_srcs = array(); |
| | 292 | foreach ( range( 4, 6 ) as $i ) { |
| | 293 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 294 | 'post_mime_type' => 'image/jpeg', |
| | 295 | 'post_type' => 'attachment' |
| | 296 | ) ); |
| | 297 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 298 | $ids2[] = $attachment_id; |
| | 299 | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 300 | } |
| | 301 | |
| | 302 | $ids1_joined = join( ',', $ids1 ); |
| | 303 | $ids2_joined = join( ',', $ids2 ); |
| | 304 | |
| | 305 | $blob =<<<BLOB |
| | 306 | [gallery ids="$ids1_joined"] |
| | 307 | |
| | 308 | [gallery ids="$ids2_joined"] |
| | 309 | BLOB; |
| | 310 | $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
| | 311 | $srcs = get_post_galleries_images( $post_id ); |
| | 312 | $this->assertEquals( $srcs, array( $ids1_srcs, $ids2_srcs ) ); |
| | 313 | } |
| | 314 | |
| | 315 | /** |
| | 316 | * @ticket 22960 |
| | 317 | */ |
| | 318 | function test_post_gallery_images() { |
| | 319 | $ids1 = array(); |
| | 320 | $ids1_srcs = array(); |
| | 321 | foreach ( range( 1, 3 ) as $i ) { |
| | 322 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 323 | 'post_mime_type' => 'image/jpeg', |
| | 324 | 'post_type' => 'attachment' |
| | 325 | ) ); |
| | 326 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 327 | $ids1[] = $attachment_id; |
| | 328 | $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 329 | } |
| | 330 | |
| | 331 | $ids2 = array(); |
| | 332 | $ids2_srcs = array(); |
| | 333 | foreach ( range( 4, 6 ) as $i ) { |
| | 334 | $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
| | 335 | 'post_mime_type' => 'image/jpeg', |
| | 336 | 'post_type' => 'attachment' |
| | 337 | ) ); |
| | 338 | wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
| | 339 | $ids2[] = $attachment_id; |
| | 340 | $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
| | 341 | } |
| | 342 | |
| | 343 | $ids1_joined = join( ',', $ids1 ); |
| | 344 | $ids2_joined = join( ',', $ids2 ); |
| | 345 | |
| | 346 | $blob =<<<BLOB |
| | 347 | [gallery ids="$ids1_joined"] |
| | 348 | |
| | 349 | [gallery ids="$ids2_joined"] |
| | 350 | BLOB; |
| | 351 | $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
| | 352 | $srcs = get_post_gallery_images( $post_id ); |
| | 353 | $this->assertEquals( $srcs, $ids1_srcs ); |
| | 354 | } |