-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed imagify pricing modal layout issue (#924)
- Loading branch information
Showing
7 changed files
with
265 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
if ( ! class_exists( 'GFCommon' ) ) { | ||
class GFForms{ | ||
public static function is_gravity_page() { | ||
return true; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Tests/Fixtures/classes/ThirdParty/Plugins/gravityForms.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
return [ | ||
'test_data' => [ | ||
'testShouldReturnStylesAndScriptWhenConflictModeIsOn' => [ | ||
'config' => [ | ||
'is_plugin_active' => true, | ||
'filter' => 'gform_noconflict_styles', | ||
], | ||
'expected' => [ | ||
'styles' => [ | ||
'imagify-admin-bar', | ||
'imagify-admin', | ||
'imagify-notices', | ||
'imagify-pricing-modal', | ||
], | ||
'scripts' => [ | ||
'imagify-admin-bar', | ||
'imagify-admin', | ||
'imagify-notices', | ||
'imagify-pricing-modal', | ||
'imagify-sweetalert', | ||
] | ||
], | ||
], | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ThirdParty\Plugins ; | ||
|
||
use Imagify\Tests\Unit\TestCase; | ||
use Imagify\ThirdParty\Plugins\GravityForms; | ||
use Mockery; | ||
use GFForms; | ||
use Brain\Monkey\Functions; | ||
use Brain\Monkey; | ||
|
||
/** | ||
* Tests for \Imagify\ThirdParty\Plugins\GravityForms. | ||
* | ||
* @covers \Imagify\ThirdParty\Plugins\GravityForms::imagify_gf_noconflict_styles | ||
* @covers \Imagify\ThirdParty\Plugins\GravityForms::imagify_gf_noconflict_scripts | ||
* | ||
* @group ThirdParty | ||
*/ | ||
class Test_GravityForms extends TestCase{ | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnAsExpected( $config, $expected ) { | ||
Functions\when( 'is_plugin_active' )->justReturn( $config[ 'is_plugin_active' ] ); | ||
Functions\when( 'get_option' )->justReturn( $config[ 'is_plugin_active' ] ); | ||
|
||
$gf_forms = Mockery::mock('overload:' . GFForms::class); | ||
$gf_forms->expects()->is_gravity_page()->andReturn( $config[ 'is_plugin_active' ] ); | ||
|
||
$gravity_forms = new GravityForms(); | ||
|
||
$styles = apply_filters( 'gform_noconflict_styles', [] ); | ||
$styles = $gravity_forms->imagify_gf_noconflict_styles( $styles ); | ||
foreach ( $expected['styles'] as $style ) { | ||
$this->assertContains( $style, $styles ); | ||
} | ||
|
||
$scripts = apply_filters( 'gform_noconflict_scripts', [] ); | ||
$scripts = $gravity_forms->imagify_gf_noconflict_scripts( $scripts ); | ||
foreach ( $expected['scripts'] as $script ) { | ||
$this->assertContains( $script, $scripts); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Imagify\ThirdParty\Plugins; | ||
|
||
use GFForms; | ||
use Imagify\EventManagement\SubscriberInterface; | ||
|
||
/** | ||
* Subscriber for compatibility with GravityForms | ||
*/ | ||
class GravityForms implements SubscriberInterface { | ||
/** | ||
* Returns an array of events that this subscriber wants to listen to. | ||
* | ||
* @return array | ||
*/ | ||
public static function get_subscribed_events(): array { | ||
if ( ! class_exists( 'GFCommon' ) ) { | ||
return []; | ||
} | ||
|
||
return [ | ||
'gform_noconflict_styles' => 'imagify_gf_noconflict_styles', | ||
'gform_noconflict_scripts' => 'imagify_gf_noconflict_scripts', | ||
]; | ||
} | ||
|
||
/** | ||
* Register imagify styles to gravity forms conflict styles | ||
* | ||
* @param array $styles Array fo registered styles. | ||
* | ||
* @return array | ||
*/ | ||
public function imagify_gf_noconflict_styles( $styles ): array { | ||
if ( ! $this->is_gravity_forms_no_conflict_mode_enabled() ) { | ||
return $styles; | ||
} | ||
|
||
$styles[] = 'imagify-admin-bar'; | ||
$styles[] = 'imagify-admin'; | ||
$styles[] = 'imagify-notices'; | ||
$styles[] = 'imagify-pricing-modal'; | ||
|
||
return $styles; | ||
} | ||
|
||
/** | ||
* Register Imagify scripts to gravity forms conflict scripts | ||
* | ||
* @param array $scripts Array fo registered scripts. | ||
* | ||
* @return array | ||
*/ | ||
public function imagify_gf_noconflict_scripts( $scripts ): array { | ||
if ( ! $this->is_gravity_forms_no_conflict_mode_enabled() ) { | ||
return $scripts; | ||
} | ||
|
||
$scripts[] = 'imagify-admin-bar'; | ||
$scripts[] = 'imagify-sweetalert'; | ||
$scripts[] = 'imagify-admin'; | ||
$scripts[] = 'imagify-notices'; | ||
$scripts[] = 'imagify-pricing-modal'; | ||
|
||
return $scripts; | ||
} | ||
|
||
/** | ||
* Check if gravity form is active and no_conflict mode is enabled. | ||
* | ||
* @return bool | ||
*/ | ||
private function is_gravity_forms_no_conflict_mode_enabled(): bool { | ||
return (bool) get_option( 'gform_enable_noconflict', false ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Imagify\ThirdParty; | ||
|
||
use Imagify\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider; | ||
use Imagify\ThirdParty\Plugins\GravityForms; | ||
|
||
/** | ||
* Service provider for Third Party(Plugins, Themes, Hosting). | ||
*/ | ||
class ServiceProvider extends AbstractServiceProvider { | ||
/** | ||
* Services provided by this provider | ||
* | ||
* @var array | ||
*/ | ||
protected $provides = [ | ||
'gravity_from_subscriber', | ||
]; | ||
|
||
/** | ||
* Subscribers provided by this provider | ||
* | ||
* @var array | ||
*/ | ||
public $subscribers = [ | ||
'gravity_from_subscriber', | ||
]; | ||
|
||
/** | ||
* Check if the service provider provides a specific service. | ||
* | ||
* @param string $id The id of the service. | ||
* | ||
* @return bool | ||
*/ | ||
public function provides( string $id ): bool { | ||
return in_array( $id, $this->provides, true ); | ||
} | ||
|
||
/** | ||
* Returns the subscribers array | ||
* | ||
* @return array | ||
*/ | ||
public function get_subscribers() { | ||
return $this->subscribers; | ||
} | ||
|
||
/** | ||
* Registers the provided classes | ||
* | ||
* @return void | ||
*/ | ||
public function register(): void { | ||
$this->getContainer()->addShared( 'gravity_from_subscriber', GravityForms::class ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters