Merge branch '2013.03' into 2013.10
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 29 Jan 2014 15:40:07 +0000 (16:40 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 29 Jan 2014 15:40:07 +0000 (16:40 +0100)
Conflicts:
tests/tine20/Crm/JsonTest.php
tine20/Crm/Model/Lead.php
tine20/Tinebase/Preference/Abstract.php

1  2 
tests/tine20/Crm/JsonTest.php
tine20/Crm/Model/Lead.php
tine20/Tinebase/Preference/Abstract.php

@@@ -564,72 -532,18 +564,86 @@@ class Crm_JsonTest extends Crm_Abstract
              }
          }
      }
 +    
 +    /**
 +     * testCreateLeadWithAttachment
 +     * 
 +     * @see 0005024: allow to attach external files to records
 +     */
 +    public function testCreateLeadWithAttachment()
 +    {
 +        $tempFileBackend = new Tinebase_TempFile();
 +        $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/Filemanager/files/test.txt');
 +        
 +        $lead = $this->_getLead()->toArray();
 +        $lead['attachments'] = array(array('tempFile' => array('id' => $tempFile->getId())));
 +        
 +        $savedLead = $this->_instance->saveLead($lead);
 +        // add path to files to remove
 +        $this->_objects['paths'][] = Tinebase_FileSystem_RecordAttachments::getInstance()->getRecordAttachmentPath(new Crm_Model_Lead($savedLead, TRUE)) . '/' . $tempFile->name;
 +        
 +        $this->assertTrue(isset($savedLead['attachments']), 'no attachments found');
 +        $this->assertEquals(1, count($savedLead['attachments']));
 +        $attachment = $savedLead['attachments'][0];
 +        $this->assertEquals('text/plain', $attachment['contenttype'], print_r($attachment, TRUE));
 +        $this->assertEquals(17, $attachment['size']);
 +        $this->assertTrue(is_array($attachment['created_by']), 'user not resolved: ' . print_r($attachment['created_by'], TRUE));
 +        $this->assertEquals(Tinebase_Core::getUser()->accountFullName, $attachment['created_by']['accountFullName'], 'user not resolved: ' . print_r($attachment['created_by'], TRUE));
 +        
 +        return $savedLead;
 +    }
 +    
 +    /**
 +     * testUpdateLeadWithAttachment
 +     * 
 +     * @see 0005024: allow to attach external files to records
 +     */
 +    public function testUpdateLeadWithAttachment()
 +    {
 +        $lead = $this->testCreateLeadWithAttachment();
 +        $savedLead = $this->_instance->saveLead($lead);
 +        $this->assertTrue(isset($savedLead['attachments']), 'no attachments found');
 +        $this->assertEquals(1, count($savedLead['attachments']));
 +    }
 +    
 +    /**
 +     * testRemoveAttachmentFromLead
 +     * 
 +     * @see 0005024: allow to attach external files to records
 +     */
 +    public function testRemoveAttachmentFromLead()
 +    {
 +        $lead = $this->testCreateLeadWithAttachment();
 +        $lead['attachments'] = array();
 +    
 +        $savedLead = $this->_instance->saveLead($lead);
 +        $this->assertEquals(0, count($savedLead['attachments']));
 +        $this->assertFalse($this->_fsController->fileExists($this->_objects['paths'][0]));
 +    }
 +    
 +    /**
 +     * testDeleteLeadWithAttachment
 +     * 
 +     * @see 0005024: allow to attach external files to records
 +     */
 +    public function testDeleteLeadWithAttachment()
 +    {
 +        $lead = $this->testCreateLeadWithAttachment();
 +        $this->_instance->deleteLeads(array($lead['id']));
 +        $this->assertFalse($this->_fsController->fileExists($this->_objects['paths'][0]));
 +    }
+     /**
+      * test saving lead with empty start date
+      * 
+      * @see 0009602: CRM should cope with empty start of leads
+      */
+     public function testEmptyStart()
+     {
+         $leadArray = $this->_getLead()->toArray();
+         $leadArray['start'] = null;
+         $newLead = $this->_instance->saveLead($leadArray);
+         
+         $this->assertContains(Tinebase_DateTime::now()->format('Y-m-d'), $newLead['start'], 'start should be set to now if missing');
+     }
  }
Simple merge