1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TractorCow\Fluent\Tests\Extension; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
|
|
|
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
8
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText; |
9
|
|
|
use TractorCow\Fluent\Extension\FluentLeftAndMainExtension; |
10
|
|
|
use TractorCow\Fluent\Extension\FluentSiteTreeExtension; |
11
|
|
|
use TractorCow\Fluent\Model\Locale; |
12
|
|
|
use TractorCow\Fluent\State\FluentState; |
13
|
|
|
use TractorCow\Fluent\Tests\Extension\Stub\FluentStubController; |
14
|
|
|
|
15
|
|
|
class FluentBadgeExtensionTest extends SapphireTest |
16
|
|
|
{ |
17
|
|
|
protected static $fixture_file = 'FluentBadgeExtensionTest.yml'; |
18
|
|
|
|
19
|
|
|
protected static $required_extensions = [ |
20
|
|
|
SiteTree::class => [ |
21
|
|
|
FluentSiteTreeExtension::class, |
22
|
|
|
], |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var SiteTree |
27
|
|
|
*/ |
28
|
|
|
protected $mockPage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Controller |
32
|
|
|
*/ |
33
|
|
|
protected $mockController; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var FluentLeftAndMainExtension |
37
|
|
|
*/ |
38
|
|
|
protected $extension; |
39
|
|
|
|
40
|
|
|
protected function setUp(): void |
41
|
|
|
{ |
42
|
|
|
parent::setUp(); |
43
|
|
|
|
44
|
|
|
// Clear cache |
45
|
|
|
Locale::clearCached(); |
46
|
|
|
|
47
|
|
|
FluentState::singleton()->withState(function (FluentState $newState) { |
48
|
|
|
$newState->setLocale('en_NZ'); |
49
|
|
|
|
50
|
|
|
$this->mockPage = $this->objFromFixture(SiteTree::class, 'test_page'); |
|
|
|
|
51
|
|
|
$this->mockController = new FluentStubController($this->mockPage->ID); |
52
|
|
|
$this->extension = new FluentLeftAndMainExtension(); |
53
|
|
|
$this->extension->setOwner($this->mockController); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testDefaultLocaleBadgeAdded() |
58
|
|
|
{ |
59
|
|
|
// Publish the page in the default locale |
60
|
|
|
FluentState::singleton()->withState(function (FluentState $newState) { |
61
|
|
|
$newState->setLocale('en_NZ'); |
62
|
|
|
$this->mockPage->publishRecursive(); |
63
|
|
|
|
64
|
|
|
$result = $this->extension->getBadge($this->mockPage); |
65
|
|
|
$this->assertInstanceOf(DBHTMLText::class, $result); |
66
|
|
|
$this->assertStringContainsString('fluent-badge--default', $result->getValue()); |
67
|
|
|
$this->assertStringContainsString('Localised in', $result->getValue()); |
68
|
|
|
$this->assertStringContainsString('NZ', $result->getValue(), 'Badge shows owner locale'); |
69
|
|
|
}); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testInvisibleLocaleBadgeWasAdded() |
73
|
|
|
{ |
74
|
|
|
FluentState::singleton()->withState(function (FluentState $newState) { |
75
|
|
|
// Don't write the page in the non-default locale, then it shouldn't exist |
76
|
|
|
$newState->setLocale('de_DE'); |
77
|
|
|
|
78
|
|
|
$result = $this->extension->getBadge($this->mockPage); |
79
|
|
|
$this->assertInstanceOf(DBHTMLText::class, $result); |
80
|
|
|
$this->assertStringContainsString('fluent-badge--invisible', $result->getValue()); |
81
|
|
|
$this->assertStringContainsString('Page has no available content in', $result->getValue()); |
82
|
|
|
$this->assertStringContainsString('de_DE', $result->getValue(), 'Badge shows owner locale'); |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths