Passed
Push — nested-vendor ( f8843a )
by Sam
09:43
created

DefaultFormFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFormThrowsExceptionOnMissingContext() 0 4 1
A testGetForm() 0 9 1
A testGetRequiredContext() 0 4 1
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use InvalidArgumentException;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\Forms\DefaultFormFactory;
8
use SilverStripe\ORM\DataObject;
9
10
class DefaultFormFactoryTest extends SapphireTest
11
{
12
    /**
13
     * @expectedException InvalidArgumentException
14
     * @expectedExceptionMessageRegExp /Missing required context/
15
     */
16
    public function testGetFormThrowsExceptionOnMissingContext()
17
    {
18
        $factory = new DefaultFormFactory();
19
        $factory->getForm();
20
    }
21
22
    public function testGetForm()
23
    {
24
        $record = new DataObject();
25
        $record->Title = 'Test';
26
27
        $factory = new DefaultFormFactory();
28
        $form = $factory->getForm(null, null, ['Record' => $record]);
29
30
        $this->assertSame($record, $form->getRecord());
31
    }
32
33
    public function testGetRequiredContext()
34
    {
35
        $factory = new DefaultFormFactory();
36
        $this->assertContains('Record', $factory->getRequiredContext());
37
    }
38
}
39