Skip to content

Commit

Permalink
Merge pull request #198 from 10up/feature/add-visual-tests-for-uploads
Browse files Browse the repository at this point in the history
Adds test for ensuring that attachment meta data is set.
  • Loading branch information
helen authored Mar 6, 2020
2 parents 37f8a9d + 237798e commit 26f18a3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
12 changes: 4 additions & 8 deletions tests/Classifai/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

namespace Classifai;

/**
* @group helpers
*/
class HelpersTest extends \WP_UnitTestCase {

function setUp() {
parent::setUp();
$this->remove_added_uploads();
}

/**
* Tear down method.
*/
public function tearDown() {
parent::tearDown();

$this->remove_added_uploads();
parent::tearDown();
}

function test_it_has_a_plugin_instance() {
Expand Down
24 changes: 22 additions & 2 deletions tests/Classifai/Providers/Azure/ComputerVisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class ComputerVisionTest extends WP_UnitTestCase {
* Tear down method.
*/
public function tearDown() {
parent::tearDown();

$this->remove_added_uploads();
parent::tearDown();
}

/**
Expand Down Expand Up @@ -79,4 +78,25 @@ public function test_smart_crop_image() {

remove_filter( 'classifai_should_smart_crop_image', '__return_true' );
}

/**
* Ensure that attachment meta is being set.
*/
public function test_set_image_meta_data() {
// Create A settings object
$settings = [
'enable_image_tagging' => 'no',
'enable_image_captions' => 'no'
];
// Add the settings.
add_option( 'classifai_computer_vision', $settings );

// Instantiate the hooks
$this->get_computer_vision()->register();

$attachment = $this->factory->attachment->create_and_get();
wp_generate_attachment_metadata( $attachment->ID, DIR_TESTDATA .'/images/33772.jpg' );
$meta = wp_get_attachment_metadata( $attachment->ID );
$this->assertNotFalse( $meta );
}
}
17 changes: 12 additions & 5 deletions tests/Classifai/Providers/Azure/SmartCroppingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ public function test_get_cropped_thumbnail() {
);

$with_filter_cb = function() use ( $attachment ) {

// Get the uploaded image url
$cropped_thumbnail_url = $this->get_smart_cropping()->get_cropped_thumbnail(
$attachment,
wp_get_attachment_metadata( $attachment )['sizes']['thumbnail']
);
// Strip out everything before /wp-content/ because it won't match.
$prepped_url = substr( $cropped_thumbnail_url, strpos( $cropped_thumbnail_url , '/wp-content/' ) );


$this->assertEquals(
sprintf( '/tmp/wordpress/wp-content/uploads/%s/%s/33772-150x150.jpg', date( 'Y' ), date( 'm' ) ),
$this->get_smart_cropping()->get_cropped_thumbnail(
$attachment,
wp_get_attachment_metadata( $attachment )['sizes']['thumbnail']
)
sprintf( '/wp-content/uploads/%s/%s/33772-150x150.jpg', date( 'Y' ), date( 'm' ) ),
$prepped_url
);

// Test when file operations fail.
Expand Down

0 comments on commit 26f18a3

Please sign in to comment.