[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/tests/soap/ -> AttachmentTest.php (source)

   1  <?php
   2  # MantisBT - A PHP based bugtracking system
   3  
   4  # MantisBT is free software: you can redistribute it and/or modify
   5  # it under the terms of the GNU General Public License as published by
   6  # the Free Software Foundation, either version 2 of the License, or
   7  # (at your option) any later version.
   8  #
   9  # MantisBT is distributed in the hope that it will be useful,
  10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  # GNU General Public License for more details.
  13  #
  14  # You should have received a copy of the GNU General Public License
  15  # along with MantisBT.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * @package Tests
  19   * @subpackage UnitTests
  20   * @copyright Copyright (C) 2002 - 2011  MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21   * @link http://www.mantisbt.org
  22   */
  23  
  24  require_once  'SoapBase.php';
  25  
  26  /**
  27   * Test fixture for attachment methods
  28   */
  29  class AttachmentTest extends SoapBase {
  30  
  31  
  32      private $projectAttachmentsToDelete = array();
  33  
  34      /**
  35       * A test case that tests the following:
  36       * 1. Create an issue.
  37       * 2. Adds at attachemnt
  38       * 3. Get the issue.
  39       * 4. Verify that the attachment is present in the issue data
  40       * 5. Verify that the attachment contents is correct
  41       */
  42  	public function testAttachmentIsAdded() {
  43          $issueToAdd = $this->getIssueToAdd( 'AttachmentTest.testAttachmentIsAdded' );
  44  
  45          $attachmentContents = 'Attachment contents.';
  46  
  47          $issueId = $this->client->mc_issue_add(
  48              $this->userName,
  49              $this->password,
  50              $issueToAdd);
  51  
  52          $this->deleteAfterRun( $issueId );
  53  
  54          $attachmentId = $this->client->mc_issue_attachment_add(
  55              $this->userName,
  56              $this->password,
  57              $issueId,
  58              'sample.txt',
  59              'txt',
  60              base64_encode( $attachmentContents )
  61          );
  62  
  63          $issue = $this->client->mc_issue_get(
  64              $this->userName,
  65              $this->password,
  66              $issueId
  67          );
  68  
  69          $attachment = $this->client->mc_issue_attachment_get(
  70              $this->userName,
  71              $this->password,
  72              $attachmentId);
  73  
  74          $this->assertEquals( 1, count( $issue->attachments ), 'count($issue->attachments)' );
  75          $this->assertEquals( $attachmentContents, base64_decode( $attachment ), '$attachmentContents' );
  76          $this->assertEquals( $this->mantisPath.'file_download.php?file_id='.$issue->attachments[0]->id.'&type=bug', $issue->attachments[0]->download_url);
  77          $this->assertEquals( $this->userId, $issue->attachments[0]->user_id);
  78      }
  79  
  80  
  81      /**
  82       * A test case that tests the following:
  83       * 1. Gets a non-existing issue attachment
  84       * 2. Verifies that that an error is thrown
  85       */
  86  	public function testIssueAttachmentNotFound() {
  87  
  88          try {
  89              $this->client->mc_issue_attachment_get(
  90                  $this->userName,
  91                  $this->password,
  92                  -1);
  93              $this->fail("Should have failed.");
  94          } catch ( SoapFault $e) {
  95              $this->assertRegexp('/Unable to find an attachment/', $e->getMessage());
  96          }
  97      }
  98  
  99      /**
 100       * A test case that tests the following:
 101       * 1. Create an issue.
 102       * 2. Adds at attachemnt
 103       * 3. Get the issue.
 104       * 4. Verify that the attachment is present in the issue data
 105       * 5. Verify that the attachment contents is correct
 106       */
 107  	public function testProjectAttachmentIsAdded() {
 108          $this->skipIfProjectDocumentationIsNotEnabled();
 109  
 110          $attachmentContents = 'Attachment contents.';
 111  
 112          $attachmentId = $this->client->mc_project_attachment_add(
 113              $this->userName,
 114              $this->password,
 115              $this->getProjectId(),
 116              'sample.txt',
 117              'title',
 118              'description',
 119              'txt',
 120              base64_encode( $attachmentContents )
 121          );
 122  
 123          $this->projectAttachmentsToDelete[] = $attachmentId;
 124  
 125          $attachment = $this->client->mc_project_attachment_get(
 126              $this->userName,
 127              $this->password,
 128              $attachmentId);
 129          
 130          $this->assertEquals( $attachmentContents, base64_decode( $attachment ), '$attachmentContents' );
 131          
 132          $attachments = $this->client->mc_project_get_attachments( $this->userName, $this->password, $this->getProjectId() );
 133          $this->assertEquals( 1, count( $attachments ) );
 134          
 135          $attachment = $attachments[0];
 136          $this->assertEquals($this->userId, $attachment->user_id);
 137          $this->assertEquals('description', $attachment->description);
 138      }
 139  
 140      /**
 141       * A test case that tests the following:
 142       * 1. Gets a non-existing project attachment
 143       * 2. Verifies that an error is thrown
 144       */
 145  	public function testProjectAttachmentNotFound() {
 146  
 147          $this->skipIfProjectDocumentationIsNotEnabled();
 148  
 149          try {
 150              $this->client->mc_project_attachment_get(
 151                  $this->userName,
 152                  $this->password,
 153                  -1);
 154              $this->fail("Should have failed.");
 155          } catch ( SoapFault $e) {
 156              $this->assertRegexp('/Unable to find an attachment/', $e->getMessage());
 157          }
 158      }
 159  
 160  	private function skipIfProjectDocumentationIsNotEnabled() {
 161  
 162          $configEnabled = $this->client->mc_config_get_string( $this->userName, $this->password, 'enable_project_documentation' );
 163  
 164          if ( ! $configEnabled  ) {
 165              $this->markTestSkipped('Project documentation is not enabled.');
 166          }
 167      }
 168  
 169  	protected function tearDown() {
 170          SoapBase::tearDown();
 171  
 172          foreach ( $this->projectAttachmentsToDelete as $projectAttachmentId ) {
 173              $this->client->mc_project_attachment_delete(
 174                  $this->userName,
 175                  $this->password,
 176                  $projectAttachmentId);
 177          }
 178      }
 179  
 180  
 181  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7