From 0d8d970cb6730dc0db2c014f57336e1b5d75b96e Mon Sep 17 00:00:00 2001 From: miya0001 Date: Mon, 6 Feb 2017 18:40:09 +0900 Subject: [PATCH] complianted to releases api --- lib/functions.php | 4 +++- tests/test-functions.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/functions.php b/lib/functions.php index 486ded6..0854f8c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -36,7 +36,9 @@ public static function get_latest_vccw_url() $api = "https://api.github.com/repos/vccw-team/vccw/releases/latest"; $body = json_decode( self::download( $api ) ); - if ( $body ) { + if ( ! empty( $body->assets[0] ) && ! empty( $body->assets[0]->browser_download_url ) ) { + return $body->assets[0]->browser_download_url; + } elseif ( $body ) { return $body->zipball_url; } } diff --git a/tests/test-functions.php b/tests/test-functions.php index 3106754..23e4f0a 100644 --- a/tests/test-functions.php +++ b/tests/test-functions.php @@ -2,6 +2,18 @@ class Scaffold_VCCW_Test extends WP_UnitTestCase { + /** + * Tests for the `Scaffold_VCCW::get_latest_vccw_url()`. + * + * @test + * @since 1.3.0 + */ + public function get_latest_vccw_url() + { + $url = Scaffold_VCCW::get_latest_vccw_url(); + $this->assertRegExp( '#^https://github.com/vccw-team/vccw/releases/download#', $url ); + } + /** * Tests for the `Scaffold_VCCW::rempty()`. *