Merge pull request #10946 from mattwire/CRM-21037_activity_sendsms_unittests
[civicrm-core.git] / tests / phpunit / api / v3 / AttachmentTest.php
index 09dc385df5c5ca8c2232a7d6cb520908892d0f65..3aef35979489edd18db0d01124d5e2b906b6129f 100644 (file)
@@ -404,6 +404,8 @@ class api_v3_AttachmentTest extends CiviUnitTestCase {
     $fileId = $createResult['id'];
     $this->assertTrue(is_numeric($fileId));
     $this->assertEquals(self::getFilePrefix() . 'weird_na_me.txt', $createResult['values'][$fileId]['name']);
+    // Check for appropriate icon
+    $this->assertEquals('fa-file-text-o', $createResult['values'][$fileId]['icon']);
   }
 
   /**
@@ -552,6 +554,36 @@ class api_v3_AttachmentTest extends CiviUnitTestCase {
     $this->assertAttachmentExistence(FALSE, $createResults['delme']['second']);
   }
 
+  /**
+   * Ensure mime type is converted to appropriate icon.
+   */
+  public function testGetIcon() {
+    $entity = CRM_Core_DAO::createTestObject('CRM_Activity_DAO_Activity');
+    $this->assertTrue(is_numeric($entity->id));
+
+    $createResult = $this->callAPISuccess('Attachment', 'create', array(
+      'name' => self::getFilePrefix() . 'hasIcon.docx',
+      'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+      'description' => 'My test description',
+      'content' => 'My test content',
+      'entity_table' => 'civicrm_activity',
+      'entity_id' => $entity->id,
+    ));
+    $fileId = $createResult['id'];
+    $this->assertEquals('fa-file-word-o', $createResult['values'][$fileId]['icon']);
+
+    $createResult = $this->callAPISuccess('Attachment', 'create', array(
+      'name' => self::getFilePrefix() . 'hasIcon.jpg',
+      'mime_type' => 'image/jpg',
+      'description' => 'My test description',
+      'content' => 'My test content',
+      'entity_table' => 'civicrm_activity',
+      'entity_id' => $entity->id,
+    ));
+    $fileId = $createResult['id'];
+    $this->assertEquals('fa-file-image-o', $createResult['values'][$fileId]['icon']);
+  }
+
   /**
    * @param $name
    * @return string