1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CWP\CWP\Tests\Tasks; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
use CWP\CWP\Tasks\PopulateThemeSampleDataTask; |
11
|
|
|
use SilverStripe\UserForms\Model\UserDefinedForm; |
|
|
|
|
12
|
|
|
use SilverStripe\Dev\BuildTask; |
13
|
|
|
use SilverStripe\Control\HTTPRequest; |
14
|
|
|
use SilverStripe\Dev\SapphireTest; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class PopulateThemeSampleDataTaskTest extends SapphireTest |
19
|
|
|
{ |
20
|
|
|
protected $usesDatabase = true; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Ensure that the "contact" user form is only created once |
24
|
|
|
*/ |
25
|
|
|
public function testOnlyCreateContactFormOnce() |
26
|
|
|
{ |
27
|
|
|
$createdMessage = 'Created "contact" UserDefinedForm'; |
28
|
|
|
|
29
|
|
|
$task = new PopulateThemeSampleDataTask; |
30
|
|
|
|
31
|
|
|
// Run the task |
32
|
|
|
$this->assertContains($createdMessage, $this->bufferedTask($task)); |
33
|
|
|
|
34
|
|
|
// Run a second time |
35
|
|
|
$this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
36
|
|
|
|
37
|
|
|
// Change the page name |
38
|
|
|
$form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first(); |
39
|
|
|
$form->URLSegment = 'testing'; |
40
|
|
|
$form->write(); |
41
|
|
|
|
42
|
|
|
// Ensure the old version is still detected in draft, so not recreated |
43
|
|
|
$this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
44
|
|
|
|
45
|
|
|
// Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions) |
46
|
|
|
$form->delete(); |
47
|
|
|
$this->assertContains($createdMessage, $this->bufferedTask($task)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Run a BuildTask while buffering its output, and return the result |
52
|
|
|
* |
53
|
|
|
* @param BuildTask $task |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
protected function bufferedTask(BuildTask $task) |
57
|
|
|
{ |
58
|
|
|
ob_start(); |
59
|
|
|
$task->run(new HTTPRequest('GET', '/')); |
60
|
|
|
return ob_get_clean(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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