Test Failed
Branch develop (db5506)
by Felipe
03:46
created

ImportTest::testIncorectTxtData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Function area: Common manipulation
4
 * Sub function area: Import
5
 *
6
 * @author     Augmentum SpikeSource Team 
7
 * @copyright  2005 by Augmentum, Inc.
8
 */
9
10
// Import the precondition class.
11
if(is_dir('../Public')) 
12
{
13
    require_once('../Public/SetPrecondition.php');
14
}
15
16
/**
17
 * This class is to test the import function.
18
 * It includes importing for XML format data and incorect text format data.
19
 * 
20
 * This part test cases cannot pass because simpletest does not support upload file.
21
 */
22
class ImportTest extends PreconditionSet 
23
{
24
    // Declare the member variables for table name and the data file's path.
25
    private $_tableName = 'student';
26
    private $_dataFilePath = '.';
27
    
28
    function setUp()
29
    {
30
        global $webUrl;
31
        global $SUPER_USER_NAME;
32
        global $SUPER_USER_PASSWORD;
33
        
34
        $this->login($SUPER_USER_NAME, $SUPER_USER_PASSWORD, "$webUrl/login.php");
35
        
36
        return TRUE;
37
    }
38
    
39
    
40
    function tearDown()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
    {
42
        // Clear the data and logout.
43
        $this->emptyTable();
44
        $this->logout();
45
        
46
        return TRUE;
47
    }
48
   
49
   
50
    /*
51
     * TestCaseID: CID01
52
     * Test to import XML format data into the table.
53
     * 
54
     * This test case will failed because SimpleTest1.0 doesn't support upload file.
55
     */
56
    function testXMLData() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
57
    {
58
        global $webUrl;
59
        global $lang, $SERVER, $DATABASE;
60
        
61
        $this->_dataFilePath = getcwd() . '/./data/';
62
        
63
        // Turn to the import data page.
64
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
65
			'server' => $SERVER,
66
			'database' => $DATABASE,
67
			'schema' => 'public',
68
			'table' => $this->_tableName,
69
			'subject' => 'table',
70
			'action' => 'import'))
71
		);
72
73
        // Enter information for importing the data.
74
        $this->assertTrue($this->setField('format', 'XML'));
75
        $this->assertTrue($this->setField('source', $this->_dataFilePath . $this->_tableName . '.xml'));
76
        
77
        // Then submit and verify it.
78
        $this->assertTrue($this->clickSubmit($lang['strimport']));
79
        // This assert will failed because SimpleTest1.0 doesn't support upload file.
80
        $this->assertWantedText($lang['strfileimported']);
81
        
82
        return TRUE;
83
    }
84
    
85
    /*
86
     * TestCaseID: CID02
87
     * Test to import incorect text format data into the table.
88
     * 
89
     * This test case will failed because SimpleTest1.0 doesn't support upload file.
90
     */
91
    function testIncorectTxtData() 
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
92
    {
93
        global $webUrl;
94
        global $lang, $SERVER, $DATABASE;
95
        
96
        $this->_dataFilePath = getcwd() . '/./data/';
97
        // Turn to the import data page.
98
		$this->assertTrue($this->get("$webUrl/tblproperties.php", array(
99
			            'server' => $SERVER,
100
						'database' => $DATABASE,
101
						'schema' => 'public',
102
						'table' => $this->_tableName,
103
						'subject' => 'table',
104
						'action' => 'import'))
105
					);
106
       
107
        // Enter information for importing the data.
108
        $this->assertTrue($this->setField('format', $lang['strauto']));
109
        $this->assertTrue($this->setField('source', $this->_dataFilePath . $this->_tableName . '.txt'));
110
        
111
        // Then submit and verify it.
112
        $this->assertTrue($this->clickSubmit($lang['strimport']));
113
        // This assert will failed because SimpleTest1.0 doesn't support upload file.
114
        $this->assertWantedText(sprintf($lang['strimporterrorline'], 2));
115
        
116
        return TRUE;
117
    }
118
    
119
    /*
120
     * Help to empty the table's data.
121
     */
122
    function emptyTable()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
    {
124
        global $webUrl;
125
        global $lang, $SERVER, $DATABASE;
126
        
127
		$this->assertTrue($this->get("$webUrl/tables.php", array(
128
			            'server' => $SERVER,
129
						'action' => 'confirm_empty',
130
						'database' => $DATABASE,
131
						'schema' => 'public',
132
						'table' => $this->_tableName))
133
					);
134
        $this->assertTrue($this->clickSubmit($lang['strempty']));
135
    	
136
        return TRUE;
137
    }
138
    
139
}
140
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
141