Skip to content

Commit

Permalink
wp-graphql#156 Moving testCreateMediaItemDefaultValues to fix merge c…
Browse files Browse the repository at this point in the history
…onflict.
  • Loading branch information
hughdevore committed Oct 5, 2017
1 parent 9126dcc commit 1bbeaf6
Showing 1 changed file with 84 additions and 84 deletions.
168 changes: 84 additions & 84 deletions tests/test-media-item-mutations.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,90 @@ public function testCreateMediaItemEditOthersPosts() {
$this->create_variables['input']['parentId'] = $this->parentId;
}

/**
* This function tests the createMediaItem mutation
*
* @source wp-content/plugins/wp-graphql/src/Type/MediaItem/Mutation/MediaItemCreate.php
* @access public
* @return void
*/
public function testCreateMediaItemMutation() {

/**
* Set the current user as the admin role so we
* can properly test the mutation
*/
wp_set_current_user( $this->admin );

/**
* Create the createMediaItem
*/
$actual = $this->createMediaItemMutation();

$media_item_id = $actual["data"]["createMediaItem"]["mediaItem"]["id"];
$attachment_id = $actual["data"]["createMediaItem"]["mediaItem"]["mediaItemId"];
$attachment_url = wp_get_attachment_url( $attachment_id );
$attachment_file = str_replace( '/tmp/wordpress//wp-content/uploads/', '', get_attached_file( $attachment_id ) );
$attachment_details = wp_get_attachment_metadata( $attachment_id );

$expected = [
'data' => [
'createMediaItem' => [
'clientMutationId' => $this->clientMutationId,
'mediaItem' => [
'id' => $media_item_id,
'mediaItemId' => $attachment_id,
'title' => $this->title,
'description' => apply_filters( 'the_content', $this->description ),
'altText' => $this->altText,
'caption' => apply_filters( 'the_content', $this->caption ),
'commentStatus' => $this->commentStatus,
'date' => $this->date,
'dateGmt' => $this->dateGmt,
'slug' => $this->slug,
'status' => strtolower( $this->status ),
'pingStatus' => $this->pingStatus,
'mimeType' => 'image/gif',
'parent' => null,
'mediaType' => 'image',
'sourceUrl' => $attachment_url,
'mediaDetails' => [
'file' => $attachment_file,
'height' => $attachment_details['height'],
'meta' => [
'aperture' => 0.0,
'credit' => '',
'camera' => '',
'caption' => '',
'createdTimestamp' => null,
'copyright' => '',
'focalLength' => null,
'iso' => 0,
'shutterSpeed' => null,
'title' => '',
'orientation' => '0',
],
'width' => $attachment_details['width'],
'sizes' => [
0 => [
'name' => 'thumbnail',
'file' => $attachment_details['sizes']['thumbnail']['file'],
'width' => (int) $attachment_details['sizes']['thumbnail']['width'],
'height' => (int) $attachment_details['sizes']['thumbnail']['height'],
'mimeType' => $attachment_details['sizes']['thumbnail']['mime-type'],
'sourceUrl' => basename( wp_get_attachment_thumb_url( $attachment_id ) ),
],
],
],
],
],
],
];

$this->assertEquals( $expected, $actual );

}

/**
* Test the MediaItemMutation by setting the default values:
*
Expand Down Expand Up @@ -677,90 +761,6 @@ public function testCreateMediaItemDefaultValues() {

}

/**
* This function tests the createMediaItem mutation
*
* @source wp-content/plugins/wp-graphql/src/Type/MediaItem/Mutation/MediaItemCreate.php
* @access public
* @return void
*/
public function testCreateMediaItemMutation() {

/**
* Set the current user as the admin role so we
* can properly test the mutation
*/
wp_set_current_user( $this->admin );

/**
* Create the createMediaItem
*/
$actual = $this->createMediaItemMutation();

$media_item_id = $actual["data"]["createMediaItem"]["mediaItem"]["id"];
$attachment_id = $actual["data"]["createMediaItem"]["mediaItem"]["mediaItemId"];
$attachment_url = wp_get_attachment_url( $attachment_id );
$attachment_file = str_replace( '/tmp/wordpress//wp-content/uploads/', '', get_attached_file( $attachment_id ) );
$attachment_details = wp_get_attachment_metadata( $attachment_id );

$expected = [
'data' => [
'createMediaItem' => [
'clientMutationId' => $this->clientMutationId,
'mediaItem' => [
'id' => $media_item_id,
'mediaItemId' => $attachment_id,
'title' => $this->title,
'description' => apply_filters( 'the_content', $this->description ),
'altText' => $this->altText,
'caption' => apply_filters( 'the_content', $this->caption ),
'commentStatus' => $this->commentStatus,
'date' => $this->date,
'dateGmt' => $this->dateGmt,
'slug' => $this->slug,
'status' => strtolower( $this->status ),
'pingStatus' => $this->pingStatus,
'mimeType' => 'image/gif',
'parent' => null,
'mediaType' => 'image',
'sourceUrl' => $attachment_url,
'mediaDetails' => [
'file' => $attachment_file,
'height' => $attachment_details['height'],
'meta' => [
'aperture' => 0.0,
'credit' => '',
'camera' => '',
'caption' => '',
'createdTimestamp' => null,
'copyright' => '',
'focalLength' => null,
'iso' => 0,
'shutterSpeed' => null,
'title' => '',
'orientation' => '0',
],
'width' => $attachment_details['width'],
'sizes' => [
0 => [
'name' => 'thumbnail',
'file' => $attachment_details['sizes']['thumbnail']['file'],
'width' => (int) $attachment_details['sizes']['thumbnail']['width'],
'height' => (int) $attachment_details['sizes']['thumbnail']['height'],
'mimeType' => $attachment_details['sizes']['thumbnail']['mime-type'],
'sourceUrl' => basename( wp_get_attachment_thumb_url( $attachment_id ) ),
],
],
],
],
],
],
];

$this->assertEquals( $expected, $actual );

}

/**
* This function tests the updateMediaItem mutation
* and is reused throughout the updateMediaItem tests
Expand Down

0 comments on commit 1bbeaf6

Please sign in to comment.