2010-10-13 01:02:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Ingo Schommer (ingo at silverstripe dot com)
|
|
|
|
* @todo There's currently no way to save outside of assets/ folder
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-10-13 01:02:10 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class FolderTest extends SapphireTest {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
|
|
|
protected static $fixture_file = 'FileTest.yml';
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCreateFromNameAndParentIDSetsFilename() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1 = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$newFolder = new Folder();
|
|
|
|
$newFolder->Name = 'CreateFromNameAndParentID';
|
|
|
|
$newFolder->ParentID = $folder1->ID;
|
|
|
|
$newFolder->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertEquals($folder1->Filename . 'CreateFromNameAndParentID/', $newFolder->Filename);
|
2010-10-13 01:02:10 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testAllChildrenIncludesFolders() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1 = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$subfolder1 = $this->objFromFixture('Folder', 'folder1-subfolder1');
|
|
|
|
$file1 = $this->objFromFixture('File', 'file1-folder1');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$children = $folder1->allChildren();
|
|
|
|
$this->assertEquals(2, $children->Count());
|
|
|
|
$this->assertContains($subfolder1->ID, $children->column('ID'));
|
|
|
|
$this->assertContains($file1->ID, $children->column('ID'));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFindOrMake() {
|
2010-10-13 01:02:10 +02:00
|
|
|
$path = '/FolderTest/testFindOrMake/';
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
2010-10-13 01:02:10 +02:00
|
|
|
$this->assertEquals(ASSETS_DIR . $path,$folder->getRelativePath(),
|
|
|
|
'Nested path information is correctly saved to database (with trailing slash)'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(file_exists(ASSETS_PATH . $path), 'File');
|
2013-06-21 00:32:08 +02:00
|
|
|
$parentFolder = DataObject::get_one('Folder', array(
|
|
|
|
'"File"."Name"' => 'FolderTest'
|
|
|
|
));
|
2010-10-13 01:02:10 +02:00
|
|
|
$this->assertNotNull($parentFolder);
|
|
|
|
$this->assertEquals($parentFolder->ID, $folder->ParentID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:21:41 +02:00
|
|
|
$path = '/FolderTest/testFindOrMake'; // no trailing slash
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
2010-10-13 01:02:10 +02:00
|
|
|
$this->assertEquals(ASSETS_DIR . $path . '/',$folder->getRelativePath(),
|
|
|
|
'Path information is correctly saved to database (without trailing slash)'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:21:41 +02:00
|
|
|
$path = '/assets/'; // relative to "assets/" folder, should produce "assets/assets/"
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
2010-10-15 05:21:41 +02:00
|
|
|
$this->assertEquals(ASSETS_DIR . $path,$folder->getRelativePath(),
|
|
|
|
'A folder named "assets/" within "assets/" is allowed'
|
|
|
|
);
|
2010-10-13 01:02:10 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testSetNameChangesFilesystemOnWrite()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSetNameChangesFilesystemOnWrite() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1 = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$subfolder1 = $this->objFromFixture('Folder', 'folder1-subfolder1');
|
|
|
|
$file1 = $this->objFromFixture('File', 'file1-folder1');
|
|
|
|
$oldPathFolder1 = $folder1->getFullPath();
|
|
|
|
$oldPathSubfolder1 = $subfolder1->getFullPath();
|
|
|
|
$oldPathFile1 = $file1->getFullPath();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Before write()
|
|
|
|
$folder1->Name = 'FileTest-folder1-renamed';
|
|
|
|
$this->assertFileExists($oldPathFolder1, 'Old path is still present');
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertFileNotExists($folder1->getFullPath(),
|
|
|
|
'New path is updated in memory, not written before write() is called');
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileExists($oldPathFile1, 'Old file is still present');
|
|
|
|
// TODO setters currently can't update in-memory
|
2012-09-26 23:34:00 +02:00
|
|
|
// $this->assertFileNotExists($file1->getFullPath(),
|
|
|
|
// 'New path on contained files is updated in memory, not written before write() is called');
|
|
|
|
// $this->assertFileNotExists($subfolder1->getFullPath(),
|
|
|
|
// 'New path on subfolders is updated in memory, not written before write() is called');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// After write()
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Reload state
|
|
|
|
clearstatcache();
|
|
|
|
DataObject::flush_and_destroy_cache();
|
|
|
|
$folder1 = DataObject::get_by_id('Folder', $folder1->ID);
|
|
|
|
$file1 = DataObject::get_by_id('File', $file1->ID);
|
|
|
|
$subfolder1 = DataObject::get_by_id('Folder', $subfolder1->ID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileNotExists($oldPathFolder1, 'Old path is removed after write()');
|
|
|
|
$this->assertFileExists($folder1->getFullPath(), 'New path is created after write()');
|
|
|
|
$this->assertFileNotExists($oldPathFile1, 'Old file is removed after write()');
|
|
|
|
$this->assertFileExists($file1->getFullPath(), 'New file path is created after write()');
|
|
|
|
$this->assertFileNotExists($oldPathSubfolder1, 'Subfolder is removed after write()');
|
|
|
|
$this->assertFileExists($subfolder1->getFullPath(), 'New subfolder path is created after write()');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Clean up after ourselves - tearDown() doesn't like renamed fixtures
|
|
|
|
$folder1->delete(); // implicitly deletes subfolder as well
|
2010-10-13 05:48:33 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testSetParentIDChangesFilesystemOnWrite()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testSetParentIDChangesFilesystemOnWrite() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1 = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$folder2 = $this->objFromFixture('Folder', 'folder2');
|
|
|
|
$oldPathFolder1 = $folder1->getFullPath();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// set ParentID
|
|
|
|
$folder1->ParentID = $folder2->ID;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Before write()
|
|
|
|
$this->assertFileExists($oldPathFolder1, 'Old path is still present');
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertFileNotExists($folder1->getFullPath(),
|
|
|
|
'New path is updated in memory, not written before write() is called');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder1->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// After write()
|
|
|
|
clearstatcache();
|
|
|
|
$this->assertFileNotExists($oldPathFolder1, 'Old path is removed after write()');
|
|
|
|
$this->assertFileExists($folder1->getFullPath(), 'New path is created after write()');
|
|
|
|
}
|
2010-10-19 06:00:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the bug #5994 - Moving folder after executing Folder::findOrMake will not set the Filenames properly
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFindOrMakeFolderThenMove() {
|
2010-10-19 06:00:57 +02:00
|
|
|
$folder1 = $this->objFromFixture('Folder', 'folder1');
|
2011-12-06 01:56:24 +01:00
|
|
|
Folder::find_or_make($folder1->Filename);
|
2010-10-19 06:00:57 +02:00
|
|
|
$folder2 = $this->objFromFixture('Folder', 'folder2');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-19 06:00:57 +02:00
|
|
|
// set ParentID
|
|
|
|
$folder1->ParentID = $folder2->ID;
|
|
|
|
$folder1->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-19 06:00:57 +02:00
|
|
|
// Check if the file in the folder moved along
|
|
|
|
$file1 = DataObject::get_by_id('File', $this->idFromFixture('File', 'file1-folder1'), false);
|
|
|
|
$this->assertFileExists($file1->getFullPath());
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($file1->Filename, 'assets/FileTest-folder2/FileTest-folder1/File1.txt',
|
|
|
|
'The file DataObject has updated path');
|
2010-10-19 06:00:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for the bug #5994 - if you don't execute get_by_id prior to the rename or move, it will fail.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRenameFolderAndCheckTheFile() {
|
2010-10-19 06:52:20 +02:00
|
|
|
// ID is prefixed in case Folder is subclassed by project/other module.
|
2013-06-21 00:32:08 +02:00
|
|
|
$folder1 = DataObject::get_one('Folder', array(
|
|
|
|
'"File"."ID"' => $this->idFromFixture('Folder', 'folder1')
|
|
|
|
));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-19 06:00:57 +02:00
|
|
|
$folder1->Name = 'FileTest-folder1-changed';
|
|
|
|
$folder1->write();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-19 06:00:57 +02:00
|
|
|
// Check if the file in the folder moved along
|
|
|
|
$file1 = DataObject::get_by_id('File', $this->idFromFixture('File', 'file1-folder1'), false);
|
|
|
|
$this->assertFileExists($file1->getFullPath());
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($file1->Filename, 'assets/FileTest-folder1-changed/File1.txt',
|
|
|
|
'The file DataObject path uses renamed folder');
|
2010-10-19 06:00:57 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testLinkAndRelativeLink()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testLinkAndRelativeLink() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$this->assertEquals(ASSETS_DIR . '/FileTest-folder1/', $folder->RelativeLink());
|
|
|
|
$this->assertEquals(Director::baseURL() . ASSETS_DIR . '/FileTest-folder1/', $folder->Link());
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testGetRelativePath()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetRelativePath() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$rootfolder = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$this->assertEquals('assets/FileTest-folder1/', $rootfolder->getRelativePath(), 'Folder in assets/');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testGetFullPath()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetFullPath() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$rootfolder = $this->objFromFixture('Folder', 'folder1');
|
|
|
|
$this->assertEquals(ASSETS_PATH . '/FileTest-folder1/', $rootfolder->getFullPath(), 'File in assets/ folder');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDeleteAlsoRemovesFilesystem() {
|
2014-08-15 08:53:05 +02:00
|
|
|
$path = '/FolderTest/DeleteAlsoRemovesFilesystemAndChildren';
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileExists(ASSETS_PATH . $path);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder->delete();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileNotExists(ASSETS_PATH . $path);
|
2010-10-13 05:48:33 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDeleteAlsoRemovesSubfoldersInDatabaseAndFilesystem() {
|
2014-08-15 08:53:05 +02:00
|
|
|
$path = '/FolderTest/DeleteAlsoRemovesSubfoldersInDatabaseAndFilesystem';
|
2010-10-15 05:20:47 +02:00
|
|
|
$subfolderPath = $path . '/subfolder';
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
|
|
|
$subfolder = Folder::find_or_make($subfolderPath);
|
2010-10-15 05:20:47 +02:00
|
|
|
$subfolderID = $subfolder->ID;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder->delete();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileNotExists(ASSETS_PATH . $path);
|
|
|
|
$this->assertFileNotExists(ASSETS_PATH . $subfolderPath, 'Subfolder removed from filesystem');
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Folder', $subfolderID), 'Subfolder removed from database');
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDeleteAlsoRemovesContainedFilesInDatabaseAndFilesystem() {
|
2014-08-15 08:53:05 +02:00
|
|
|
$path = '/FolderTest/DeleteAlsoRemovesContainedFilesInDatabaseAndFilesystem';
|
2011-12-06 01:56:24 +01:00
|
|
|
$folder = Folder::find_or_make($path);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$file = $this->objFromFixture('File', 'gif');
|
|
|
|
$file->ParentID = $folder->ID;
|
|
|
|
$file->write();
|
|
|
|
$fileID = $file->ID;
|
|
|
|
$fileAbsPath = $file->getFullPath();
|
|
|
|
$this->assertFileExists($fileAbsPath);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$folder->delete();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileNotExists($fileAbsPath, 'Contained files removed from filesystem');
|
|
|
|
$this->assertFalse(DataObject::get_by_id('File', $fileID), 'Contained files removed from database');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/**
|
|
|
|
* @see FileTest->testDeleteDatabaseOnly()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDeleteDatabaseOnly() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$subfolder = $this->objFromFixture('Folder', 'subfolder');
|
|
|
|
$subfolderID = $subfolder->ID;
|
|
|
|
$subfolderFile = $this->objFromFixture('File', 'subfolderfile');
|
|
|
|
$subfolderFileID = $subfolderFile->ID;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$subfolder->deleteDatabaseOnly();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
DataObject::flush_and_destroy_cache();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileExists($subfolder->getFullPath());
|
|
|
|
$this->assertFalse(DataObject::get_by_id('Folder', $subfolderID));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
$this->assertFileExists($subfolderFile->getFullPath());
|
|
|
|
$this->assertFalse(DataObject::get_by_id('File', $subfolderFileID));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
2010-10-15 05:20:47 +02:00
|
|
|
parent::setUp();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
if(!file_exists(ASSETS_PATH)) mkdir(ASSETS_PATH);
|
|
|
|
|
|
|
|
// Create a test folders for each of the fixture references
|
|
|
|
$folderIDs = $this->allFixtureIDs('Folder');
|
|
|
|
foreach($folderIDs as $folderID) {
|
|
|
|
$folder = DataObject::get_by_id('Folder', $folderID);
|
|
|
|
if(!file_exists(BASE_PATH."/$folder->Filename")) mkdir(BASE_PATH."/$folder->Filename");
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Create a test files for each of the fixture references
|
|
|
|
$fileIDs = $this->allFixtureIDs('File');
|
|
|
|
foreach($fileIDs as $fileID) {
|
|
|
|
$file = DataObject::get_by_id('File', $fileID);
|
|
|
|
$fh = fopen(BASE_PATH."/$file->Filename", "w");
|
|
|
|
fwrite($fh, str_repeat('x',1000000));
|
|
|
|
fclose($fh);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2010-10-15 05:20:47 +02:00
|
|
|
$testPath = ASSETS_PATH . '/FolderTest';
|
|
|
|
if(file_exists($testPath)) Filesystem::removeFolder($testPath);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
/* Remove the test files that we've created */
|
|
|
|
$fileIDs = $this->allFixtureIDs('File');
|
|
|
|
foreach($fileIDs as $fileID) {
|
|
|
|
$file = DataObject::get_by_id('File', $fileID);
|
|
|
|
if($file && file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename");
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
// Remove the test folders that we've crated
|
|
|
|
$folderIDs = $this->allFixtureIDs('Folder');
|
|
|
|
foreach($folderIDs as $folderID) {
|
|
|
|
$folder = DataObject::get_by_id('Folder', $folderID);
|
|
|
|
// Might have been removed during test
|
2012-09-26 23:34:00 +02:00
|
|
|
if($folder && file_exists(BASE_PATH."/$folder->Filename")) {
|
|
|
|
Filesystem::removeFolder(BASE_PATH."/$folder->Filename");
|
|
|
|
}
|
2010-10-15 05:20:47 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2010-10-15 05:20:47 +02:00
|
|
|
parent::tearDown();
|
|
|
|
}
|
2013-05-11 05:07:12 +02:00
|
|
|
|
|
|
|
public function testSyncedChildren() {
|
|
|
|
mkdir(ASSETS_PATH ."/FolderTest");
|
|
|
|
mkdir(ASSETS_PATH ."/FolderTest/sync");
|
|
|
|
|
|
|
|
$files = array(
|
|
|
|
'.htaccess',
|
|
|
|
'.git',
|
|
|
|
'web.config',
|
|
|
|
'.DS_Store',
|
2014-04-09 07:37:25 +02:00
|
|
|
'_my_synced_file.txt',
|
|
|
|
'invalid_extension.xyz123'
|
2013-05-11 05:07:12 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$folders = array(
|
|
|
|
'_combinedfiles',
|
|
|
|
'_resampled',
|
|
|
|
'_testsync'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($files as $file) {
|
|
|
|
$fh = fopen(ASSETS_PATH."/FolderTest/sync/$file", "w");
|
|
|
|
fwrite($fh, 'test');
|
|
|
|
fclose($fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($folders as $folder) {
|
|
|
|
mkdir(ASSETS_PATH ."/FolderTest/sync/". $folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
$folder = Folder::find_or_make('/FolderTest/sync');
|
|
|
|
$result = $folder->syncChildren();
|
|
|
|
|
2014-04-09 07:37:25 +02:00
|
|
|
$this->assertEquals(11, $result['skipped']);
|
2013-05-11 05:07:12 +02:00
|
|
|
$this->assertEquals(2, $result['added']);
|
|
|
|
|
|
|
|
// folder with a path of _test should exist
|
|
|
|
$this->assertEquals(1, Folder::get()->filter(array(
|
|
|
|
'Name' => '_testsync'
|
|
|
|
))->count());
|
|
|
|
|
|
|
|
$this->assertEquals(1, File::get()->filter(array(
|
|
|
|
'Name' => '_my_synced_file.txt'
|
|
|
|
))->count());
|
2014-04-09 07:37:25 +02:00
|
|
|
|
|
|
|
$this->assertEquals(0, File::get()->filter(array(
|
|
|
|
'Name' => 'invalid_extension.xyz123'
|
|
|
|
))->count());
|
2013-05-11 05:07:12 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-02-20 02:03:40 +01:00
|
|
|
public function testIllegalFilenames() {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-02-20 02:03:40 +01:00
|
|
|
// Test that generating a filename with invalid characters generates a correctly named folder.
|
|
|
|
$folder = Folder::find_or_make('/FolderTest/EN_US Lang');
|
|
|
|
$this->assertEquals(ASSETS_DIR.'/FolderTest/EN-US-Lang/', $folder->getRelativePath());
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-02-20 02:03:40 +01:00
|
|
|
// Test repeatitions of folder
|
|
|
|
$folder2 = Folder::find_or_make('/FolderTest/EN_US Lang');
|
|
|
|
$this->assertEquals($folder->ID, $folder2->ID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-02-20 02:03:40 +01:00
|
|
|
$folder3 = Folder::find_or_make('/FolderTest/EN--US_L!ang');
|
|
|
|
$this->assertEquals($folder->ID, $folder3->ID);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-02-20 02:03:40 +01:00
|
|
|
$folder4 = Folder::find_or_make('/FolderTest/EN-US-Lang');
|
|
|
|
$this->assertEquals($folder->ID, $folder4->ID);
|
|
|
|
}
|
2014-05-02 04:41:10 +02:00
|
|
|
|
|
|
|
public function testTitleTiedToName() {
|
|
|
|
$newFolder = new Folder();
|
|
|
|
|
|
|
|
$newFolder->Name = 'TestNameCopiedToTitle';
|
|
|
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
|
|
|
|
|
|
|
$newFolder->Title = 'TestTitleCopiedToName';
|
|
|
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
|
|
|
|
|
|
|
$newFolder->Name = 'TestNameWithIllegalCharactersCopiedToTitle <!BANG!>';
|
|
|
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
|
|
|
|
|
|
|
$newFolder->Title = 'TestTitleWithIllegalCharactersCopiedToName <!BANG!>';
|
|
|
|
$this->assertEquals($newFolder->Name, $newFolder->Title);
|
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|