Merge pull request #488 from marc1706/ticket/477

[ticket/477] Expect version_helper to throw RuntimeException
This commit is contained in:
Marc Alexander
2015-02-27 10:40:39 +01:00
2 changed files with 36 additions and 12 deletions

View File

@@ -41,6 +41,12 @@ class version_check
*/ */
protected $current_version; protected $current_version;
/** @var array Update data */
protected $update_data;
/** @var array Template data */
protected $template_data;
/** /**
* Construct a version_check object * Construct a version_check object
* *
@@ -65,7 +71,7 @@ class version_check
* returning current version * returning current version
* *
* @param bool $return_version Yes if current version should be returned * @param bool $return_version Yes if current version should be returned
* @return string Current version if $return_version is set to true * @return string|bool Current version if $return_version is set to true, false if not
*/ */
public function check($return_version = false) public function check($return_version = false)
{ {
@@ -76,7 +82,15 @@ class version_check
$this->version_helper->force_stability(($this->config['extension_force_unstable'] || !$this->version_helper->is_stable($this->current_version)) ? 'unstable' : null); $this->version_helper->force_stability(($this->config['extension_force_unstable'] || !$this->version_helper->is_stable($this->current_version)) ? 'unstable' : null);
$updates = $this->version_helper->get_suggested_updates(true); // Expect version_helper to throw RuntimeExceptions
try
{
$this->update_data = $this->version_helper->get_suggested_updates(true);
}
catch (\RuntimeException $e)
{
return false;
}
// Return version if $return_version is set to true // Return version if $return_version is set to true
if ($return_version) if ($return_version)
@@ -84,9 +98,9 @@ class version_check
return $this->current_version; return $this->current_version;
} }
$version_up_to_date = empty($updates); $version_up_to_date = empty($this->update_data);
$template_data = array( $this->template_data = array(
'AUTHOR' => $this->version_data['author'], 'AUTHOR' => $this->version_data['author'],
'CURRENT_VERSION' => $this->current_version, 'CURRENT_VERSION' => $this->current_version,
'UP_TO_DATE' => sprintf((!$version_up_to_date) ? $this->user->lang['NOT_UP_TO_DATE'] : $this->user->lang['UP_TO_DATE'], $this->version_data['title']), 'UP_TO_DATE' => sprintf((!$version_up_to_date) ? $this->user->lang['NOT_UP_TO_DATE'] : $this->user->lang['UP_TO_DATE'], $this->version_data['title']),
@@ -96,15 +110,25 @@ class version_check
'LATEST_VERSION' => $this->current_version, 'LATEST_VERSION' => $this->current_version,
); );
if (!$version_up_to_date) $this->display_update_information();
$this->template->assign_block_vars('mods', $this->template_data);
return false;
}
/**
* Display update information if updates exist
*/
protected function display_update_information()
{ {
$updates = array_shift($updates); if (!empty($this->update_data))
$template_data = array_merge($template_data, array( {
'ANNOUNCEMENT' => (string) $updates['announcement'], $update = array_shift($this->update_data);
'DOWNLOAD' => (string) $updates['download'], $this->template_data = array_merge($this->template_data, array(
'LATEST_VERSION' => $updates['current'], 'ANNOUNCEMENT' => (string) $update['announcement'],
'DOWNLOAD' => (string) $update['download'],
'LATEST_VERSION' => $update['current'],
)); ));
} }
$this->template->assign_block_vars('mods', $template_data);
} }
} }

View File

@@ -76,7 +76,7 @@ class phpbb_functions_version_check_test extends \board3\portal\tests\testframew
{ {
$this->get_version_helper($version); $this->get_version_helper($version);
$this->assertEquals($version, $this->version_check->check(true)); $this->assertEquals($version, $this->version_check->check(true));
$this->assertNull($this->version_check->check()); $this->assertFalse($this->version_check->check());
$this->template->assert_equals($template_data, 'mods'); $this->template->assert_equals($template_data, 'mods');
} }
} }