| 1 | diff --git tests/media.php tests/media.php |
|---|
| 2 | index abc62c5..5732de4 100644 |
|---|
| 3 | --- tests/media.php |
|---|
| 4 | +++ tests/media.php |
|---|
| 5 | @@ -15,6 +15,9 @@ CAP; |
|---|
| 6 | $this->img_content = <<<CAP |
|---|
| 7 | <img src="pic.jpg" id='anId' alt="pic"/> |
|---|
| 8 | CAP; |
|---|
| 9 | + $this->img_name = 'image.jpg'; |
|---|
| 10 | + $this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name; |
|---|
| 11 | + $this->img_dimensions = array( 'width' => 100, 'height' => 100 ); |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | function test_img_caption_shortcode_added() { |
|---|
| 15 | @@ -169,4 +172,184 @@ CAP; |
|---|
| 16 | $this->assertEquals( '-1B', wp_convert_bytes_to_hr( -1 ) ); |
|---|
| 17 | $this->assertEquals( '0B', wp_convert_bytes_to_hr( 0 ) ); |
|---|
| 18 | } |
|---|
| 19 | + |
|---|
| 20 | + /** |
|---|
| 21 | + * @ticket 22960 |
|---|
| 22 | + */ |
|---|
| 23 | + function test_get_attached_images() { |
|---|
| 24 | + $post_id = $this->factory->post->create(); |
|---|
| 25 | + $attachment_id = $this->factory->attachment->create_object( $this->img_name, $post_id, array( |
|---|
| 26 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 27 | + 'post_type' => 'attachment' |
|---|
| 28 | + ) ); |
|---|
| 29 | + |
|---|
| 30 | + $images = get_attached_images( $post_id ); |
|---|
| 31 | + $this->assertEquals( $images, array( $attachment_id => get_post( $attachment_id ) ) ); |
|---|
| 32 | + } |
|---|
| 33 | + |
|---|
| 34 | + /** |
|---|
| 35 | + * @ticket 22960 |
|---|
| 36 | + */ |
|---|
| 37 | + function test_get_attached_image_srcs() { |
|---|
| 38 | + $post_id = $this->factory->post->create(); |
|---|
| 39 | + $this->factory->attachment->create_object( $this->img_name, $post_id, array( |
|---|
| 40 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 41 | + 'post_type' => 'attachment' |
|---|
| 42 | + ) ); |
|---|
| 43 | + |
|---|
| 44 | + $images = get_attached_image_srcs( $post_id ); |
|---|
| 45 | + $this->assertEquals( $images, array( $this->img_url ) ); |
|---|
| 46 | + } |
|---|
| 47 | + |
|---|
| 48 | + /** |
|---|
| 49 | + * @ticket 22960 |
|---|
| 50 | + */ |
|---|
| 51 | + function test_content_images() { |
|---|
| 52 | + $blob =<<<BLOB |
|---|
| 53 | +This is a sentence that will all of a sudden contain <img src="{$this->img_url}"/> |
|---|
| 54 | +BLOB; |
|---|
| 55 | + |
|---|
| 56 | + $images = get_content_images( $blob ); |
|---|
| 57 | + $this->assertEquals( $images, array( $this->img_url ) ); |
|---|
| 58 | + } |
|---|
| 59 | + |
|---|
| 60 | + /** |
|---|
| 61 | + * @ticket 22960 |
|---|
| 62 | + */ |
|---|
| 63 | + function test_content_image() { |
|---|
| 64 | + $blob =<<<BLOB |
|---|
| 65 | +This is a sentence that will all of a sudden contain <img src="{$this->img_url}"/> |
|---|
| 66 | +BLOB; |
|---|
| 67 | + |
|---|
| 68 | + $image = get_content_image( $blob ); |
|---|
| 69 | + $this->assertEquals( $image, $this->img_url ); |
|---|
| 70 | + } |
|---|
| 71 | + |
|---|
| 72 | + /** |
|---|
| 73 | + * @ticket 22960 |
|---|
| 74 | + */ |
|---|
| 75 | + function test_content_galleries() { |
|---|
| 76 | + $ids1 = array(); |
|---|
| 77 | + $ids1_srcs = array(); |
|---|
| 78 | + foreach ( range( 1, 3 ) as $i ) { |
|---|
| 79 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 80 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 81 | + 'post_type' => 'attachment' |
|---|
| 82 | + ) ); |
|---|
| 83 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 84 | + $ids1[] = $attachment_id; |
|---|
| 85 | + $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 86 | + } |
|---|
| 87 | + |
|---|
| 88 | + $ids2 = array(); |
|---|
| 89 | + $ids2_srcs = array(); |
|---|
| 90 | + foreach ( range( 4, 6 ) as $i ) { |
|---|
| 91 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 92 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 93 | + 'post_type' => 'attachment' |
|---|
| 94 | + ) ); |
|---|
| 95 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 96 | + $ids2[] = $attachment_id; |
|---|
| 97 | + $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 98 | + } |
|---|
| 99 | + |
|---|
| 100 | + $ids1_joined = join( ',', $ids1 ); |
|---|
| 101 | + $ids2_joined = join( ',', $ids2 ); |
|---|
| 102 | + |
|---|
| 103 | + $blob =<<<BLOB |
|---|
| 104 | +[gallery ids="$ids1_joined"] |
|---|
| 105 | + |
|---|
| 106 | +[gallery ids="$ids2_joined"] |
|---|
| 107 | +BLOB; |
|---|
| 108 | + |
|---|
| 109 | + $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
|---|
| 110 | + $galleries = get_content_galleries( get_post_field( 'post_content', $post_id ) ); |
|---|
| 111 | + $expected = array( |
|---|
| 112 | + array( 'ids' => $ids1_joined, 'src' => $ids1_srcs ), |
|---|
| 113 | + array( 'ids' => $ids2_joined, 'src' => $ids2_srcs ) |
|---|
| 114 | + ); |
|---|
| 115 | + $this->assertEquals( $galleries, $expected ); |
|---|
| 116 | + } |
|---|
| 117 | + |
|---|
| 118 | + /** |
|---|
| 119 | + * @ticket 22960 |
|---|
| 120 | + */ |
|---|
| 121 | + function test_post_galleries_images() { |
|---|
| 122 | + $ids1 = array(); |
|---|
| 123 | + $ids1_srcs = array(); |
|---|
| 124 | + foreach ( range( 1, 3 ) as $i ) { |
|---|
| 125 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 126 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 127 | + 'post_type' => 'attachment' |
|---|
| 128 | + ) ); |
|---|
| 129 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 130 | + $ids1[] = $attachment_id; |
|---|
| 131 | + $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 132 | + } |
|---|
| 133 | + |
|---|
| 134 | + $ids2 = array(); |
|---|
| 135 | + $ids2_srcs = array(); |
|---|
| 136 | + foreach ( range( 4, 6 ) as $i ) { |
|---|
| 137 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 138 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 139 | + 'post_type' => 'attachment' |
|---|
| 140 | + ) ); |
|---|
| 141 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 142 | + $ids2[] = $attachment_id; |
|---|
| 143 | + $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 144 | + } |
|---|
| 145 | + |
|---|
| 146 | + $ids1_joined = join( ',', $ids1 ); |
|---|
| 147 | + $ids2_joined = join( ',', $ids2 ); |
|---|
| 148 | + |
|---|
| 149 | + $blob =<<<BLOB |
|---|
| 150 | +[gallery ids="$ids1_joined"] |
|---|
| 151 | + |
|---|
| 152 | +[gallery ids="$ids2_joined"] |
|---|
| 153 | +BLOB; |
|---|
| 154 | + $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
|---|
| 155 | + $srcs = get_post_galleries_images( $post_id ); |
|---|
| 156 | + $this->assertEquals( $srcs, array( $ids1_srcs, $ids2_srcs ) ); |
|---|
| 157 | + } |
|---|
| 158 | + |
|---|
| 159 | + /** |
|---|
| 160 | + * @ticket 22960 |
|---|
| 161 | + */ |
|---|
| 162 | + function test_post_gallery_images() { |
|---|
| 163 | + $ids1 = array(); |
|---|
| 164 | + $ids1_srcs = array(); |
|---|
| 165 | + foreach ( range( 1, 3 ) as $i ) { |
|---|
| 166 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 167 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 168 | + 'post_type' => 'attachment' |
|---|
| 169 | + ) ); |
|---|
| 170 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 171 | + $ids1[] = $attachment_id; |
|---|
| 172 | + $ids1_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 173 | + } |
|---|
| 174 | + |
|---|
| 175 | + $ids2 = array(); |
|---|
| 176 | + $ids2_srcs = array(); |
|---|
| 177 | + foreach ( range( 4, 6 ) as $i ) { |
|---|
| 178 | + $attachment_id = $this->factory->attachment->create_object( "image$i.jpg", 0, array( |
|---|
| 179 | + 'post_mime_type' => 'image/jpeg', |
|---|
| 180 | + 'post_type' => 'attachment' |
|---|
| 181 | + ) ); |
|---|
| 182 | + wp_update_attachment_metadata( $attachment_id, $this->img_dimensions ); |
|---|
| 183 | + $ids2[] = $attachment_id; |
|---|
| 184 | + $ids2_srcs[] = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . "image$i.jpg"; |
|---|
| 185 | + } |
|---|
| 186 | + |
|---|
| 187 | + $ids1_joined = join( ',', $ids1 ); |
|---|
| 188 | + $ids2_joined = join( ',', $ids2 ); |
|---|
| 189 | + |
|---|
| 190 | + $blob =<<<BLOB |
|---|
| 191 | +[gallery ids="$ids1_joined"] |
|---|
| 192 | + |
|---|
| 193 | +[gallery ids="$ids2_joined"] |
|---|
| 194 | +BLOB; |
|---|
| 195 | + $post_id = $this->factory->post->create( array( 'post_content' => $blob ) ); |
|---|
| 196 | + $srcs = get_post_gallery_images( $post_id ); |
|---|
| 197 | + $this->assertEquals( $srcs, $ids1_srcs ); |
|---|
| 198 | + } |
|---|
| 199 | } |
|---|