Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

PopulateThemeSampleDataTaskTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testOnlyCreateContactFormOnce() 0 23 1
A bufferedTask() 0 5 1
1
<?php
2
3
class PopulateThemeSampleDataTaskTest extends SapphireTest
4
{
5
	protected $usesDatabase = true;
6
7
	/**
8
	 * Ensure that the "contact" user form is only created once
9
	 */
10
	public function testOnlyCreateContactFormOnce()
11
	{
12
		$createdMessage = 'Created "contact" UserDefinedForm';
13
14
		$task = new PopulateThemeSampleDataTask;
15
16
		// Run the task
17
		$this->assertContains($createdMessage, $this->bufferedTask($task));
18
19
		// Run a second time
20
		$this->assertNotContains($createdMessage, $this->bufferedTask($task));
21
22
		// Change the page name
23
		$form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first();
0 ignored issues
show
Bug introduced by
The type UserDefinedForm was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
		$form->URLSegment = 'testing';
25
		$form->write();
26
27
		// Ensure the old version is still detected in draft, so not recreated
28
		$this->assertNotContains($createdMessage, $this->bufferedTask($task));
29
30
		// Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions)
31
		$form->delete();
32
		$this->assertContains($createdMessage, $this->bufferedTask($task));
33
	}
34
35
	/**
36
	 * Run a BuildTask while buffering its output, and return the result
37
	 *
38
	 * @param  BuildTask $task
39
	 * @return string
40
	 */
41
	protected function bufferedTask(BuildTask $task)
42
	{
43
		ob_start();
44
		$task->run(new SS_HTTPRequest('GET', '/'));
45
		return ob_get_clean();
46
	}
47
}
48