Skip to content

Commit

Permalink
Fix indentation + php docs
Browse files Browse the repository at this point in the history
Fixes #30415
  • Loading branch information
vboctor committed Apr 28, 2023
1 parent 99f61e9 commit 4cdf5c7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 41 deletions.
76 changes: 38 additions & 38 deletions core/commands/VersionUpdateCommand.php
Expand Up @@ -36,28 +36,28 @@ class VersionUpdateCommand extends Command {
*/
private $version_id;

/**
* $p_data['query'] is expected to contain:
* - project_id (integer)
/**
* $p_data['query'] is expected to contain:
* - project_id (integer)
* - version_id (integer)
*
* $p_data['payload'] is expected to contain:
* - name (string)
* - description (string)
* - released (bool)
* - obsolete (bool)
* - timestamp (timestamp) - e.g. 2018-05-21T15:00:00-08:00
*
* @param array $p_data The command data.
*/
function __construct( array $p_data ) {
parent::__construct( $p_data );
}

/**
* Validate the data.
*/
function validate() {
*
* $p_data['payload'] is expected to contain:
* - name (string)
* - description (string)
* - released (bool)
* - obsolete (bool)
* - timestamp (timestamp) - e.g. 2018-05-21T15:00:00-08:00
*
* @param array $p_data The command data.
*/
function __construct( array $p_data ) {
parent::__construct( $p_data );
}

/**
* Validate the data.
*/
function validate() {
$this->project_id = helper_parse_id( $this->query( 'project_id' ), 'project_id' );

if( !project_exists( $this->project_id ) ) {
Expand Down Expand Up @@ -89,14 +89,14 @@ function validate() {
ERROR_VERSION_NOT_FOUND,
array( $this->version_id ) );
}
}

/**
* Process the command.
*
* @return array Command response
*/
protected function process() {
}

/**
* Process the command.
*
* @return array Command response
*/
protected function process() {
global $g_project_override;

$t_prev_project_id = $g_project_override;
Expand All @@ -109,7 +109,7 @@ protected function process() {
array( $this->version_id ) );
}

$t_version = version_get( $this->version_id );
$t_version = version_get( $this->version_id );

$t_name = $this->payload( 'name' );
if( !is_null( $t_name ) ) {
Expand All @@ -121,7 +121,7 @@ protected function process() {
}

$t_version->version = $t_name = trim( $t_name );

if( !version_is_valid_name( $t_name ) ) {
throw new ClientException(
'Invalid version name',
Expand All @@ -143,7 +143,7 @@ protected function process() {
$t_version->description = trim( $t_description );
}

$t_released = $this->payload( 'released' );
$t_released = $this->payload( 'released' );
if( !is_null( $t_released ) ) {
$t_version->released = $t_released ? VERSION_RELEASED : VERSION_FUTURE;
}
Expand All @@ -153,13 +153,13 @@ protected function process() {
$t_version->obsolete = $t_obsolete;
}

$t_timestamp = $this->payload( 'timestamp' );
if( !is_null( $t_timestamp ) && !is_blank( $t_timestamp ) ) {
$t_timestamp = strtotime( $t_timestamp );
$t_timestamp = $this->payload( 'timestamp' );
if( !is_null( $t_timestamp ) && !is_blank( $t_timestamp ) ) {
$t_timestamp = strtotime( $t_timestamp );
$t_version->date_order = $t_timestamp;
}
}

version_update( $t_version );
version_update( $t_version );

event_signal( 'EVENT_MANAGE_VERSION_UPDATE', array( $this->version_id ) );

Expand All @@ -170,5 +170,5 @@ protected function process() {
$g_project_override = $t_prev_project_id;

return $t_result;
}
}
}
6 changes: 6 additions & 0 deletions core/version_api.php
Expand Up @@ -286,6 +286,12 @@ function version_is_unique( $p_version, $p_project_id = null ) {
return version_get_id( $p_version, $p_project_id ) === false;
}

/**
* Validate the specified version name
*
* @param string $p_version_name Version name to validate.
* @return boolean true: valid, false: otherwise.
*/
function version_is_valid_name( $p_version_name ) {
if( is_null( $p_version_name ) ||
is_blank( $p_version_name ) ||
Expand Down
10 changes: 8 additions & 2 deletions tests/rest/RestBase.php
Expand Up @@ -146,20 +146,26 @@ protected function tearDown() {
}
}

/**
* Creates a RequestBuilder instance for building a http request.
*
* @return RequestBuilder
*/
public function builder() {
return new RequestBuilder( $this->base_path, $this->token );
}

/**
* return integer The default project id.
* Gets the id of the default project used for testing.
*
* @return integer
*/
protected function getProjectId() {
return $this->projectId;
}

/**
* return string The default category.
* Gets the default category used for testing.
* @return string
*/
protected function getCategory() {
Expand Down
58 changes: 57 additions & 1 deletion tests/rest/RestProjectVersionTests.php
Expand Up @@ -50,13 +50,17 @@ public function setUp() {

/**
* Test add a version by name
*
* @return void
*/
public function testProjectAddVersionWithName() {
$this->createVersion();
}

/**
* Test add a version by name and desc
*
* @return void
*/
public function testProjectAddVersionWithNameAndDesc() {
$t_version_to_create = array(
Expand All @@ -77,6 +81,11 @@ public function testProjectAddVersionWithNameAndDesc() {
$this->assertEquals( $t_version_to_create['description'], $t_version['description'] );
}

/**
* Test getting a version
*
* @return void
*/
public function testProjectGetVersion() {
$t_version = $this->createVersion();

Expand All @@ -91,6 +100,11 @@ public function testProjectGetVersion() {
$this->assertEquals( $t_version['name'], $t_returned_version['name'] );
}

/**
* Testing getting versions belong to a project.
*
* @return void
*/
public function testProjectGetVersions() {
$this->createVersion();

Expand All @@ -101,22 +115,42 @@ public function testProjectGetVersions() {
$this->assertGreaterThanOrEqual( 1, count( $t_result['versions'] ) );
}

/**
* Test getting versions for a project that doesn't exist.
*
* @return void
*/
public function testProjectGetVersionsForNonExistentProject() {
$t_response = $this->builder()->get( '/projects/1000000/versions' )->send();
$this->assertEquals( 404, $t_response->getStatusCode() );
}

/**
* Test getting a version that doesn't exist.
*
* @return void
*/
public function testProjectGetVersionForNonExistentVersion() {
$t_response = $this->builder()->get( $this->ver_base_url . '1000000' )->send();
$this->assertEquals( 404, $t_response->getStatusCode() );
}

/**
* Test adding a version for a project that doesn't exist.
*
* @return void
*/
public function testProjectAddVersionForNonExistentProject() {
$t_version_to_create = array( 'name' => $this->versionName() );
$t_response = $this->builder()->post( '/projects/1000000/versions', $t_version_to_create )->send();
$this->assertEquals( 404, $t_response->getStatusCode() );
}

/**
* Test deleting a version.
*
* @return void
*/
public function testProjectDeleteVersion() {
$t_version = $this->createVersion();

Expand All @@ -137,7 +171,12 @@ public function testProjectDeleteVersion() {
$this->assertEquals( 204, $t_response->getStatusCode() );
}

public function testProjectVersionAnonymous() {
/**
* Test that an anonymous user can't delete a version.
*
* @return void
*/
public function testProjectDeleteVersionAnonymous() {
$t_version = $this->createVersion();

// anonymous users can't update a version
Expand Down Expand Up @@ -253,6 +292,12 @@ public function testProjectUpdateVersion() {
$this->assertTrue( $t_version_result['released'] );
}

/**
* Data provider for version names that should be rejected by
* create/update version APIs.
*
* @return array The test data
*/
public function providerVersionInvalidNames() {
return array(
'empty' =>array( '' ),
Expand All @@ -265,10 +310,21 @@ public function providerVersionInvalidNames() {
);
}

/**
* Generate a random version name
*
* @return string The version name
*/
private function versionName() {
return 'Test Version ' . rand( 1, 1000000 );
}

/**
* Create a version, validate that it was created successfully, and
* return the version information.
*
* @return array The version information
*/
private function createVersion() {
$t_version_to_create = array( 'name' => $this->versionName() );

Expand Down

0 comments on commit 4cdf5c7

Please sign in to comment.