Issues (399)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/tasks/MigrateToDocumentSetsTaskTest.php (10 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class MigrateToDocumentSetsTaskTest extends SapphireTest
4
{
5
    protected static $fixture_file = 'MigrateToDocumentSetsTaskTest.yml';
6
7
    /**
8
     * Ensure that output is formatted either for the CLI or browser
9
     *
10
     * @param bool   $isCli
11
     * @param string $expected
12
     * @dataProvider outputProvider
13
     */
14
    public function testCanOutputToCliOrBrowser($isCli, $expected)
15
    {
16
        $lines = array('Test', 'Test line 2');
17
18
        $mock = $this->getMockBuilder('MigrateToDocumentSetsTask')
0 ignored issues
show
The method getMockBuilder() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
            ->setMethods(array('isCli'))
20
            ->getMock();
21
22
        $mock->expects($this->exactly(2))
0 ignored issues
show
The method exactly() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
            ->method('isCli')
24
            ->will($this->returnValue($isCli));
0 ignored issues
show
The method returnValue() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
26
        ob_start();
27
        foreach ($lines as $line) {
28
            $mock->output($line);
29
        }
30
        $result = ob_get_clean();
31
        $this->assertSame($expected, $result);
0 ignored issues
show
The method assertSame() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
    }
33
34
    /**
35
     * @return array[]
36
     */
37
    public function outputProvider()
38
    {
39
        return array(
40
            array(true, 'Test' . PHP_EOL . 'Test line 2' . PHP_EOL),
41
            array(false, 'Test<br />Test line 2<br />')
42
        );
43
    }
44
45
    /**
46
     * Ensure that providing an invalid action returns an error
47
     */
48
    public function testShowErrorOnInvalidAction()
49
    {
50
        $result = $this->runTask(array('action' => 'coffeetime'));
51
        $this->assertContains('Error! Specified action is not valid.', $result);
52
    }
53
54
    /**
55
     * Test that default document sets can be created for those pages that don't have them already
56
     */
57
    public function testCreateDefaultDocumentSets()
58
    {
59
        $this->fixtureOldRelations();
60
61
        $result = $this->runTask(array('action' => 'create-default-document-set'));
62
        $this->assertContains('Finished', $result);
63
        // There are four pages in the fixture, but one of them already has a document set, so should be unchanged
64
        $this->assertContains('Default document set added: 3', $result);
65
        $this->assertContains('Skipped: already has a set: 1', $result);
66
67
        // Test that some of the relationship records were written correctly
68
        $this->assertCount(1, $firstPageSets = $this->objFromFixture('SiteTree', 'one')->getDocumentSets());
0 ignored issues
show
The method assertCount() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
        $this->assertSame('Default', $firstPageSets->first()->Title);
0 ignored issues
show
The method assertSame() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
        $this->assertCount(1, $this->objFromFixture('SiteTree', 'two')->getDocumentSets());
0 ignored issues
show
The method assertCount() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
72
        // With dryrun enabled and being run the second time, nothing should be done
73
        $result = $this->runTask(array('action' => 'create-default-document-set', 'dryrun' => '1'));
74
        $this->assertContains('Skipped: already has a set: 4', $result);
75
        $this->assertContains('NOTE: Dryrun mode enabled', $result);
76
    }
77
78
    /**
79
     * Test that legacy ORM relationship maps are migrated to the new page -> document set -> document relationship
80
     */
81
    public function testReassignDocumentsToFirstSet()
82
    {
83
        $this->fixtureOldRelations();
84
85
        // Ensure default sets are created
86
        $this->runTask(array('action' => 'create-default-document-set'));
87
88
        // Dryrun check
89
        $result = $this->runTask(array('action' => 'reassign-documents', 'dryrun' => '1'));
90
        $this->assertContains('NOTE: Dryrun mode enabled', $result);
91
        $this->assertContains('Reassigned to document set: 3', $result);
92
93
        // Actual run
94
        $result = $this->runTask(array('action' => 'reassign-documents'));
95
        $this->assertNotContains('NOTE: Dryrun mode enabled', $result);
96
        $this->assertContains('Reassigned to document set: 3', $result);
97
98
        // Smoke ORM checks
99
        $this->assertCount(1, $this->objFromFixture('SiteTree', 'one')->getAllDocuments());
0 ignored issues
show
The method assertCount() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        $this->assertCount(1, $this->objFromFixture('SiteTree', 'two')->getAllDocuments());
0 ignored issues
show
The method assertCount() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
101
        $this->assertCount(0, $this->objFromFixture('SiteTree', 'four')->getAllDocuments());
0 ignored issues
show
The method assertCount() does not seem to exist on object<MigrateToDocumentSetsTaskTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
    }
103
104
    /**
105
     * Centralises (slightly) logic for capturing direct output from the task
106
     *
107
     * @param  array $getVars
108
     * @return string Task output
109
     */
110
    protected function runTask(array $getVars)
111
    {
112
        $task = new MigrateToDocumentSetsTask;
113
        $request = new SS_HTTPRequest('GET', '/', $getVars);
114
115
        ob_start();
116
        $task->run($request);
117
        return ob_get_clean();
118
    }
119
120
    /**
121
     * Set up the old many many relationship table from documents to pages
122
     */
123
    protected function fixtureOldRelations()
124
    {
125
        if (!DB::get_schema()->hasTable('DMSDocument_Pages')) {
126
            DB::create_table('DMSDocument_Pages', array(
127
                'DMSDocumentID' => 'int(11) null',
128
                'SiteTreeID' => 'int(11) null'
129
            ));
130
        }
131
132
        $documentIds = $this->getFixtureFactory()->getIds('DMSDocument');
133
        $pageIds = $this->getFixtureFactory()->getIds('SiteTree');
134
        foreach (array('one', 'two', 'three') as $fixtureName) {
135
            $this->getFixtureFactory()->createRaw(
136
                'DMSDocument_Pages',
137
                'rln_' . $fixtureName,
138
                array('DMSDocumentID' => $documentIds[$fixtureName], 'SiteTreeID' => $pageIds[$fixtureName])
139
            );
140
        }
141
    }
142
}
143