Skip to content

Commit

Permalink
NEW Add a couple of basic test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Dec 18, 2017
1 parent e5a2f76 commit 8f79e65
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/DocumentConverterDecoratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

class DocumentConverterDecoratorTest extends SapphireTest
{
protected $requiredExtensions = array(
'SiteTree' => array(
'DocumentConverterDecorator',
),
);

public function testFieldListHasDocumentImportField()
{
$fields = (new SiteTree)->getCMSFields();
$this->assertInstanceOf(
'DocumentImportField',
$fields->fieldByName('Root.Import')->Fields()->First()
);
}
}
51 changes: 51 additions & 0 deletions tests/DocumentImportFieldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

class DocumentImportFieldTest extends SapphireTest
{
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsExceptionWhenGivenString()
{
new DocumentImportField('exception time!');
}

/**
* @expectedException InvalidArgumentException
*/
public function testConstructorThrowsExceptionWhenGivenChildren()
{
new DocumentImportField(['i', 'don\'t', 'like', 'kids']);
}

public function testFieldAddsJavascriptRequirements()
{
// Start with a clean slate (no global state interference)
Requirements::backend()->clear();

new DocumentImportField();
$javascript = Requirements::backend()->get_javascript();
$this->assertNotEmpty($javascript);
}

public function testFieldListGeneration()
{
$importField = new DocumentImportField();

$fields = $importField->getChildren();
$this->assertInstanceOf('FieldList', $fields);

// We don't need to check that all of the fields are there, but just check a couple
$this->assertInstanceOf('HeaderField', $fields->fieldByName('FileWarningHeader'));
$innerField = $fields->fieldByName('ImportedFromFile');
$this->assertInstanceOf('DocumentImportInnerField', $innerField);

// Check the getter works
$this->assertSame($innerField, $importField->getInnerField());

// Check the fields have been given has the change tracker disabled
$splitHeader = $fields->fieldByName('DocumentImportField-SplitHeader');
$this->assertInstanceOf('DropdownField', $splitHeader);
$this->assertContains('no-change-track', $splitHeader->extraClass());
}
}

0 comments on commit 8f79e65

Please sign in to comment.