Skip to content

Commit

Permalink
fix: compatibility with shortcode ultimate, adds more usecases to test
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Jun 25, 2019
1 parent 58d83b0 commit c6673eb
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ logs
dist
artifact
cypress/videos
cypress/fixtures
vendor
code_quality
build
Expand Down
19 changes: 19 additions & 0 deletions cypress/integration/test_gutenberg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe( 'Check gutenberg page', function () {
it( 'successfully loads', function () {
cy.visit( '/gutenberg' )
} );
it( 'Gutenberg images should have replaced srcs', function () {
cy.get( '.wp-block-image > img' ).should( 'have.attr', 'src' ).and( 'include', 'i.optimole.com' );
} );
it( 'Gutenberg images should data-opt-src attribute', function () {
cy.get( '.wp-block-image > img' ).should( 'have.attr', 'data-opt-src' ).and( 'include', 'i.optimole.com' );
} );
it( 'Gutenberg images should have no script tag', function () {
cy.get( '.wp-block-image > noscript' ).should( 'exist' );
cy.get( '.wp-block-image > noscript' ).should( 'contain', 'img' ).should( 'contain', 'i.optimole.com' )
} );

it( 'Gutenberg block cover background image should be properly replaced', function () {
cy.get( '.wp-block-cover ' ).should( 'have.css','background-image' ).and( 'include', 'i.optimole.com' );
} );
} );
14 changes: 14 additions & 0 deletions cypress/integration/test_su.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe( 'Check Shortcode ultimate page', function () {
it( 'successfully loads', function () {
cy.visit( '/blog/test/' )
} );
it( 'Carousel should have proper resize type', function () {
cy.get( '.su-carousel-slide img' ).should( 'have.attr', 'data-opt-src' ).and( 'include', 'i.optimole.com' ).and( 'include', 'rt:fill' );
} );
it( 'Slider should have proper resize type', function () {
cy.get( '.su-slider img' ).should( 'have.attr', 'data-opt-src' ).and( 'include', 'i.optimole.com' ).and( 'include', 'rt:fill' );
} );
it( 'Gallery should have proper resize type', function () {
cy.get( '.su-custom-gallery img' ).should( 'have.attr', 'data-opt-src' ).and( 'include', 'i.optimole.com' ).and( 'include', 'rt:fill' );
} );
} );
31 changes: 31 additions & 0 deletions cypress/integration/test_woo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe( 'Check product page', function () {
it( 'successfully loads', function () {
cy.visit( '/product/test-product/' )
} );
it( 'Gallery wrapper should have proper data-thumb', function () {
cy.get( '.woocommerce-product-gallery__wrapper > div' ).should( 'have.attr', 'data-thumb' ).and( 'include', 'i.optimole.com' );
} );
it( 'Gallery wrapper link should have auto sizes', function () {
cy.get( '.woocommerce-product-gallery__wrapper > div > a' ).should( 'have.attr', 'href' ).and( 'include', 'i.optimole.com' ).and( 'include', 'w:auto/h:auto' );
} );
it( 'Gallery wrapper image from link should have proper images', function () {
cy.get( '.woocommerce-product-gallery__wrapper > div > a > img' ).should( 'have.attr', 'src' ).and( 'include', 'i.optimole.com' );
cy.get( '.woocommerce-product-gallery__wrapper > div > a > img' ).should( 'have.attr', 'data-src' ).and( 'include', 'i.optimole.com' );
cy.get( '.woocommerce-product-gallery__wrapper > div > a > img' ).should( 'have.attr', 'data-large_image' ).and( 'include', 'i.optimole.com' );
} );
it( 'Zoom img should have auto size', function () {
cy.get( '.woocommerce-product-gallery__wrapper .zoomImg' ).should( 'have.attr', 'src' ).and( 'include', 'i.optimole.com' ).and( 'include', 'w:auto/h:auto' );
} );
it( 'All images should have proper tags', function () {
cy.get( 'img' ).should( 'have.attr', 'src' ).and( 'include', 'i.optimole.com' );
} );
} );
describe( 'Test quick view', function () {
it( 'successfully loads', function () {
cy.visit( '/shop' )
cy.get( '.yith-wcqv-button:first' ).click();
} );
it( 'Quick view have optimole images', function () {
cy.get( '#yith-quick-view-content .woocommerce-product-gallery__wrapper img' ).should( 'have.attr', 'src' ).and( 'include', 'i.optimole.com' );
} );
} );
2 changes: 2 additions & 0 deletions inc/compatibilities/shortcode_ultimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ function alter_shortcode_output( $output, $tag, $attr ) {
}

add_filter( 'optml_default_crop', [ $this, 'change_default_crop' ] );
add_filter( 'optml_parse_resize_from_tag', [ $this, 'change_default_crop' ] );

$output = Optml_Main::instance()->manager->process_images_from_content( $output );

remove_filter( 'optml_default_crop', [ $this, 'change_default_crop' ] );
remove_filter( 'optml_parse_resize_from_tag', [ $this, 'change_default_crop' ] );

return $output;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/tag_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function process_image_tags( $content, $images = array() ) {
}
if ( empty( $resize ) && isset( $sizes2crop[ $width . $height ] ) ) {
$resize = $this->to_optml_crop( $sizes2crop[ $width . $height ] );
} elseif ( $crop !== null ) {
} elseif ( $crop === true ) {
$resize = $this->to_optml_crop( $crop );
}

Expand Down

0 comments on commit c6673eb

Please sign in to comment.