Skip to content

Commit

Permalink
fix: background image replacement url
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoreMihai committed Aug 28, 2019
1 parent aaf2815 commit d176c11
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public function process_urls_from_content( $html ) {
* @return array
*/
public function extract_image_urls_from_content( $content ) {
$regex = '/(?:http(?:s?):)(?:[\/\\\\|.|\w|\s|-])*\.(?:' . implode( '|', array_keys( Optml_Config::$extensions ) ) . ')(?:\?{1}[\w|=|&|\-|\.|:|;]*)?/';
$regex = '/((?:http(?:s?):)(?:[\/\\\\|.|\w|\s|-])*\.(?:' . implode( '|', array_keys( Optml_Config::$extensions ) ) . ')(?:\?{1}[\w|=|&|\-|\.|:|;]*)?)|((?:[\/\\\\|.|\w|\s|-])*\.(?:' . implode( '|', array_keys( Optml_Config::$extensions ) ) . ')(?:\?{1}[\w|=|&|\-|\.|:|;]*)?)/';
preg_match_all(
$regex,
$content,
Expand Down
51 changes: 51 additions & 0 deletions tests/test-background-image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* WordPress unit test plugin.
*
* @package Optimole-WP
* @subpackage Tests
* @copyright Copyright (c) 2017, ThemeIsle
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
class Test_Background_Image extends WP_UnitTestCase
{

const IMG_TAGS_GIF = '<div data-hash="5c2602bbe76e6f966a846fb661b9d76d" data-desktop="//366b4e08.ngrok.io/wp-content/uploads/2019/08/image3-10-5.jpg" class="n2-ss-slide-background-image" data-blur="0" style="background-image:url("//example.org/wp-content/themes/test/assets/images/header-300x300.png");"> </div>';


public static $sample_post;

public function setUp()
{

parent::setUp();
$settings = new Optml_Settings();
$settings->update('service_data', [
'cdn_key' => 'test123',
'cdn_secret' => '12345',
'whitelist' => ['example.com'],

]);
$settings->update('lazyload', 'disabled');
$settings->update('img_to_video', 'enabled');


Optml_Url_Replacer::instance()->init();
Optml_Tag_Replacer::instance()->init();
Optml_Manager::instance()->init();

self::$sample_post = self::factory()->post->create([
'post_title' => 'Test post',
'post_content' => self::IMG_TAGS_GIF
]
);
}

public function test_should_replace_tag()
{

$replaced_content = Optml_Manager::instance()->replace_content(self::IMG_TAGS_GIF);
$this->assertContains('i.optimole.com', $replaced_content);
}
}

1 comment on commit d176c11

@GrigoreMihai
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@preda-bogdan this is the fix for schema-less

Please sign in to comment.