class api_v3_AttachmentTest extends CiviUnitTestCase {
protected static $filePrefix = NULL;
+ /**
+ * @return string
+ */
public static function getFilePrefix() {
if (!self::$filePrefix) {
self::$filePrefix = "test_" . CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_';
\Civi\Core\Container::singleton(TRUE);
}
+ /**
+ * @return array
+ */
public function okCreateProvider() {
$cases = array(); // array($entityClass, $createParams, $expectedContent)
return $cases;
}
+ /**
+ * @return array
+ */
public function badCreateProvider() {
$cases = array(); // array($entityClass, $createParams, $expectedError)
return $cases;
}
+ /**
+ * @return array
+ */
public function badUpdateProvider() {
$cases = array(); // array($entityClass, $createParams, $updateParams, $expectedError)
return $cases;
}
+ /**
+ * @return array
+ */
public function okGetProvider() {
$cases = array(); // array($getParams, $expectedNames)
// Activity #123: example_123.txt (text/plain) and example_123.csv (text/csv)
// Activity #456: example_456.txt (text/plain) and example_456.csv (text/csv)
- $cases[] = array(
- array('entity_table' => 'civicrm_activity'),
- array(
- self::getFilePrefix() . 'example_123.csv',
- self::getFilePrefix() . 'example_123.txt',
- self::getFilePrefix() . 'example_456.csv',
- self::getFilePrefix() . 'example_456.txt',
- ),
- );
- $cases[] = array(
- array('entity_table' => 'civicrm_activity', 'mime_type' => 'text/plain'),
- array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_456.txt'),
- );
+ // NOTE: Searching across multiple records (w/o entity_id) is currently
+ // prohibited by DynamicFKAuthorization. The technique used to authorize requests
+ // does not adapt well to such searches.
+
+ //$cases[] = array(
+ // array('entity_table' => 'civicrm_activity'),
+ // array(
+ // self::getFilePrefix() . 'example_123.csv',
+ // self::getFilePrefix() . 'example_123.txt',
+ // self::getFilePrefix() . 'example_456.csv',
+ // self::getFilePrefix() . 'example_456.txt',
+ // ),
+ //);
+ //$cases[] = array(
+ // array('entity_table' => 'civicrm_activity', 'mime_type' => 'text/plain'),
+ // array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_456.txt'),
+ //);
+
$cases[] = array(
array('entity_table' => 'civicrm_activity', 'entity_id' => '123'),
array(self::getFilePrefix() . 'example_123.txt', self::getFilePrefix() . 'example_123.csv'),
return $cases;
}
+ /**
+ * @return array
+ */
public function badGetProvider() {
$cases = array(); // array($getParams, $expectedNames)
);
$cases[] = array(
array('check_permissions' => 1),
- "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/",
+ "/Mandatory key\\(s\\) missing from params array: 'id' or 'entity_table'/",
);
$cases[] = array(
- array('entity_table' => 'civicrm_activity', 'name' => 'example_456.csv'),
+ array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'name' => 'example_456.csv'),
"/Get by name is not currently supported/",
);
$cases[] = array(
- array('entity_table' => 'civicrm_activity', 'content' => 'test'),
+ array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'content' => 'test'),
"/Get by content is not currently supported/",
);
$cases[] = array(
- array('entity_table' => 'civicrm_activity', 'path' => '/home/foo'),
+ array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'path' => '/home/foo'),
"/Get by path is not currently supported/",
);
$cases[] = array(
- array('entity_table' => 'civicrm_activity', 'url' => '/index.php'),
+ array('entity_table' => 'civicrm_activity', 'entity_id' => '123', 'url' => '/index.php'),
"/Get by url is not currently supported/",
);
}
/**
- * Create an attachment using "content" and then "get" the attachment
+ * Create an attachment using "content" and then "get" the attachment.
*
* @param string $testEntityClass
* E.g. "CRM_Core_DAO_Activity".
$this->assertAttachmentExistence(FALSE, $createResults['delme']['second']);
}
- protected function assertAttachmentExistence($exists, $apiResult) {
- $fileId = $apiResult['id'];
- $this->assertTrue(is_numeric($fileId));
- $this->assertEquals($exists, file_exists($apiResult['values'][$fileId]['path']));
- $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_file WHERE id = %1', array(
- 1 => array($fileId, 'Int'),
- ));
- $this->assertDBQuery($exists ? 1 : 0, 'SELECT count(*) FROM civicrm_entity_file WHERE id = %1', array(
- 1 => array($fileId, 'Int'),
- ));
- }
-
+ /**
+ * @param $name
+ * @return string
+ */
protected function tmpFile($name) {
$tmpDir = sys_get_temp_dir();
$this->assertTrue($tmpDir && is_dir($tmpDir), 'Tmp dir must exist: ' . $tmpDir);
}
}
+
}