-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
432 additions
and
62 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,17 @@ | ||
describe( 'Sassy Social Share', function () { | ||
it( 'successfully loads', function () { | ||
cy.visit( '/sassy-social-share/' ) | ||
} ); | ||
it( 'click on button', function () { | ||
cy.get( '.heateorSssSharing.heateorSssPinterestBackground' ).click( { multiple: true } ) | ||
} ); | ||
it( 'images should not have quality:eco', function () { | ||
cy.get( 'img' ).should( ( $imgs ) => { | ||
expect( $imgs ).to.have.length( 5 ) | ||
expect( $imgs.eq( 0 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' ) | ||
expect( $imgs.eq( 1 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' ) | ||
expect( $imgs.eq( 2 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' ) | ||
expect( $imgs.eq( 3 ) ).to.have.attr( 'src' ).and.to.not.contain( 'eco' ) | ||
} ); | ||
} ); | ||
} ); |
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
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,48 @@ | ||
<?php | ||
|
||
/** | ||
* CLI class. | ||
* | ||
* Author: Bogdan Preda <[email protected]> | ||
* Created on: 19/07/2018 | ||
* | ||
* @package \Optimole\Inc | ||
* @author Optimole <[email protected]> | ||
*/ | ||
|
||
/** | ||
* Class Optml_Cli | ||
*/ | ||
class Optml_Cli { | ||
|
||
/** | ||
* Api version. | ||
* | ||
* @var string Version string. | ||
*/ | ||
const CLI_NAMESPACE = 'optimole'; | ||
|
||
/** | ||
* CLI controllers | ||
* | ||
* @var array List of CLI controllers. | ||
*/ | ||
private $commands = array( | ||
'setting', | ||
); | ||
|
||
/** | ||
* Optml_Cli constructor. | ||
*/ | ||
public function __construct() { | ||
foreach ( $this->commands as $command ) { | ||
$class_name = 'Optml_Cli_' . ucfirst( $command ); | ||
$controller = new $class_name(); | ||
try { | ||
\WP_CLI::add_command( self::CLI_NAMESPACE . ' ' . $command, $controller ); | ||
} catch ( \Exception $e ) { | ||
// TODO Log this exception. | ||
} | ||
} | ||
} | ||
} |
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,144 @@ | ||
<?php | ||
/** | ||
* CLI commands responsible for the Optimole settings. | ||
*/ | ||
|
||
if ( ! class_exists( 'WP_CLI' ) ) { | ||
return; | ||
} | ||
|
||
/** | ||
* Class Optml_Cli_Setting | ||
*/ | ||
class Optml_Cli_Setting extends WP_CLI_Command { | ||
/** | ||
* Holds an array of possible settings to alter. | ||
* | ||
* @var array Whitelisted settings. | ||
*/ | ||
public static $whitelisted_settings = [ | ||
'image_replacer' => 'bool', | ||
'quality' => 'int', | ||
'lazyload' => 'bool', | ||
'lazyload_placeholder' => 'bool', | ||
]; | ||
|
||
/** | ||
* Connect to service | ||
* <apikey> | ||
* : The api key to use. | ||
*/ | ||
public function connect( $args ) { | ||
if ( empty( $args ) || ! isset( $args[0] ) || $args[0] === '' ) { | ||
return \WP_CLI::error( 'No argument passed. Required one argument ( api key )' ); | ||
} | ||
|
||
if ( sizeof( $args ) > 1 ) { | ||
return \WP_CLI::error( 'To many arguments passed' ); | ||
} | ||
|
||
$api_key = $args[0]; | ||
|
||
$request = new Optml_Api(); | ||
$data = $request->get_user_data( $api_key ); | ||
if ( $data === false || is_wp_error( $data ) ) { | ||
$extra = ''; | ||
if ( is_wp_error( $data ) ) { | ||
/** | ||
* Error from api. | ||
* | ||
* @var WP_Error $data Error object. | ||
*/ | ||
$extra = sprintf( __( '. ERROR details: %s', 'optimole-wp' ), $data->get_error_message() ); | ||
} | ||
|
||
return \WP_CLI::error( __( 'Can not connect to Optimole service', 'optimole-wp' ) . $extra ); | ||
} | ||
$settings = new Optml_Settings(); | ||
$settings->update( 'service_data', $data ); | ||
$settings->update( 'api_key', $api_key ); | ||
|
||
\WP_CLI::success( sprintf( 'Connected API key %s to Optimole Service', $args[0] ) ); | ||
} | ||
|
||
/** | ||
* Disconnect from service. | ||
*/ | ||
public function disconnect() { | ||
$settings = new Optml_Settings(); | ||
$settings->reset(); | ||
\WP_CLI::success( 'Disconnected from Optimole Service' ); | ||
} | ||
|
||
/** | ||
* Update settings. | ||
* | ||
* <setting_name> | ||
* : The setting name to update. | ||
* | ||
* <setting_value> | ||
* : The setting value to update. | ||
*/ | ||
public function update( $args ) { | ||
if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) { | ||
\WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) ); | ||
|
||
return false; | ||
} | ||
|
||
if ( self::$whitelisted_settings[ $args[0] ] === 'bool' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || ! in_array( | ||
$args[1], | ||
array( | ||
'on', | ||
'off', | ||
) | ||
) ) ) { | ||
return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' ); | ||
} | ||
|
||
if ( self::$whitelisted_settings[ $args[0] ] === 'int' && ( empty( $args ) || ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) { | ||
return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' ); | ||
} | ||
|
||
$value = ( self::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1]; | ||
|
||
$new_value = $this->update_setting( array( $args[0] => $value ) ); | ||
\WP_CLI::success( sprintf( 'Setting %s updated to: %s', $args[0], $new_value[ $args[0] ] ) ); | ||
} | ||
|
||
/** | ||
* Check settings. | ||
* | ||
* <setting_name> | ||
* : The setting name to check. | ||
*/ | ||
public function get( $args ) { | ||
if ( empty( $args ) || ! isset( self::$whitelisted_settings[ $args[0] ] ) ) { | ||
\WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( self::$whitelisted_settings ) ) ) ); | ||
|
||
return false; | ||
} | ||
|
||
$value = ( new Optml_Settings() )->get( $args[0] ); | ||
|
||
\WP_CLI::success( sprintf( 'Setting %s is set to: %s', $args[0], $value ) ); | ||
} | ||
|
||
|
||
/** | ||
* Utility method to update setting | ||
* | ||
* @param mixed $new_setting The setting to parse. | ||
* | ||
* @return array | ||
*/ | ||
private function update_setting( $new_setting ) { | ||
if ( empty( $new_setting ) ) { | ||
\WP_CLI::error( __( 'No setting to update', 'optimole-wp' ) ); | ||
} | ||
$settings = new Optml_Settings(); | ||
|
||
return $settings->parse_settings( $new_setting ); | ||
} | ||
|
||
} |
Oops, something went wrong.