Skip to content

Commit

Permalink
Fix spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Dec 3, 2024
1 parent 74f6e48 commit fab05a2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function check_for_svg( $file ) {
return $file;
}

$file_name = isset( $file['name'] ) ? $file['name'] : '';
$file_name = isset( $file['name'] ) ? $file['name'] : '';

// Allow SVGs to be uploaded when this function runs.
add_filter( 'upload_mimes', array( $this, 'allow_svg' ) );
Expand All @@ -269,7 +269,7 @@ public function check_for_svg( $file ) {
// This is because wp_check_filetype_and_ext() is called multiple times during the upload process.
add_filter( 'pre_move_uploaded_file', array( $this, 'pre_move_uploaded_file' ) );

$type = ! empty( $wp_filetype['type'] ) ? $wp_filetype['type'] : '';
$type = ! empty( $wp_filetype['type'] ) ? $wp_filetype['type'] : '';

if ( 'image/svg+xml' === $type ) {
if ( ! $this->current_user_can_upload_svg() ) {
Expand Down
76 changes: 38 additions & 38 deletions tests/cypress/e2e/safe-svg.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ describe('Safe SVG Tests', () => {
});

it('Admin can add SVG block to a post', () => {
cy.uploadMedia('.wordpress-org/icon.svg');

cy.createPost( {
title: 'SVG Block Test',
beforeSave: () => {
cy.insertBlock( 'safe-svg/svg-icon' );
cy.getBlockEditor().find( '.block-editor-media-placeholder' ).contains( 'button', 'Media Library' ).click();
cy.get( '#menu-item-browse' ).click();
cy.get( '.attachments-wrapper li:first .thumbnail' ).click();
cy.get( '.media-modal .media-button-select' ).click();
},
} ).then( post => {
cy.visit( `/wp-admin/post.php?post=${post.id}&action=edit` );
cy.getBlockEditor().find( '.wp-block-safe-svg-svg-icon' );
} );
cy.uploadMedia('.wordpress-org/icon.svg');

cy.createPost( {
title: 'SVG Block Test',
beforeSave: () => {
cy.insertBlock( 'safe-svg/svg-icon' );
cy.getBlockEditor().find( '.block-editor-media-placeholder' ).contains( 'button', 'Media Library' ).click();
cy.get( '#menu-item-browse' ).click();
cy.get( '.attachments-wrapper li:first .thumbnail' ).click();
cy.get( '.media-modal .media-button-select' ).click();
},
} ).then( post => {
cy.visit( `/wp-admin/post.php?post=${post.id}&action=edit` );
cy.getBlockEditor().find( '.wp-block-safe-svg-svg-icon' );
} );
} );

/**
Expand All @@ -49,8 +49,8 @@ describe('Safe SVG Tests', () => {
// Test
cy.uploadMedia('tests/cypress/fixtures/custom.svg');
cy.get('#media-items .media-item a.edit-attachment').invoke('attr', 'href').then(editLink => {
cy.visit(editLink);
} );
cy.visit(editLink);
} );
cy.get('input#attachment_url').invoke('val')
.then(url => {
cy.request(url)
Expand All @@ -74,8 +74,8 @@ describe('Safe SVG Tests', () => {
cy.uploadMedia('tests/cypress/fixtures/custom.svg');

cy.get('#media-items .media-item a.edit-attachment').invoke('attr', 'href').then(editLink => {
cy.visit( editLink );
});
cy.visit( editLink );
});
cy.get('input#attachment_url').invoke('val')
.then(url => {
cy.request(url)
Expand Down Expand Up @@ -110,36 +110,36 @@ describe('Safe SVG Tests', () => {
// Activate test plugin.
cy.activatePlugin('safe-svg-cypress-test-plugin');

// Visit the home page.
// Visit the home page.
cy.visit('/');

// Verify that the SVG images are displayed with the correct dimensions.
cy.get('#thumbnail-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#medium-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#large-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#full-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#custom-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
// Verify that the SVG images are displayed with the correct dimensions.
cy.get('#thumbnail-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#medium-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#large-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#full-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('#custom-image').should('have.attr', 'width', '256').should('have.attr', 'height', '256');

// Deactivate the test plugin.
cy.deactivatePlugin('safe-svg-cypress-test-plugin');
// Deactivate the test plugin.
cy.deactivatePlugin('safe-svg-cypress-test-plugin');
});

it('Output of get_image_tag should use custom dimensions', () => {
// Activate test plugin.
cy.activatePlugin('safe-svg-cypress-test-plugin');

// Visit the home page.
// Visit the home page.
cy.visit('/');

// Verify that the SVG images are displayed with the correct dimensions.
// TODO: these are the sizes returned but seems they are not correct. get_image_tag_override needs to be fixed.
cy.get('.size-thumbnail.wp-image-6').should('have.attr', 'width', '150').should('have.attr', 'height', '150');
cy.get('.size-medium.wp-image-6').should('have.attr', 'width', '300').should('have.attr', 'height', '300');
cy.get('.size-large.wp-image-6').should('have.attr', 'width', '1024').should('have.attr', 'height', '1024');
cy.get('.size-full.wp-image-6').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('.size-100x120.wp-image-6').should('have.attr', 'width', '100').should('have.attr', 'height', '100');
// Verify that the SVG images are displayed with the correct dimensions.
// TODO: these are the sizes returned but seems they are not correct. get_image_tag_override needs to be fixed.
cy.get('.size-thumbnail.wp-image-6').should('have.attr', 'width', '150').should('have.attr', 'height', '150');
cy.get('.size-medium.wp-image-6').should('have.attr', 'width', '300').should('have.attr', 'height', '300');
cy.get('.size-large.wp-image-6').should('have.attr', 'width', '1024').should('have.attr', 'height', '1024');
cy.get('.size-full.wp-image-6').should('have.attr', 'width', '256').should('have.attr', 'height', '256');
cy.get('.size-100x120.wp-image-6').should('have.attr', 'width', '100').should('have.attr', 'height', '100');

// Deactivate the test plugin.
cy.deactivatePlugin('safe-svg-cypress-test-plugin');
// Deactivate the test plugin.
cy.deactivatePlugin('safe-svg-cypress-test-plugin');
});
});

0 comments on commit fab05a2

Please sign in to comment.