Completed
Push — master ( 81e087...6d49c7 )
by Russell
09:00 queued 03:18
created

JSONTextExtensionTest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
use PhpTek\JSONText\Exception\JSONTextException;
10
use SilverStripe\Dev\FunctionalTest;
11
use SilverStripe\Security\Member;
12
use PhpTek\JSONText\Dev\Fixture\MyAwesomeJSONPage;
13
14
class JSONTextExtensionTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $extra_dataobjects = [
20
        MyAwesomeJSONPage::class,
21
    ];
22
    
23
    /**
24
     * @var string
25
     */
26
    protected static $fixture_file;
27
    
28
    /**
29
     * Modifies fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows
30
     */
31
    public function __construct()
32
    {
33
        $dir = realpath(__DIR__);
34
        
35
        self::$fixture_file = $dir . '/fixtures/yml/JSONTextExtension.yml';
36
        
37
        parent::__construct();
38
    }
39
    
40
    /**
41
     * Is an exception thrown when no POSTed vars are available for
42
     * non DB-backed fields declared on a SiteTree class?
43
     */
44
    public function testExceptionThrownOnBeforeWrite()
45
    {
46
        $member = $this->objFromFixture(Member::class, 'admin');
47
        $fixture = $this->objFromFixture(MyAwesomeJSONPage::class, 'dummy');
48
        
49
        $member->logIn();
50
        $fixture->config()->update('json_field_map', ['MyJSON' => ['FooField']]);
51
        $fixture->write();
52
        
53
        // Submit a CMS POST request _without_ JSON data
54
        $this->setExpectedException(JSONTextException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
55
        $this->post('admin/pages/edit/EditForm/44/', [
56
            'ParentID' => '0',
57
            'action_save' => 'Saved',
58
            'ID' => '44',
59
        ]);
60
    }
61
}
62