2010-03-21 23:32:22 +01:00
|
|
|
<?php
|
|
|
|
|
2017-04-23 22:23:34 +02:00
|
|
|
namespace SilverStripe\Subsites\Tests;
|
|
|
|
|
2016-09-22 16:38:29 +02:00
|
|
|
use SilverStripe\Assets\File;
|
|
|
|
use SilverStripe\Assets\Folder;
|
2017-05-24 15:26:28 +02:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-05-29 13:42:42 +02:00
|
|
|
use SilverStripe\Security\Member;
|
2017-05-30 15:14:28 +02:00
|
|
|
use SilverStripe\Subsites\Extensions\FileSubsites;
|
2017-05-24 15:25:34 +02:00
|
|
|
use SilverStripe\Subsites\Model\Subsite;
|
|
|
|
|
2017-05-24 15:26:28 +02:00
|
|
|
class FileSubsitesTest extends BaseSubsiteTest
|
|
|
|
{
|
2017-04-23 22:23:34 +02:00
|
|
|
|
2017-05-30 15:14:28 +02:00
|
|
|
public static $fixture_file = 'subsites/tests/php/SubsiteTest.yml';
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable other file extensions
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-06-01 15:57:53 +02:00
|
|
|
protected $illegalExtensions = [
|
|
|
|
'File' => [
|
2017-05-29 13:42:42 +02:00
|
|
|
'SecureFileExtension',
|
|
|
|
'VersionedFileExtension'
|
2017-06-01 15:57:53 +02:00
|
|
|
],
|
|
|
|
'SiteTree' => [
|
2017-04-23 22:23:34 +02:00
|
|
|
'Translatable',
|
2017-06-01 15:57:53 +02:00
|
|
|
]
|
|
|
|
];
|
2017-05-29 13:42:42 +02:00
|
|
|
|
|
|
|
public function testTrivialFeatures()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-05-30 15:14:28 +02:00
|
|
|
$this->assertTrue(is_array(singleton(FileSubsites::class)->extraStatics()));
|
2017-05-24 15:26:28 +02:00
|
|
|
$file = new File();
|
|
|
|
$file->Name = 'FileTitle';
|
|
|
|
$file->Title = 'FileTitle';
|
|
|
|
$this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
|
2017-05-30 15:14:28 +02:00
|
|
|
$file->SubsiteID = $this->objFromFixture(Subsite::class, 'domaintest1')->ID;
|
2017-05-24 15:26:28 +02:00
|
|
|
$this->assertEquals('FileTitle', $file->getTreeTitle());
|
2017-06-01 15:12:18 +02:00
|
|
|
$this->assertInstanceOf(FieldList::class, singleton(Folder::class)->getCMSFields());
|
2017-05-24 15:26:28 +02:00
|
|
|
Subsite::changeSubsite(1);
|
2017-05-30 15:15:54 +02:00
|
|
|
$this->assertEquals('subsite-1', $file->getExtensionInstance(FileSubsites::class)->cacheKeyComponent());
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function testWritingSubsiteID()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->objFromFixture(Member::class, 'admin')->logIn();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
2017-05-30 15:14:28 +02:00
|
|
|
$subsite = $this->objFromFixture(Subsite::class, 'domaintest1');
|
2017-05-24 15:26:28 +02:00
|
|
|
FileSubsites::$default_root_folders_global = true;
|
|
|
|
|
|
|
|
Subsite::changeSubsite(0);
|
|
|
|
$file = new File();
|
|
|
|
$file->write();
|
|
|
|
$file->onAfterUpload();
|
|
|
|
$this->assertEquals((int)$file->SubsiteID, 0);
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$this->assertTrue($file->canEdit());
|
|
|
|
|
|
|
|
$file = new File();
|
|
|
|
$file->write();
|
|
|
|
$this->assertEquals((int)$file->SubsiteID, 0);
|
|
|
|
$this->assertTrue($file->canEdit());
|
|
|
|
|
|
|
|
FileSubsites::$default_root_folders_global = false;
|
|
|
|
|
|
|
|
Subsite::changeSubsite($subsite->ID);
|
|
|
|
$file = new File();
|
|
|
|
$file->write();
|
|
|
|
$this->assertEquals($file->SubsiteID, $subsite->ID);
|
|
|
|
|
|
|
|
// Test inheriting from parent folder
|
|
|
|
$folder = new Folder();
|
|
|
|
$folder->write();
|
|
|
|
$this->assertEquals($folder->SubsiteID, $subsite->ID);
|
|
|
|
FileSubsites::$default_root_folders_global = true;
|
|
|
|
$file = new File();
|
|
|
|
$file->ParentID = $folder->ID;
|
|
|
|
$file->onAfterUpload();
|
|
|
|
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
|
|
|
|
}
|
|
|
|
|
2017-05-29 13:42:42 +02:00
|
|
|
public function testSubsitesFolderDropdown()
|
2017-05-24 15:26:28 +02:00
|
|
|
{
|
2017-05-29 13:42:42 +02:00
|
|
|
$this->objFromFixture(Member::class, 'admin')->logIn();
|
2017-05-24 15:26:28 +02:00
|
|
|
|
|
|
|
$file = new Folder();
|
|
|
|
|
|
|
|
$source = array_values($file->getCMSFields()->dataFieldByName('SubsiteID')->getSource());
|
|
|
|
asort($source);
|
|
|
|
|
2017-06-01 15:57:53 +02:00
|
|
|
$this->assertEquals([
|
2017-05-24 15:26:28 +02:00
|
|
|
'Main site',
|
|
|
|
'Subsite1 Template',
|
|
|
|
'Subsite2 Template',
|
2017-05-29 13:42:42 +02:00
|
|
|
'Template',
|
2017-05-24 15:26:28 +02:00
|
|
|
'Test 1',
|
|
|
|
'Test 2',
|
2017-05-29 13:42:42 +02:00
|
|
|
'Test 3',
|
|
|
|
'Test Non-SSL',
|
|
|
|
'Test SSL',
|
2017-06-01 15:57:53 +02:00
|
|
|
], array_values($source));
|
2017-05-24 15:26:28 +02:00
|
|
|
}
|
2010-03-21 23:32:22 +01:00
|
|
|
}
|