Skip to content

Commit

Permalink
NEW Add test for FolderFormFactoryExtension with a separate fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Jan 18, 2018
1 parent a0836be commit 4f174ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
34 changes: 34 additions & 0 deletions tests/php/Extensions/FolderFormFactoryExtensionTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions tests/php/Extensions/FolderFormFactoryExtensionTest.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 0 additions & 32 deletions tests/php/FileSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -73,27 +64,4 @@ public function testWritingSubsiteID()
$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));
}
}

0 comments on commit 4f174ff

Please sign in to comment.