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

ContentReviewBaseTest::tearDown()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
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