From bd2d492f2616489a40a0f3ed90ea5e6558117fc8 Mon Sep 17 00:00:00 2001 From: nickw Date: Tue, 27 Oct 2009 21:58:25 +0000 Subject: Modifying user file locations to be based on guid. Previous implementations utilized the owner's username to determine a file path matrix based on (up to) the first five letters. To eliminate language and filesystem inconsistencies, the matrix is now created from the entity's creation date and guid. This has the added benefit of (potentially) allowing users to update their usernames. git-svn-id: http://code.elgg.org/elgg/trunk@3590 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/tests/objects/filestore.php | 106 +++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 engine/tests/objects/filestore.php (limited to 'engine/tests/objects/filestore.php') diff --git a/engine/tests/objects/filestore.php b/engine/tests/objects/filestore.php new file mode 100644 index 000000000..76583a463 --- /dev/null +++ b/engine/tests/objects/filestore.php @@ -0,0 +1,106 @@ +filestore = new ElggDiskFilestoreTest(); + } + + /** + * Called after each test method. + */ + public function tearDown() { + // do not allow SimpleTest to interpret Elgg notices as exceptions + $this->swallowErrors(); + + unset($this->filestore); + } + + /** + * Called after each test object. + */ + public function __destruct() { + // all code should go above here + parent::__destruct(); + } + + public function testFileMatrix() { + global $CONFIG; + + // create a test user + $user = $this->createTestUser(); + $created = date('Y/m/d', $user->time_created); + + // check matrix with username + $user_dir = $this->filestore->make_file_matrix($user->username); + $this->assertIdentical($user_dir, "f/i/l/e/T/fileTest/"); + + // check matrix with guid + $guid_dir = $this->filestore->make_file_matrix($user->guid); + $this->assertIdentical($guid_dir, "$created/$user->guid/"); + $this->dump($user_dir);$this->dump($guid_dir); + + // clean up user + $user->delete(); + } + + public function testFilenameOnFilestore() { + global $CONFIG; + + // create a user to own the file + $user = $this->createTestUser(); + $created = date('Y/m/d', $user->time_created); + + // setup a test file; no need to save + $file = new ElggFile(); + $file->owner_guid = $user->guid; + $file->setFilename('testing/filestore.txt'); + + // ensure filename and path is expected + $filename = $file->getFilenameOnFilestore($file); + $filepath = "$CONFIG->dataroot$created/$user->guid/testing/filestore.txt"; + $this->assertIdentical($filename, $filepath); + + // clean up user + $user->delete(); + } + + + protected function createTestUser($username = 'fileTest') { + $user = new ElggUser(); + $user->username = $username; + $guid = $user->save(); + + // load user to have access to creation time + return get_entity($guid); + } +} + +class ElggDiskFilestoreTest extends ElggDiskFilestore { + public function make_file_matrix($filename) { + return parent::make_file_matrix($filename); + } + + public function user_file_matrix($guid) { + return parent::user_file_matrix($guid); + } +} -- cgit v1.2.3