FileNlsTest   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 146
Duplicated Lines 11.64 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 17
loc 146
rs 10
wmc 18
lcom 1
cbo 3

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testDefaultNLS() 0 11 1
A testAllNLS() 0 11 2
A testAllNLSPlain() 0 11 2
A testAllNLSShow() 0 13 2
A testunavailableNls() 8 8 1
A testUnavailableNlsPlain() 9 9 1
A testunavailableNlsChangeDefault() 0 10 1
A testAllNLSPlainHTML() 0 11 2
A testAllNLSPlainPDF() 0 11 2
A testSaveExistingFile() 0 11 1
A testParseFile() 0 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class FileNlsTest extends AriadneBaseTest
4
{
5
6
	public function setUp()
7
	{
8
		$this->initAriadne();
9
	}
10
11
	public function testDefaultNLS() {
12
		global $AR;
13
14
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
15
		$defaultnls = $obj->data->nls->default;
16
17
		$one = trim($obj->getFile('file',$defaultnls));
18
		$two = trim($obj->getFile());
19
		$this->assertEquals('taal '.$defaultnls,$one);
20
		$this->assertEquals($one,$two);
21
	}
22
23
	public function testAllNLS() {
24
		global $AR;
25
26
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
27
28
		foreach($obj->data->nls->list as $nls => $language) {
29
			$content = $obj->getFile('file',$nls);
30
			$content = trim($content);
31
			$this->assertEquals('taal '.$nls , $content);
32
		}
33
	}
34
35
	public function testAllNLSPlain() {
36
		global $AR;
37
38
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
39
40
		foreach($obj->data->nls->list as $nls => $language) {
41
			$content = $obj->getPlainText('file',$nls);
42
			$content = trim($content);
43
			$this->assertEquals('taal '.$nls , $content);
44
		}
45
	}
46
47
	public function testAllNLSShow() {
48
		global $AR;
49
50
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
51
		foreach($obj->data->nls->list as $nls => $language) {
52
			ob_start();
53
			$obj->ShowFile('file',$nls);
54
			$content  = ob_get_contents();
55
			ob_end_clean();
56
			$content = trim($content);
57
			$this->assertEquals('taal '.$nls , $content);
58
		}
59
	}
60
61 View Code Duplication
	public function testunavailableNls() {
62
		global $AR;
63
64
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
65
		$content = $obj->getFile('file','zz');
66
		$content = trim($content);
67
		$this->assertEquals('taal '.$obj->data->nls->default , $content);
68
	}
69
70 View Code Duplication
	public function testUnavailableNlsPlain() {
71
		global $AR;
72
73
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
74
		$nls = $obj->data->nls->default;
75
		$content = $obj->getPlainText('file','zz');
76
		$content = trim($content);
77
		$this->assertEquals('taal '.$nls , $content);
78
	}
79
80
	public function testunavailableNlsChangeDefault() {
81
		global $AR;
82
83
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
84
		$nls = $obj->data->nls->default;
85
		$obj->data->nls->default = 'de';
86
		$content = $obj->getFile('file','zz');
87
		$content = trim($content);
88
		$this->assertNotEquals('taal '.$nls , $content);
89
	}
90
91
	public function testAllNLSPlainHTML() {
92
		global $AR;
93
94
		$obj =current(ar::get(TESTBASE.'/file-nls/file-html/')->call('system.get.phtml'));
95
96
		foreach($obj->data->nls->list as $nls => $language) {
97
			$content = $obj->getPlainText('file',$nls);
98
			$content = trim($content);
99
			$this->assertEquals($nls , $content);
100
		}
101
	}
102
	public function testAllNLSPlainPDF() {
103
		global $AR;
104
105
		$obj =current(ar::get(TESTBASE.'/file-nls/file-pdf/')->call('system.get.phtml'));
106
107
		foreach($obj->data->nls->list as $nls => $language) {
108
			$content = $obj->getPlainText('file',$nls);
109
			$content = trim($content);
110
			$this->assertEquals($nls , $content);
111
		}
112
	}
113
114
	public function testSaveExistingFile() {
115
		global $AR,$ARCurrent;
116
		$content = 'testfrmlfrop';
117
		$obj  = current(ar::get(TESTBASE.'/file-nls/file-nls/' )->call('system.get.phtml'));
118
119
		$res = $obj->SaveFile($content ,'text/plain', 'newfile', $obj->nls);
120
		$this->assertEquals(strlen($content), $res);
121
122
		$res = $obj->GetFile('newfile', $obj->nls);
123
		$this->assertEquals($content, $res);
124
	}
125
126
	public function testParseFile() {
127
		global $AR;
128
129
		$obj =current(ar::get(TESTBASE.'/file-nls/file-nls/')->call('system.get.phtml'));
130
		foreach($obj->data->nls->list as $nls => $language) {
131
			$content = $obj->ParseFile('file',$nls);
132
			$content = trim($content);
133
			$this->assertEquals('taal '.$nls , $content);
134
		}
135
	}
136
137
/*
138
	TODO:
139
		- save file for new object
140
		- showfile
141
			- mimetype
142
			- headers
143
		- download file
144
			- file
145
			- mimetype
146
			- headers
147
*/
148
}
149
?>
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...
150