[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/tests/soap/ -> IssueAddTest.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 issue creation webservice methods.
  28   */
  29  class IssueAddTest extends SoapBase {
  30      /**
  31       * A test case that tests the following:
  32       * 1. Ability to create an issue with only the mandatory parameters.
  33       * 2. mc_issue_get_biggest_id()
  34       * 3. mc_issue_get_id_from_summary()
  35       * 4. The defaulting of the non-mandatory parameters.
  36       */
  37  	public function testCreateIssue() {
  38          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssue' );
  39  
  40          $issueId = $this->client->mc_issue_add(
  41              $this->userName,
  42              $this->password,
  43              $issueToAdd);
  44  
  45          $this->deleteAfterRun( $issueId );
  46  
  47          $issueExists = $this->client->mc_issue_exists(
  48              $this->userName,
  49              $this->password,
  50              $issueId);
  51  
  52          $this->assertEquals( true, $issueExists );
  53  
  54          $biggestId = $this->client->mc_issue_get_biggest_id(
  55              $this->userName,
  56              $this->password,
  57              $issueToAdd['project']['id']);
  58  
  59          $this->assertEquals( $issueId, $biggestId );
  60  
  61          $issueIdFromSummary = $this->client->mc_issue_get_id_from_summary(
  62              $this->userName,
  63              $this->password,
  64              $issueToAdd['summary']);
  65  
  66          $this->assertEquals( $issueId, $issueIdFromSummary );
  67  
  68          $issue = $this->client->mc_issue_get(
  69              $this->userName,
  70              $this->password,
  71              $issueId);
  72  
  73          // explicitly specified fields
  74          $this->assertEquals( $issueToAdd['category'], $issue->category );
  75          $this->assertEquals( $issueToAdd['summary'], $issue->summary );
  76          $this->assertEquals( $issueToAdd['description'], $issue->description );
  77          $this->assertEquals( $issueToAdd['project']['id'], $issue->project->id );
  78  
  79          // defaulted fields
  80          $this->assertEquals( $issueId, $issue->id );
  81          $this->assertEquals( 10, $issue->view_state->id );
  82          $this->assertEquals( 'public', $issue->view_state->name );
  83          $this->assertEquals( 30, $issue->priority->id );
  84          $this->assertEquals( 'normal', $issue->priority->name );
  85          $this->assertEquals( 50, $issue->severity->id );
  86          $this->assertEquals( 'minor', $issue->severity->name );
  87          $this->assertEquals( 10, $issue->status->id );
  88          $this->assertEquals( 'new', $issue->status->name );
  89          $this->assertEquals( $this->userName, $issue->reporter->name );
  90          $this->assertEquals( 70, $issue->reproducibility->id );
  91          $this->assertEquals( 'have not tried', $issue->reproducibility->name );
  92          $this->assertEquals( 0, $issue->sponsorship_total );
  93          $this->assertEquals( 10, $issue->projection->id );
  94          $this->assertEquals( 'none', $issue->projection->name );
  95          $this->assertEquals( 10, $issue->eta->id );
  96          $this->assertEquals( 'none', $issue->eta->name );
  97          $this->assertEquals( 10, $issue->resolution->id );
  98          $this->assertEquals( 'open', $issue->resolution->name );
  99  
 100      }
 101  
 102      /**
 103       * A test cases that tests the creation of issues with html markup in summary
 104       * and description.
 105       */
 106  	public function testCreateIssueWithHtmlMarkup() {
 107          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithHtmlMarkup' );
 108  
 109          $issueToAdd['summary'] .= " <strong>WithHtmlMarkup</strong>";
 110          $issueToAdd['description'] .= " <strong>WithHtmlMarkup</strong>";
 111  
 112          $issueId = $this->client->mc_issue_add(
 113              $this->userName,
 114              $this->password,
 115              $issueToAdd);
 116  
 117          $this->deleteAfterRun( $issueId );
 118  
 119          $issue = $this->client->mc_issue_get(
 120              $this->userName,
 121              $this->password,
 122              $issueId);
 123  
 124          // explicitly specified fields
 125          $this->assertEquals( $issueToAdd['summary'], $issue->summary );
 126          $this->assertEquals( $issueToAdd['description'], $issue->description );
 127  
 128      }
 129  
 130      /**
 131       * This issue tests the following:
 132       * 1. Creating an issue with some fields that are typically not used at creation time.
 133       *    For example: projection, eta, resolution, status, fixed_in_version, and target_version.
 134       * 2. Get the issue and confirm that all fields are set as expected.
 135       * 3. Delete the issue.
 136       *
 137       * This test case was added for bug #9132.
 138       */
 139  	public function testCreateIssueWithRareFields() {
 140          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithRareFields' );
 141  
 142          $issueToAdd['projection'] = array( 'id' => 90 );    // redesign
 143          $issueToAdd['eta'] = array( 'id' => 60 );           // > 1 month
 144          $issueToAdd['resolution'] = array( 'id' => 80 );    // suspended
 145          $issueToAdd['status'] = array( 'id' => 40 );        // confirmed
 146          $issueToAdd['fixed_in_version'] = 'fixed version';
 147          $issueToAdd['target_version'] = 'target version';
 148  
 149          $issueId = $this->client->mc_issue_add(
 150              $this->userName,
 151              $this->password,
 152              $issueToAdd);
 153  
 154          $this->deleteAfterRun( $issueId );
 155  
 156          $issue = $this->client->mc_issue_get(
 157              $this->userName,
 158              $this->password,
 159              $issueId);
 160  
 161          // explicitly specified fields
 162          $this->assertEquals( $issueToAdd['projection']['id'], $issue->projection->id );
 163          $this->assertEquals( $issueToAdd['eta']['id'], $issue->eta->id );
 164          $this->assertEquals( $issueToAdd['resolution']['id'], $issue->resolution->id );
 165          $this->assertEquals( $issueToAdd['status']['id'], $issue->status->id );
 166          $this->assertEquals( $issueToAdd['fixed_in_version'], $issue->fixed_in_version );
 167          $this->assertEquals( $issueToAdd['target_version'], $issue->target_version );
 168      }
 169  
 170      /**
 171       * This issue tests the following:
 172       * 1. Retrieving all the administrator users, and verifying at least one is present
 173       * 2. Creating an issue with the first admin user as a handler
 174       * 3. Retrieving the issue after it is created
 175       * 4. Verifying that the correct handler is passed
 176       * 5. Deleting the issue
 177       */
 178  	public function testCreateIssueWithHandler() {
 179  
 180          $adminUsers = $this->client->mc_project_get_users($this->userName, $this->password, $this->getProjectId(), 90);
 181  
 182          $this->assertTrue(count($adminUsers) >= 1 , "count(adminUsers) >= 1");
 183  
 184          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithHandler' );
 185  
 186          $adminUser = $adminUsers[0];
 187  
 188          $issueToAdd['handler'] = $adminUser;
 189  
 190          $issueId = $this->client->mc_issue_add(
 191              $this->userName,
 192              $this->password,
 193              $issueToAdd);
 194  
 195          $this->deleteAfterRun( $issueId );
 196  
 197          $issue = $this->client->mc_issue_get(
 198              $this->userName,
 199              $this->password,
 200              $issueId);
 201  
 202          $this->assertEquals( $adminUser->id, $issue->handler->id, 'handler.id' );
 203      }
 204  
 205      /**
 206       * This issue tests the following
 207       *
 208       * 1. Creating an issue with a due date
 209       * 2. Retrieving the issue
 210       * 3. Validating that the due date is properly set
 211       */
 212  	public function testCreateIssueWithDueDate() {
 213  
 214          $this->skipIfDueDateIsNotEnabled();
 215  
 216          $date = '2015-10-29T12:59:14Z';
 217  
 218          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithDueDate' );
 219  
 220          $issueToAdd['due_date'] = $date;
 221  
 222          $issueId = $this->client->mc_issue_add(
 223              $this->userName,
 224              $this->password,
 225              $issueToAdd);
 226  
 227          $this->deleteAfterRun( $issueId );
 228  
 229          $issue = $this->client->mc_issue_get(
 230              $this->userName,
 231              $this->password,
 232              $issueId);
 233  
 234  
 235          $this->assertEquals( $date, $issue->due_date, "due_date");
 236      }
 237  
 238      /**
 239       * This issue tests the following
 240       *
 241       * 1. Creating an issue without a due date
 242       * 2. Retrieving the issue
 243       * 3. Validating that the due date is properly encoded as null
 244       *
 245       * This stricter verification originates in some SOAP frameworks, notably
 246       * Axis, not accepting the empty tag format sent by nusoap by default, which
 247       * is accepted by the PHP5 SOAP extension nevertheless.
 248       */
 249  	public function testCreateIssueWithNullDueDate() {
 250          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithNullDueDate' );
 251  
 252          $issueId = $this->client->mc_issue_add(
 253              $this->userName,
 254              $this->password,
 255              $issueToAdd);
 256  
 257          $this->deleteAfterRun( $issueId );
 258  
 259          $issue = $this->client->mc_issue_get(
 260              $this->userName,
 261              $this->password,
 262              $issueId);
 263  
 264          $this->assertNull( $issue->due_date , 'due_date is not null' );
 265          $this->assertEquals( 'true', $this->readDueDate( $this->client->__getLastResponse() ) , 'xsi:nil not set to true' );
 266      }
 267  
 268      /**
 269       * This issue tests the following
 270       *
 271       * 1. Creating an issue with no category
 272       * 2. Retrieving the issue
 273       * 3. Verifying that the category is empty.
 274       *
 275       */
 276  	public function testCreateBugWithNoCategory() {
 277          $this->skipIfAllowNoCategoryIsDisabled();
 278  
 279          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateBugWithNoCategory' );
 280          unset ( $issueToAdd['category'] );
 281  
 282          $issueId = $this->client->mc_issue_add(
 283              $this->userName,
 284              $this->password,
 285              $issueToAdd);
 286  
 287          $this->deleteAfterRun( $issueId );
 288  
 289          $issue = $this->client->mc_issue_get(
 290              $this->userName,
 291              $this->password,
 292              $issueId);
 293  
 294          $this->assertEquals( '', $issue->category, 'category' );
 295  
 296      }
 297  
 298      /**
 299       *
 300       * @param string $issueDataXml
 301       * @return string the xsi:null value
 302       */
 303  	private function readDueDate( $issueDataXml ) {
 304          $reader = new XMLReader();
 305          $reader->XML( $this->client->__getLastResponse());
 306  
 307          while ( $reader->read() ) {
 308              switch ( $reader->nodeType ) {
 309  
 310                  case XMLReader::ELEMENT:
 311                      if ( $reader->name == 'due_date') {
 312                          return $reader->getAttribute( 'xsi:nil' );
 313                      }
 314                      break;
 315              }
 316          }
 317          return null;
 318      }
 319  
 320      /**
 321       * A test cases that tests the creation of issues
 322       * with a note passed in which contains time tracking data.
 323       */
 324  	public function testCreateIssueWithTimeTrackingNote() {
 325  
 326          $this->skipIfTimeTrackingIsNotEnabled();
 327  
 328          $issueToAdd = $this->getIssueToAdd( 'testCreateIssueWithNote' );
 329          $issueToAdd['notes'] = array(
 330              array(
 331                  'text' => "first note",
 332                  'time_tracking' => "30"
 333              )
 334          );
 335  
 336          $issueId = $this->client->mc_issue_add(
 337              $this->userName,
 338              $this->password,
 339              $issueToAdd);
 340  
 341          $issue = $this->client->mc_issue_get(
 342              $this->userName,
 343              $this->password,
 344              $issueId);
 345  
 346          // verify note existence and time tracking data
 347          $this->assertEquals( 1, count( $issue->notes ) );
 348  
 349          $note = $issue->notes[0];
 350  
 351          $this->assertEquals( 30, $note->time_tracking );
 352  
 353          $this->client->mc_issue_delete(
 354              $this->userName,
 355              $this->password,
 356              $issueId);
 357      }
 358  
 359      /**
 360       * This issue tests the following
 361       *
 362       * 1. Creating an issue where the handler is given by name
 363       * 2. Retrieving the issue
 364       * 3. Verifying that the handler name is correctly set
 365       */
 366  	public function testCreateIssueWithHandlerByName() {
 367  
 368          $issueToAdd = $this->getIssueToAdd( 'testCreateIssueWithHandlerByName' );
 369          $issueToAdd['handler'] = array(
 370              'name' => $this->userName
 371          );
 372  
 373          $issueId = $this->client->mc_issue_add(
 374              $this->userName,
 375              $this->password,
 376              $issueToAdd);
 377  
 378          $this->deleteAfterRun( $issueId );
 379  
 380          $issue = $this->client->mc_issue_get(
 381              $this->userName,
 382              $this->password,
 383              $issueId);
 384  
 385          $this->assertEquals( $this->userName,  $issue->handler->name );
 386      }
 387      
 388      /**
 389       * Tests that a created issue with a non-existent version returns the correct error message.
 390       */
 391      public function testCreateIssueWithFaultyVersionGeneratesError() {
 392  
 393          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithFaultyVersionGeneratesError' );
 394          $issueToAdd['version'] = 'noSuchVersion';
 395          
 396          try {
 397              $this->client->mc_issue_add(
 398                  $this->userName,
 399                  $this->password,
 400                  $issueToAdd);
 401              
 402              $this->fail( "Invalid version did not raise error." );
 403          } catch ( SoapFault $e) {
 404              $this->assertContains( "Version 'noSuchVersion' does not exist in project", $e->getMessage() );    
 405          }
 406      }
 407      
 408      /**
 409       * Tests that an issue with a proper version set is correctly created
 410       */
 411  	public function testCreateIssueWithVersion() {
 412          
 413          $version = array (
 414              'project_id' => $this->getProjectId(),
 415              'name' => '1.0',
 416              'released' => 'true',
 417              'description' => 'Test version',
 418              'date_order' => ''
 419          );
 420          
 421          $versionId = $this->client->mc_project_version_add( $this->userName, $this->password, $version );
 422          
 423          $this->deleteVersionAfterRun( $versionId );
 424          
 425          $issueToAdd = $this->getIssueToAdd( 'IssueAddTest.testCreateIssueWithVersion' );
 426          $issueToAdd['version'] = $version['name'];
 427          
 428          $issueId = $this->client->mc_issue_add( $this->userName, $this->password, $issueToAdd );
 429          
 430          $this->deleteAfterRun($issueId);
 431          
 432          $createdIssue = $this->client->mc_issue_get( $this->userName, $this->password, $issueId );
 433          
 434          $this->assertEquals( $version['name'], $createdIssue->version );
 435      }
 436      
 437      /**
 438       * Test that the biggest id is correctly retrieved
 439       */
 440  	public function testGetBiggestId() {
 441          
 442          $firstIssueId = $this->client->mc_issue_add( $this->userName, $this->password, $this->getIssueToAdd( 'IssueAddTest.testGetBiggestId1'));
 443          $this->deleteAfterRun( $firstIssueId );
 444          
 445          $secondIssueId = $this->client->mc_issue_add( $this->userName, $this->password, $this->getIssueToAdd( 'IssueAddTest.testGetBiggestId2'));
 446          $this->deleteAfterRun( $secondIssueId );
 447          
 448          $firstIssue = $this->client->mc_issue_get( $this->userName, $this->password, $firstIssueId );
 449          
 450          // this update should trigger this issue's id to be returned as the biggest
 451          // reported as bug #12887
 452          $this->client->mc_issue_update( $this->userName, $this->password, $firstIssueId, $firstIssue);
 453          
 454          $this->assertEquals( $secondIssueId, $this->client->mc_issue_get_biggest_id( $this->userName, $this->password, $this->getProjectId() ));
 455      }
 456      
 457      /**
 458       * A test cases that tests the creation of issues 
 459       * with a note passed in which contains time tracking data.
 460       */
 461  	public function testCreateIssueWithMiscNote() {
 462          
 463          $issueToAdd = $this->getIssueToAdd( 'testCreateIssueWithMiscNote' );
 464          $issueToAdd['notes'] = array(
 465              array(
 466                  'text' => "first note",
 467                  'note_type' => 2,
 468                  'note_attr' => 'attr_value'
 469              )
 470          );
 471  
 472          $issueId = $this->client->mc_issue_add(
 473              $this->userName,
 474              $this->password,
 475              $issueToAdd);
 476              
 477          $this->deleteAfterRun($issueId);
 478  
 479          $issue = $this->client->mc_issue_get(
 480              $this->userName,
 481              $this->password,
 482              $issueId);
 483  
 484          // verify note existence and time tracking data
 485          $this->assertEquals( 1, count( $issue->notes ) );
 486  
 487          $note = $issue->notes[0];
 488          
 489          $this->assertEquals( 2, $note->note_type );
 490          $this->assertEquals( 'attr_value', $note->note_attr );
 491      }
 492  }


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