Completed
Push — master ( fc234b...50b50a )
by Matthew
02:02
created

ElementBlogPostsTest::testGetElementSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Elements\Blog\Elements\Tests;
4
5
use Dynamic\Elements\Blog\Elements\ElementBlogPosts;
6
use SilverStripe\Blog\Model\Blog;
7
use SilverStripe\Blog\Model\BlogPost;
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Forms\FieldList;
10
11
class ElementBlogPostsTest extends SapphireTest
12
{
13
    /**
14
     * @var string
15
     */
16
    protected static $fixture_file = '../fixtures.yml';
17
18
    /**
19
     *
20
     */
21
    public function testGetElementSummary()
22
    {
23
        $object = $this->objFromFixture(ElementBlogPosts::class, 'one');
24
        $this->assertEquals($object->ElementSummary(), $object->dbObject("Content")->Summary(20));
25
    }
26
27
    /**
28
     *
29
     */
30
    public function testGetType()
31
    {
32
        $object = $this->objFromFixture(ElementBlogPosts::class, 'one');
33
        $this->assertEquals($object->getType(), 'Blog Posts');
34
    }
35
36
    /**
37
     *
38
     */
39
    public function testGetCMSFields()
40
    {
41
        $object = $this->objFromFixture(ElementBlogPosts::class, 'one');
42
        $fields = $object->getCMSFields();
43
        $this->assertInstanceOf(FieldList::class, $fields);
44
        $this->assertNotNull($fields->dataFieldByName('BlogID'));
45
    }
46
47
    /**
48
     *
49
     */
50
    public function testValidateBlog()
51
    {
52
        $object = $this->objFromFixture(ElementBlogPosts::class, 'one');
53
        $blog = $this->objFromFixture(Blog::class, 'default');
0 ignored issues
show
Unused Code introduced by
The assignment to $blog is dead and can be removed.
Loading history...
54
55
        $valid = $object->validate()->isValid();
56
        $this->assertTrue($valid);
57
        $object->BlogID = 0;
58
        $valid = $object->validate()->isValid();
59
        $this->assertFalse($valid);
60
    }
61
62
    /**
63
     *
64
     */
65
    public function testGetPostsList()
66
    {
67
        $object = $this->objFromFixture(ElementBlogPosts::class, 'one');
68
        $this->assertEquals($object->Blog()->getBlogPosts()->limit($object->Limit), $object->getPostsList());
69
    }
70
}
71