Skip to content

Commit

Permalink
Merge pull request #1548 from tripal/tv4g0-issue214-tripal-version
Browse files Browse the repository at this point in the history
Port tripal_version() api function and drush trp-version to Tripal 4
  • Loading branch information
laceysanderson committed Jul 1, 2023
2 parents ed03c3a + 56cf869 commit e72299a
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 4 deletions.
13 changes: 12 additions & 1 deletion tripal/src/Commands/TripalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,15 @@ public function rerunJob($options = ['username' => NULL, 'job_id' => NULL,
tripal_launch_job(0, $new_job_id, $max_jobs, $single);
}
}
}
/**
* Returns the current version of Tripal that is installed
*
* @command tripal:version
* @aliases trp-version
* @usage drush trp-version
* Returns the current Tripal version string.
*/
public function tripalVersion() {
$this->output()->writeln(tripal_version());
}
}
14 changes: 13 additions & 1 deletion tripal/src/api/tripal.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@ function tripal_load_configuration($module, $config_type) {
}
}
}
}
}

/**
* Returns the current version of Tripal as defined in the tripal.info.yml file.
*
* @return string
* The version string of Tripal, e.g. "4.0"
*/
function tripal_version() {
$tripal_module = \Drupal::service('module_handler')->getModule('tripal');
$tripal_info = \Drupal::service('info_parser')->parse($tripal_module->getPathname());
return $tripal_info['version'];
}
69 changes: 69 additions & 0 deletions tripal/tests/src/Kernel/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Drupal\Tests\tripal\Kernel\TripalConfig;

use Drupal\KernelTests\KernelTestBase;

/**
* Tests for configuration in Yaml files.
* These tests do not currently cover any code.
*
* @group Tripal
* @group Tripal Config
*/
class configTest extends KernelTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = ['tripal', 'tripal_biodb', 'tripal_chado'];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
}

/**
* {@inheritdoc}
*/
public static function tearDownAfterClass() :void {
}

/**
* When we update the version of Tripal, we need to remember to
* do it in all three yaml files. This function confirms that
* version and also core_version_requirements are consistent in
* each of the sub-modules' *.info.yml files.
*
*/
public function testConfigYaml() {
$previous_module = NULL;
$previous_version = NULL;
$previous_core_version_requirement = NULL;
foreach (self::$modules as $module) {
$moduleObj = \Drupal::service('module_handler')->getModule($module);
$moduleInfo = \Drupal::service('info_parser')->parse($moduleObj->getPathname());
$version = $moduleInfo['version'] ?? NULL;
$core_version_requirement = $moduleInfo['core_version_requirement'] ?? NULL;
// Verify that values are present.
$this->assertNotNull($version, 'No "version" was specified in ' . $module . '.info.yml');
$this->assertNotNull($core_version_requirement, 'No "core_version_requirement" was specified in ' . $module . '.info.yml');
// On second and later modules, verify that returned values match those
// from the previous module (the consistency check).
if ($previous_module) {
$this->assertEquals($version, $previous_version,
'version for module "'
. $previous_module . '" is different than for module "' . $module . '"');
$this->assertEquals($core_version_requirement, $previous_core_version_requirement,
'core_version_requirement for module "'
. $previous_module . '" is different than for module "' . $module . '"');
}
$previous_module = $module;
$previous_version = $version;
$previous_core_version_requirement = $core_version_requirement;
}
}

}
50 changes: 50 additions & 0 deletions tripal/tests/src/Kernel/api/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Drupal\Tests\tripal\Kernel\Api\TripalApi;

use Drupal\KernelTests\KernelTestBase;

/**
* Tests for procedural API functions.
*
* @group Tripal
* @group Tripal Api
*/
class apiTest extends KernelTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = ['tripal'];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
}

/**
* {@inheritdoc}
*/
public static function tearDownAfterClass() :void {
}

/**
* Tests the API function tripal_version().
*
* @cover ::tripal_version
*/
public function testTripalVersion() {
// Get the version of the Tripal module as stored in tripal.info.yml
$moduleObj = \Drupal::service('module_handler')->getModule(self::$modules[0]);
$info = \Drupal::service('info_parser')->parse($moduleObj->getPathname());
$check_version = $info['version'] ?? NULL;

// Get the version using the API function to be tested.
$tripal_version = tripal_version();

$this->assertEquals($check_version, $tripal_version, 'tripal_version() returned the wrong value');
}

}
1 change: 1 addition & 0 deletions tripal/tripal.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type: module
description: Tripal is a toolkit to facilitate construction of online genomic, genetic (and other biological) websites.
core_version_requirement: ^9.4 || ^10
package: Tripal
version: 4.0.alpha2
dependencies:
- drupal:pgsql
- drupal:views
Expand Down
3 changes: 2 additions & 1 deletion tripal_biodb/tripal_biodb.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: 'Tripal BioDB Task API'
type: module
description: 'Provides a database focused TASK API for Tripal.'
core_version_requirement: ^9.2 || ^10
core_version_requirement: ^9.4 || ^10
package: 'Tripal'
version: 4.0.alpha2
dependencies:
- tripal:tripal
3 changes: 2 additions & 1 deletion tripal_chado/tripal_chado.info.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: 'Tripal Chado'
type: module
description: 'Chado integration for Tripal.'
core_version_requirement: ^9.2 || ^10
core_version_requirement: ^9.4 || ^10
package: 'Tripal'
version: 4.0.alpha2
dependencies:
- tripal:tripal
- tripal:tripal_biodb

0 comments on commit e72299a

Please sign in to comment.