Skip to content

Commit

Permalink
Fix project attachment handling using the SOAP API
Browse files Browse the repository at this point in the history
This commit fixes 2 issues with the project attachment handling:

- in mc_project_attachment_add the contents was not base64 decoded;
- in mci_file_get the $row array expected to contain a bug id, bug
  that only holds for issue attachments.

A test has been added to verify the behaviour of project
attachments.
  • Loading branch information
rombert committed Oct 30, 2009
1 parent f7004c2 commit 475ecf2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/soap/mc_file_api.php
Expand Up @@ -159,10 +159,10 @@ function mci_file_get( $p_file_id, $p_type, $p_user_id ) {
$result = db_query( $query );
$row = db_fetch_array( $result );

$t_bug_id = $row['bug_id'];

if ( $p_type == 'doc' ) {
$t_project_id = $row['project_id'];
} else if ( $p_type == 'bug' ) {
$t_bug_id = $row['bug_id'];
}

$t_diskfile = $row['diskfile'];
Expand Down
2 changes: 1 addition & 1 deletion api/soap/mc_project_attachment_api.php
Expand Up @@ -53,7 +53,7 @@ function mc_project_attachment_add( $p_username, $p_password, $p_project_id, $p_
if( is_blank( $p_title ) ) {
return new soap_fault( 'Client', '', 'Title must not be empty.' );
}
return mci_file_add( $p_project_id, $p_name, $p_content, $p_file_type, 'project', $p_title, $p_description );
return mci_file_add( $p_project_id, $p_name, base64_decode( $p_content ), $p_file_type, 'project', $p_title, $p_description );
}

/**
Expand Down
51 changes: 51 additions & 0 deletions tests/soap/AttachmentTest.php
Expand Up @@ -27,6 +27,10 @@
* Test fixture for attachment methods
*/
class AttachmentTest extends SoapBase {


private $projectAttachmentsToDelete = array();

/**
* A test case that tests the following:
* 1. Create an issue.
Expand Down Expand Up @@ -70,4 +74,51 @@ public function testAttachmentIsAdded() {
$this->assertEquals( 1, count( $issue->attachments ), 'count($issue->attachments)' );
$this->assertEquals( $attachmentContents, $attachment, '$attachmentContents' );
}

/**
* A test case that tests the following:
* 1. Create an issue.
* 2. Adds at attachemnt
* 3. Get the issue.
* 4. Verify that the attachment is present in the issue data
* 5. Verify that the attachment contents is correct
*/
public function testProjectAttachmentIsAdded() {
$issueToAdd = $this->getIssueToAdd( 'AttachmentTest.testProjectAttachmentIsAdded' );

$attachmentContents = 'Attachment contents.';

$attachmentId = $this->client->mc_project_attachment_add(
$this->userName,
$this->password,
$this->getProjectId(),
'sample.txt',
'title',
'description',
'txt',
base64_encode( $attachmentContents )
);

$this->projectAttachmentsToDelete[] = $attachmentId;

$attachment = $this->client->mc_project_attachment_get(
$this->userName,
$this->password,
$attachmentId);

$this->assertEquals( $attachmentContents, $attachment, '$attachmentContents' );
}

protected function tearDown() {
SoapBase::tearDown();

foreach ( $this->projectAttachmentsToDelete as $projectAttachmentId) {
$this->client->mc_project_attachment_delete(
$this->userName,
$this->password,
$projectAttachmentId);
}
}


}

0 comments on commit 475ecf2

Please sign in to comment.