function PathfilterTestCase::uploadNodeFile in Path Filter 6
Upload a file to a node.
File
- tests/
pathfilter.test, line 49 - Tests for Path Filter
Class
Code
function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE) {
$edit = array(
'title' => $this
->randomName(),
'revision' => (string) (int) $new_revision,
);
if (is_numeric($nid_or_type)) {
$node = node_load($nid_or_type);
$delta = isset($node->{$field_name}) ? count($node->{$field_name}) : 0;
$edit['files[' . $field_name . '_' . $delta . ']'] = realpath($file->filepath);
$this
->drupalPost('node/' . $nid_or_type . '/edit', $edit, t('Save'));
}
else {
$edit['files[' . $field_name . '_0]'] = realpath($file->filepath);
$type = str_replace('_', '-', $nid_or_type);
$this
->drupalPost('node/add/' . $type, $edit, t('Save'));
}
$matches = array();
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
return $matches[1];
}