Skip to content

Commit

Permalink
Updated dev-lib bootstrap and phpunit config
Browse files Browse the repository at this point in the history
  • Loading branch information
dtbaker committed Feb 27, 2018
1 parent c271d26 commit 98b9ee0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 51 deletions.
3 changes: 3 additions & 0 deletions envato-market.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
/* Set constant path to the plugin directory. */
define( 'ENVATO_MARKET_SLUG', basename( plugin_dir_path( __FILE__ ) ) );

/* Set constant path to the main file for activation call */
define( 'ENVATO_MARKET_CORE_FILE', __FILE__ );

/* Set constant path to the plugin directory. */
define( 'ENVATO_MARKET_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );

Expand Down
2 changes: 1 addition & 1 deletion inc/admin/class-envato-market-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ public function render_templates() {
<div class="envato-card {{ data.type }}">
<div class="envato-card-top">
<a href="{{ data.url }}" class="column-icon">
<img src="{{ data.icon_url }}"/>
<img src="{{ data.thumbnail_url }}"/>
</a>
<div class="column-name">
<h4>
Expand Down
4 changes: 2 additions & 2 deletions inc/admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function envato_market_themes_column( $group = 'install' ) {
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<div class="envato-card-top">
<a href="<?php echo esc_url( $url ); ?>" class="column-icon">
<img src="<?php echo esc_url( $theme['icon_url'] ); ?>"/>
<img src="<?php echo esc_url( $theme['thumbnail_url'] ); ?>"/>
</a>
<div class="column-name">
<h4>
Expand Down Expand Up @@ -403,7 +403,7 @@ function envato_market_plugins_column( $group = 'install' ) {
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<div class="envato-card-top">
<a href="<?php echo esc_url( $url ); ?>" class="column-icon">
<img src="<?php echo esc_url( $plugin['icon_url'] ); ?>"/>
<img src="<?php echo esc_url( $plugin['thumbnail_url'] ); ?>"/>
</a>
<div class="column-name">
<h4>
Expand Down
17 changes: 8 additions & 9 deletions inc/class-envato-market-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,22 +273,22 @@ public function normalize_theme( $theme ) {
'author_url' => ( ! empty( $theme['author_url'] ) ? $theme['author_url'] : '' ),
'thumbnail_url' => ( ! empty( $theme['thumbnail_url'] ) ? $theme['thumbnail_url'] : '' ),
'rating' => ( ! empty( $theme['rating'] ) ? $theme['rating'] : '' ),
'icon_url' => '',
'landscape_url' => '',
);

// No main thumbnail in API response, so we grab it from the preview array.
if ( empty( $normalized_theme['thumbnail_url'] ) && ! empty( $theme['previews'] ) && is_array( $theme['previews'] ) ) {
foreach ( $theme['previews'] as $possible_preview ) {
if ( ! empty( $possible_preview['landscape_url'] ) ) {
$normalized_theme['thumbnail_url'] = $possible_preview['landscape_url'];
$normalized_theme['landscape_url'] = $possible_preview['landscape_url'];
break;
}
}
}
if ( empty( $normalized_theme['icon_url'] ) && ! empty( $theme['previews'] ) && is_array( $theme['previews'] ) ) {
if ( empty( $normalized_theme['thumbnail_url'] ) && ! empty( $theme['previews'] ) && is_array( $theme['previews'] ) ) {
foreach ( $theme['previews'] as $possible_preview ) {
if ( ! empty( $possible_preview['icon_url'] ) ) {
$normalized_theme['icon_url'] = $possible_preview['icon_url'];
$normalized_theme['thumbnail_url'] = $possible_preview['icon_url'];
break;
}
}
Expand Down Expand Up @@ -364,22 +364,21 @@ public function normalize_plugin( $plugin ) {
'number_of_sales' => ( ! empty( $plugin['number_of_sales'] ) ? $plugin['number_of_sales'] : '' ),
'updated_at' => ( ! empty( $plugin['updated_at'] ) ? $plugin['updated_at'] : '' ),
'rating' => ( ! empty( $plugin['rating'] ) ? $plugin['rating'] : '' ),
'icon_url' => '',
);

// No main thumbnail in API response, so we grab it from the preview array.
if ( empty( $plugin_normalized['thumbnail_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
if ( empty( $plugin_normalized['landscape_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
foreach ( $plugin['previews'] as $possible_preview ) {
if ( ! empty( $possible_preview['landscape_url'] ) ) {
$plugin_normalized['thumbnail_url'] = $possible_preview['landscape_url'];
$plugin_normalized['landscape_url'] = $possible_preview['landscape_url'];
break;
}
}
}
if ( empty( $plugin_normalized['icon_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
if ( empty( $plugin_normalized['thumbnail_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
foreach ( $plugin['previews'] as $possible_preview ) {
if ( ! empty( $possible_preview['icon_url'] ) ) {
$plugin_normalized['icon_url'] = $possible_preview['icon_url'];
$plugin_normalized['thumbnail_url'] = $possible_preview['icon_url'];
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions inc/class-envato-market.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ private function init_includes() {
*/
private function init_actions() {
// Activate plugin.
register_activation_hook( ENVATO_MARKET_PATH, array( $this, 'activate' ) );
register_activation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'activate' ) );

// Deactivate plugin.
register_deactivation_hook( ENVATO_MARKET_PATH, array( $this, 'deactivate' ) );
register_deactivation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'deactivate' ) );

// Load the textdomain.
add_action( 'init', array( $this, 'load_textdomain' ) );
Expand Down
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<phpunit
<phpunit
bootstrap="tests/phpunit/includes/bootstrap.php"
backupGlobals="false"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -23,8 +23,8 @@
<directory suffix=".php">tests</directory>
<directory suffix=".php">vendor</directory>
<directory suffix=".php">inc/admin/view</directory>
<file>inc/admin/upgrader-skins.php</file>
<file>inc/admin/upgrader.php</file>
<file>inc/admin/class-envato-market-theme-installer-skin.php</file>
<file>inc/admin/class-envato-market-theme-upgrader.php</file>
</exclude>
</whitelist>
</filter>
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/data/themes.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
{
"count":1,
"results":[
{
"results":[
{
"amount":"35.00",
"sold_at":"2011-04-03T19:34:35+10:00",
"item":{
Expand Down
60 changes: 30 additions & 30 deletions tests/phpunit/includes/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@
<?php

/**
* Bootstrap the WordPress unit testing environment.
*
* @package Archetype
* Determine if we should update the content and plugin paths.
*/
if ( ! defined( 'WP_CONTENT_DIR' ) && getenv( 'WP_CONTENT_DIR' ) ) {
define( 'WP_CONTENT_DIR', getenv( 'WP_CONTENT_DIR' ) );
}
if ( ! defined( 'WP_CONTENT_DIR' ) ) {
if ( file_exists( dirname( __DIR__ ) . '/wp-load.php' ) ) {
define( 'WP_CONTENT_DIR', dirname( __DIR__ ) . '/wp-content/' );
} else if ( file_exists( '../../../wp-content' ) ) {
define( 'WP_CONTENT_DIR', dirname( dirname( dirname( getcwd() ) ) ) . '/wp-content/' );
}
}

if ( defined( 'WP_CONTENT_DIR' ) && ! defined( 'WP_PLUGIN_DIR' ) ) {
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . 'plugins/' );
}

if ( file_exists( __DIR__ . '/../phpunit-plugin-bootstrap.project.php' ) ) {
require_once( __DIR__ . '/../phpunit-plugin-bootstrap.project.php' );
}

global $_plugin_file;

$_tests_dir = getenv( 'WP_TESTS_DIR' );

// Travis testing.
// Travis CI & Vagrant SSH tests directory.
if ( empty( $_tests_dir ) ) {
$_tests_dir = '/tmp/wordpress-tests-lib';
$_tests_dir = '/tmp/wordpress-tests';
}

// Command line testing in Core.
if ( ! file_exists( $_tests_dir . '/includes/' ) ) {
// Relative path to Core tests directory.
if ( ! is_dir( $_tests_dir . '/includes/' ) ) {
$_tests_dir = '../../../../tests/phpunit';
if ( ! file_exists( $_tests_dir . '/includes/' ) ) {
trigger_error( 'Unable to locate wordpress-tests-lib', E_USER_ERROR );
}
}

if ( ! is_dir( $_tests_dir . '/includes/' ) ) {
trigger_error( 'Unable to locate wordpress-tests-lib', E_USER_ERROR );
}
require_once $_tests_dir . '/includes/functions.php';

$_plugin_dir = str_replace( '/tests/phpunit', '', dirname( __DIR__ ) );
$_plugin_dir = getcwd();
foreach ( glob( $_plugin_dir . '/*.php' ) as $_plugin_file_candidate ) {
// @codingStandardsIgnoreStart
$_plugin_file_src = file_get_contents( $_plugin_file_candidate );
Expand All @@ -37,23 +54,6 @@
if ( ! isset( $_plugin_file ) ) {
trigger_error( 'Unable to locate a file containing a plugin metadata block.', E_USER_ERROR );
}

// Setup the token.
$_token = getenv( 'TOKEN' );
if ( empty( $_token ) ) {
$path = $_plugin_dir . '/.token';
if ( ! file_exists( $path ) ) {
$_token = '';
} else {
$_token = @file_get_contents( $path );
if ( false === $_token ) {
$_token = '';
}
}
}
define( 'TOKEN', $_token );
define( 'TESTS_DATA_DIR', dirname( __FILE__ ) . '/../data' );

unset( $_plugin_dir, $_plugin_file_candidate, $_plugin_file_src );

/**
Expand All @@ -69,12 +69,12 @@ function xwp_filter_active_plugins_for_phpunit( $active_plugins ) {
$forced_active_plugins = array();
if ( file_exists( WP_CONTENT_DIR . '/themes/vip/plugins/vip-init.php' ) && defined( 'WP_TEST_VIP_QUICKSTART_ACTIVATED_PLUGINS' ) ) {
$forced_active_plugins = preg_split( '/\s*,\s*/', WP_TEST_VIP_QUICKSTART_ACTIVATED_PLUGINS );
} elseif ( defined( 'WP_TEST_ACTIVATED_PLUGINS' ) ) {
} else if ( defined( 'WP_TEST_ACTIVATED_PLUGINS' ) ) {
$forced_active_plugins = preg_split( '/\s*,\s*/', WP_TEST_ACTIVATED_PLUGINS );
}
if ( ! empty( $forced_active_plugins ) ) {
foreach ( $forced_active_plugins as $forced_active_plugin ) {
$active_plugins[ "$forced_active_plugin" ] = time();
$active_plugins[] = $forced_active_plugin;
}
}
return $active_plugins;
Expand Down

0 comments on commit 98b9ee0

Please sign in to comment.