JSONTextExtensionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A testExceptionThrownOnBeforeWrite() 0 17 1
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
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