Skip to content

Commit

Permalink
Fixed #9472: Issues updating duplicates notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Apr 13, 2009
1 parent ffff385 commit 974883d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
13 changes: 9 additions & 4 deletions api/soap/mc_issue_api.php
Expand Up @@ -696,15 +696,20 @@ function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {

mci_issue_set_custom_fields( $p_issue_id, $p_issue['custom_fields'] );

if( isset( $v_notes ) && is_array( $v_notes ) ) {
foreach( $v_notes as $t_note ) {
if( isset( $t_note['view_state'] ) ) {
if ( isset( $p_issue['notes'] ) && is_array( $p_issue['notes'] ) ) {
foreach ( $p_issue['notes'] as $t_note ) {
if ( isset( $t_note['id'] ) && ( (int)$t_note['id'] > 0 ) ) {
# skip issues that have an id, hence, are already added.
# these are the result of a previous call to mc_issue_get().
continue;
}

if ( isset( $t_note['view_state'] ) ) {
$t_view_state = $t_note['view_state'];
} else {
$t_view_state = config_get( 'default_bugnote_view_status' );
}

// TODO: consider supporting updating of bugnotes and detecting the ones that haven't changed.
$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
bugnote_add( $p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE );
}
Expand Down
73 changes: 73 additions & 0 deletions tests/soap/IssueUpdateTest.php
Expand Up @@ -159,4 +159,77 @@ public function testUpdateSummaryBasedOnMandatoryFields() {
$this->password,
$issueId);
}

/**
* This test case tests the following:
* 1. Creation of an issue.
* 2. Adding a note to the issue.
* 3. Getting the issue and calling update - making sure the note is not duplicated.
* 4. Getting the issue, adding a new note and making sure that the first is not duplicated, but second is added.
* 5. Deleting the issue.
*/
public function testUpdateWithNewNote() {
$issueToAdd = $this->getIssueToAdd( 'IssueUpdateTest.testUpdateWithNewNote' );

$issueId = $this->client->mc_issue_add(
$this->userName,
$this->password,
$issueToAdd);

$createdIssue = $this->client->mc_issue_get(
$this->userName,
$this->password,
$issueId);

$noteData = array(
'text' => "first note",
);

$this->client->mc_issue_note_add(
$this->userName,
$this->password,
$issueId,
$noteData);

$issueWithNote = $this->client->mc_issue_get(
$this->userName,
$this->password,
$issueId);

$this->assertEquals( 1, count( $issueWithNote->notes ) );

$this->client->mc_issue_update(
$this->userName,
$this->password,
$issueId,
$issueWithNote);

$issueWithNoteAfterUpdate = $this->client->mc_issue_get(
$this->userName,
$this->password,
$issueId);

$this->assertEquals( 1, count( $issueWithNoteAfterUpdate->notes ) );

$issueWithOneNewNote = $issueWithNoteAfterUpdate;
$issueWithOneNewNote->notes[] = array( 'text' => 'second note' );

$this->client->mc_issue_update(
$this->userName,
$this->password,
$issueId,
$issueWithOneNewNote);

$issueWithTwoNotes = $this->client->mc_issue_get(
$this->userName,
$this->password,
$issueId);

$this->assertEquals( 2, count( $issueWithTwoNotes->notes ) );

$this->client->mc_issue_delete(
$this->userName,
$this->password,
$issueId);
}
}

0 comments on commit 974883d

Please sign in to comment.