NEW Add test for FolderFormFactoryExtension with a separate fixture

This commit is contained in:
Robbie Averill 2018-01-18 16:22:35 +13:00
parent a0836bed79
commit 4f174ffd6e
3 changed files with 45 additions and 32 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace SilverStripe\Subsites\Tests\Extensions;
use SilverStripe\AssetAdmin\Forms\FolderFormFactory;
use SilverStripe\Assets\Folder;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormFactory;
class FolderFormFactoryExtensionTest extends SapphireTest
{
protected static $fixture_file = 'FolderFormFactoryExtensionTest.yml';
public function testSubsitesFolderDropdown()
{
$this->logInWithPermission('ADMIN');
/** @var Folder $folder */
$folder = $this->objFromFixture(Folder::class, 'folder_a');
/** @var Form $folderForm */
$folderForm = FolderFormFactory::create()->getForm(null, FormFactory::DEFAULT_NAME, [
'Record' => $folder
]);
$source = array_values($folderForm->Fields()->fieldByName('SubsiteID')->getSource());
$result = array_values($source);
$this->assertContains('Main site', $result);
$this->assertContains('Subsite A', $result);
$this->assertContains('Subsite B', $result);
}
}

View File

@ -0,0 +1,11 @@
SilverStripe\Subsites\Model\Subsite:
main:
Title: Template
subsite_a:
Title: Subsite A
subsite_b:
Title: Subsite B
SilverStripe\Assets\Folder:
folder_a:
Title: Folder A

View File

@ -12,15 +12,6 @@ class FileSubsitesTest extends BaseSubsiteTest
{
protected static $fixture_file = 'SubsiteTest.yml';
/**
* Disable other file extensions
*
* @var array
*/
protected static $illegal_extensions = [
SiteTree::class => ['Translatable'], // @todo implement namespace for Translatable
];
public function testTrivialFeatures()
{
$this->assertTrue(is_array(singleton(FileSubsites::class)->extraStatics()));
@ -73,27 +64,4 @@ class FileSubsitesTest extends BaseSubsiteTest
$file->onAfterUpload();
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}
public function testSubsitesFolderDropdown()
{
$this->logInAs('admin');
$file = new Folder();
$source = array_values($file->getCMSFields()->dataFieldByName('SubsiteID')->getSource());
asort($source);
$this->assertEquals([
'Main site',
'Subsite1 Template',
'Subsite2 Template',
'Template',
'Test 1',
'Test 2',
'Test 3',
'Test Non-SSL',
'Test SSL',
'Test Vagrant VM on port 8080'
], array_values($source));
}
}