/** * @see Envato_Market_Items::rebuild_plugins() */ function test_rebuild_plugins() { $plugins = array('purchased' => array(array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'active' => array(), 'installed' => array('envato-market/envato-market.php' => array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'install' => array()); $expected = array('purchased' => array(array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'active' => array('envato-market/envato-market.php' => array('id' => 12345, 'name' => 'Envato Market', 'author' => 'Derek Herman', 'version' => '10.0.0', 'description' => '', 'url' => 'http://sample.org/custom/', 'author_url' => 'http://sample.org/', 'thumbnail_url' => 'http://sample.org/thumb.png', 'landscape_url' => 'http://sample.org/landscape.png', 'requires' => '4.2', 'tested' => '4.4', 'number_of_sales' => 25000, 'updated_at' => '', 'rating' => array('rating' => 4.79, 'count' => 4457))), 'installed' => array(), 'install' => array()); set_site_transient(envato_market()->get_option_name() . '_plugins', $plugins); $ref = new ReflectionProperty('Envato_Market_Items', 'plugins'); $ref->setAccessible(true); $ref->setValue(null, $plugins); $this->assertEquals($plugins, $this->items->plugins()); $this->items->rebuild_plugins('envato-market/envato-market.php'); $this->assertEquals($expected, $this->items->plugins()); global $wp_current_filter; $wp_current_filter[] = 'deactivated_plugin'; $this->items->rebuild_plugins('envato-market/envato-market.php'); $this->assertEquals($plugins, $this->items->plugins()); $ref = new ReflectionProperty('Envato_Market_Items', 'plugins'); $ref->setAccessible(true); $ref->setValue(null, array()); }
/** * Set the list of plugins * * @since 1.0.0 * * @param bool $forced Forces an API request. Default is 'false'. * @param bool $use_cache Attempts to rebuild from the cache before making an API request. * @param array $args Used to remove or add a plugin during activate and deactivate routines. */ public function set_plugins($forced = false, $use_cache = false, $args = array()) { self::$plugins = get_site_transient(envato_market()->get_option_name() . '_plugins'); if (false === self::$plugins || true === $forced) { $plugins = envato_market()->api()->plugins(); foreach (envato_market()->get_option('items', array()) as $item) { if (empty($item)) { continue; } if ('plugin' === $item['type']) { $request_args = array('headers' => array('Authorization' => 'Bearer ' . $item['token'])); $request = envato_market()->api()->item($item['id'], $request_args); if (false !== $request) { $plugins[] = $request; } } } self::process_plugins($plugins, $args); } elseif (true === $use_cache) { self::process_plugins(self::$plugins['purchased'], $args); } }