Completed
Push — master ( 4a6357...521c8c )
by Franco
10s
created

ContentReviewBaseTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 19 2
A tearDown() 0 10 3
1
<?php
2
3
namespace SilverStripe\ContentReview\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
use SilverStripe\CMS\Model\SiteTree;
7
// @todo add translatable namespace
8
use Translatable;
9
10
/**
11
 * Extend this class when writing unit tests which are compatible with other modules.
12
 * All compatibility code goes here.
13
 */
14
abstract class ContentReviewBaseTest extends FunctionalTest
15
{
16
    /**
17
     * @var bool
18
     */
19
    protected $translatableEnabledBefore;
20
21
    protected function setUp()
22
    {
23
        parent::setUp();
24
25
        /*
26
         *  We set the locale for pages explicitly, because if we don't, then we get into a situation
27
         *  where the page takes on the tester's (your) locale, and any calls to simulate subsequent requests
28
         *  (e.g. $this->post()) do not seem to get passed the tester's locale, but instead fallback to the default locale.
29
         *
30
         *  So we set the pages locale to be the default locale, which will then match any subsequent requests.
31
         *
32
         *  If creating pages in your unit tests (rather than reading from the fixtures file), you must explicitly call
33
         *  self::compat() on the page, for the same reasons as above.
34
         */
35
        if (class_exists(Translatable::class)) {
36
            $this->translatableEnabledBefore = SiteTree::has_extension(Translatable::class);
37
            SiteTree::remove_extension(Translatable::class);
38
        }
39
    }
40
41
    protected function tearDown()
42
    {
43
        if (class_exists(Translatable::class)) {
44
            if ($this->translatableEnabledBefore) {
45
                SiteTree::add_extension(Translatable::class);
46
            }
47
        }
48
49
        parent::tearDown();
50
    }
51
}
52