RecipeIngredientTest::testGetCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Dynamic\RecipeBook\Test\Model;
4
5
use Dynamic\RecipeBook\Model\RecipeIngredient;
6
use Dynamic\RecipeBook\Page\RecipePage;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\ORM\ValidationException;
10
11
class RecipeIngredientTest extends SapphireTest
12
{
13
    /**
14
     * @var string
15
     */
16
    protected static $fixture_file = '../fixtures.yml';
17
18
    /**
19
     *
20
     */
21
    public function testGetCMSFields()
22
    {
23
        $object = $this->objFromFixture(RecipeIngredient::class, 'one');
24
        $fields = $object->getCMSFields();
25
        $this->assertInstanceOf(FieldList::class, $fields);
26
    }
27
28
    /**
29
     * @throws ValidationException
30
     */
31
    public function testDefaultSortValue()
32
    {
33
        $recipe = $this->objFromFixture(RecipePage::class, 'two');
34
35
        $ingredient = RecipeIngredient::create();
36
        $ingredient->Title = 'My First Ingredient';
37
        $ingredient->RecipeID = $recipe->ID;
38
39
        $this->assertEquals(0, $ingredient->Sort);
40
41
        $ingredient->write();
42
43
        $this->assertNotEquals(0, $ingredient->Sort);
44
45
        $ingredient2 = RecipeIngredient::create();
46
        $ingredient2->Title = 'My Second Ingredient';
47
        $ingredient2->RecipeID = $recipe->ID;
48
49
        $this->assertEquals(0, $ingredient2->Sort);
50
51
        $ingredient2->write();
52
53
        $this->assertGreaterThan($ingredient->Sort, $ingredient2->Sort);
54
    }
55
}
56