diff --git a/safe-svg.php b/safe-svg.php index 326399a..548d869 100644 --- a/safe-svg.php +++ b/safe-svg.php @@ -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' ) ); @@ -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() ) { diff --git a/tests/cypress/e2e/safe-svg.cy.js b/tests/cypress/e2e/safe-svg.cy.js index 9038d18..5e033b9 100644 --- a/tests/cypress/e2e/safe-svg.cy.js +++ b/tests/cypress/e2e/safe-svg.cy.js @@ -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' ); + } ); } ); /** @@ -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) @@ -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) @@ -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'); }); });