/** * testCreateTempFileWithNonUTF8Filename * * @see 0008184: files with umlauts in filename cannot be attached with safari */ public function testCreateTempFileWithNonUTF8Filename() { $filename = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'brokenname.txt'); $path = tempnam(Tinebase_Core::getTempDir(), 'tine_tempfile_test_'); $tempFile = $this->_instance->createTempFile($path, $filename); $this->assertEquals("_tüt", $tempFile->name); }
/** * get test temp file * * @return Tinebase_TempFile */ protected function _getTempFile() { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile(dirname(__FILE__) . '/Filemanager/files/test.txt'); return $tempFile; }
/** * 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' => $tempFile->toArray())); $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; }
/** * import helper * * @param array $additionalOptions * @param array $clientRecords * @param string $filename * @return array */ protected function _importHelper($additionalOptions = array('dryrun' => 1), $clientRecords = array(), $filename = NULL) { $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_tine_import_csv'); $definitionOptions = Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($definition); $tempFileBackend = new Tinebase_TempFile(); $importFile = $filename ? $filename : dirname(dirname(dirname(dirname(__FILE__)))) . '/tine20/' . $definitionOptions->example; $tempFile = $tempFileBackend->createTempFile($importFile); $options = array_merge($additionalOptions, array('container_id' => $this->container->getId())); $result = $this->_uit->importContacts($tempFile->getId(), $definition->getId(), $options, $clientRecords); if (isset($additionalOptions['dryrun']) && $additionalOptions['dryrun'] === 0) { foreach ($result['results'] as $contact) { $this->_contactIdsToDelete[] = $contact['id']; } } return $result; }
/** * import file * * @param string $_filename * @param Tinebase_Model_ImportExportDefinition $_definition * @param boolean $_useJsonImportFn * @param boolean $removeGroupList * @return array course data */ protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE, $removeGroupList = FALSE) { $definition = $_definition !== NULL ? $_definition : $this->_getCourseImportDefinition(); $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id'])); if ($removeGroupList) { $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']); Addressbook_Controller_List::getInstance()->delete($group->list_id); } if ($_useJsonImportFn) { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile($_filename); Courses_Config::getInstance()->set(Courses_Config::STUDENTS_IMPORT_DEFINITION, $definition->name); $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']); $this->assertGreaterThan(0, $result['results']); } else { $maildomain = TestServer::getPrimaryMailDomain(); $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array('group_id' => $courseData['group_id'], 'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/', 'accountEmailDomain' => $maildomain, 'password' => $courseData['name'], 'samba' => array('homePath' => '//basehome/', 'homeDrive' => 'H:', 'logonScript' => 'logon.bat', 'profilePath' => '\\\\profile\\'))); $tempFilename = TestServer::replaceEmailDomainInFile($_filename); $importer->importFile($tempFilename); } $courseData = $this->_json->getCourse($courseData['id']); return $courseData; }
/** * testInvitationWithAttachment * * @see 0008592: append event file attachments to invitation mail * @see 0009246: Mail address of organizer is broken in invite mails */ public function testInvitationWithAttachment() { $event = $this->_getEvent(TRUE); $event->attendee = $this->_getPersonaAttendee('pwulf'); $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile(dirname(dirname(dirname(__FILE__))) . '/Filemanager/files/test.txt'); $event->attachments = array(array('tempFile' => array('id' => $tempFile->getId()))); self::flushMailer(); $persistentEvent = $this->_eventController->create($event); $messages = self::getMessages(); $this->assertEquals(1, count($messages)); $parts = $messages[0]->getParts(); $this->assertEquals(2, count($parts)); $fileAttachment = $parts[1]; $this->assertEquals('text/plain; name="=?utf-8?Q?tempfile.tmp?="', $fileAttachment->type); // check VEVENT ORGANIZER mailto $vcalendarPart = $parts[0]; $vcalendar = quoted_printable_decode($vcalendarPart->getContent()); $this->assertContains('SENT-BY="mailto:' . Tinebase_Core::getUser()->accountEmailAddress . '":mailto:', str_replace("\r\n ", '', $vcalendar), 'sent-by mailto not quoted'); // @todo assert attachment content (this seems to not work with array mailer, maybe we need a "real" email test here) // $content = $fileAttachment->getDecodedContent(); // $this->assertEquals('test file content', $content); }
/** * tests the recursive filter */ public function testSearchRecursiveFilter() { $fixtures = array(array('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testa', 'color-red.gif'), array('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testb', 'color-green.gif'), array('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testc', 'color-blue.gif')); $tempFileBackend = new Tinebase_TempFile(); foreach ($fixtures as $path) { $node = $this->_json->createNode($path[0], Tinebase_Model_Tree_Node::TYPE_FOLDER, NULL, FALSE); $this->_objects['containerids'][] = $node['name']['id']; $this->assertTrue(is_array($node['name'])); $this->assertEquals(str_replace('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/', '', $path[0]), $node['name']['name']); $this->assertEquals($path[0], $node['path']); $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($node['path']); $filepath = $node['path'] . '/' . $path[1]; // create empty file first (like the js frontend does) $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_Node::TYPE_FILE, array(), FALSE); $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/files/' . $path[1]); $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_Node::TYPE_FILE, $tempFile->getId(), TRUE); } $filter = array(array('field' => 'recursive', 'operator' => 'equals', 'value' => 1), array('field' => 'path', 'operator' => 'equals', 'value' => '/'), array('field' => 'query', 'operator' => 'contains', 'value' => 'color'), 'AND'); $result = $this->_json->searchNodes($filter, array('sort' => 'name', 'start' => 0, 'limit' => 0)); $this->assertEquals(3, count($result), '3 files should have been found!'); }
/** * import file * * @param string $_filename * @param Tinebase_Model_ImportExportDefinition $_definition * @return array course data */ protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE) { $definition = $_definition !== NULL ? $_definition : $this->_getCourseImportDefinition(); $course = $this->_getCourseData(); $courseData = $this->_json->saveCourse($course); $this->_coursesToDelete[] = $courseData['id']; if ($_useJsonImportFn) { $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile($_filename); $this->_json->setConfig(array('import_definition' => 'course_user_import_csv')); $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']); $this->assertGreaterThan(0, $result['results']); } else { $testConfig = Zend_Registry::get('testConfig'); $maildomain = $testConfig->maildomain ? $testConfig->maildomain : 'school.org'; $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array('group_id' => $courseData['group_id'], 'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/', 'accountEmailDomain' => $maildomain, 'password' => $courseData['name'], 'samba' => array('homePath' => '//basehome/', 'homeDrive' => 'H:', 'logonScript' => 'logon.bat', 'profilePath' => '\\\\profile\\'))); $importer->importFile($_filename); } $courseData = $this->_json->getCourse($courseData['id']); return $courseData; }
/** * testCreateFileNodeWithTempfile * * @return array node */ public function testCreateFileNodeWithTempfile() { $sharedContainerNode = $this->testCreateContainerNodeInSharedFolder(); $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($sharedContainerNode['path']); $filepath = $sharedContainerNode['path'] . '/test.txt'; // create empty file first (like the js frontend does) $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_Node::TYPE_FILE, array(), FALSE); $tempFileBackend = new Tinebase_TempFile(); $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/files/test.txt'); $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_Node::TYPE_FILE, $tempFile->getId(), TRUE); $this->assertEquals('text/plain', $result['contenttype'], print_r($result, TRUE)); $this->assertEquals(17, $result['size']); return $result; }