Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test for ensuring that attachment meta data is set. #198

Merged
merged 6 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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