Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
7e25cc04
Commit
7e25cc04
authored
7 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
FIX Phpunit on file submit with REST API
parent
0e6ab01a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
htdocs/api/class/api_documents.class.php
+1
-2
1 addition, 2 deletions
htdocs/api/class/api_documents.class.php
htdocs/core/lib/geturl.lib.php
+1
-0
1 addition, 0 deletions
htdocs/core/lib/geturl.lib.php
test/phpunit/RestAPIDocumentTest.php
+35
-24
35 additions, 24 deletions
test/phpunit/RestAPIDocumentTest.php
with
37 additions
and
26 deletions
htdocs/api/class/api_documents.class.php
+
1
−
2
View file @
7e25cc04
...
...
@@ -36,9 +36,8 @@ class Documents extends DolibarrApi
* @var array $DOCUMENT_FIELDS Mandatory fields, checked when create and update object
*/
static
$DOCUMENT_FIELDS
=
array
(
'name'
,
'modulepart'
,
'file'
'file
name
'
);
/**
...
...
This diff is collapsed.
Click to expand it.
htdocs/core/lib/geturl.lib.php
+
1
−
0
View file @
7e25cc04
...
...
@@ -71,6 +71,7 @@ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addhea
curl_setopt
(
$ch
,
CURLOPT_CONNECTTIMEOUT
,
empty
(
$conf
->
global
->
MAIN_USE_CONNECT_TIMEOUT
)
?
5
:
$conf
->
global
->
MAIN_USE_CONNECT_TIMEOUT
);
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
empty
(
$conf
->
global
->
MAIN_USE_RESPONSE_TIMEOUT
)
?
30
:
$conf
->
global
->
MAIN_USE_RESPONSE_TIMEOUT
);
//curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); // PHP 5.5
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
// We want response
if
(
$postorget
==
'POST'
)
{
...
...
This diff is collapsed.
Click to expand it.
test/phpunit/RestAPIDocumentTest.php
+
35
−
24
View file @
7e25cc04
...
...
@@ -28,6 +28,7 @@ global $conf,$user,$langs,$db;
require_once
dirname
(
__FILE__
)
.
'/../../htdocs/master.inc.php'
;
require_once
dirname
(
__FILE__
)
.
'/../../htdocs/core/lib/date.lib.php'
;
require_once
dirname
(
__FILE__
)
.
'/../../htdocs/core/lib/geturl.lib.php'
;
require_once
dirname
(
__FILE__
)
.
'/../../htdocs/core/lib/files.lib.php'
;
if
(
empty
(
$user
->
id
))
{
echo
"Load permissions for admin user nb 1
\n
"
;
...
...
@@ -141,40 +142,50 @@ class RestAPIDocumentTest extends PHPUnit_Framework_TestCase
$url
=
$this
->
api_url
.
'/documents/?api_key='
.
$this
->
api_key
;
$fileName
=
'img250x20.png'
;
$filePath
=
dirname
(
__FILE__
)
.
'/'
.
$fileName
;
$mimetype
=
dol_mimetype
(
$filePath
);
echo
__METHOD__
.
' Request POST url='
.
$url
.
"
\n
"
;
// Send to existant directory
// Send to non existant directory
dol_delete_dir_recursive
(
DOL_DATA_ROOT
.
'/medias/tmpphpunit'
);
//$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }';
$data
=
array
(
'modulepart'
=>
'facture'
,
'file'
=>
'eeeeeee'
,
'refname'
=>
'AV1303-0003'
,
'name'
=>
$fileName
,
// Name for destination
'mime'
=>
$mimetype
);
'filename'
=>
"mynewfile.txt"
,
'modulepart'
=>
"medias"
,
'ref'
=>
""
,
'subdir'
=>
"tmpphpunit/tmpphpunit2"
,
'filecontent'
=>
"content text"
,
'fileencoding'
=>
""
);
$result
=
getURLContent
(
$url
,
'POST'
,
$data
,
1
);
echo
__METHOD__
.
' Result for sending document: '
.
var_export
(
$result
,
true
)
.
"
\n
"
;
echo
__METHOD__
.
' curl_error_no: '
.
$result
[
'curl_error_no'
]
.
"
\n
"
;
$this
->
assertEquals
(
$result
[
'curl_error_no'
],
''
);
$this
->
assertEquals
(
$result
[
'content'
],
'true'
);
$object
=
json_decode
(
$result
[
'content'
],
true
);
$this
->
assertNotNull
(
$object
,
'Parsing of json result must no be null'
);
$this
->
assertEquals
(
'401'
,
$object
[
'error'
][
'code'
]);
// Send to unexistant directory
// Send to existant directory
dol_mkdir
(
DOL_DATA_ROOT
.
'/medias/tmpphpunit/tmpphpunit2'
);
$data
=
array
(
'modulepart'
=>
'facture'
,
'file'
=>
$cfile
,
'name'
=>
'AV1303-0003STSEIUDEISRESIJLEU/'
.
$fileName
,
// Name for destination
'type'
=>
$mimetype
,
);
'filename'
=>
"mynewfilethatwillfails.txt"
,
'modulepart'
=>
"medias"
,
'ref'
=>
""
,
'subdir'
=>
"tmpphpunit/tmpphpunit2"
,
'filecontent'
=>
"content text"
,
'fileencoding'
=>
""
);
$result2
=
getURLContent
(
$url
,
'POST'
,
$data
,
1
);
echo
__METHOD__
.
' Result for sending document: '
.
var_export
(
$result2
,
true
)
.
"
\n
"
;
echo
__METHOD__
.
' curl_error_no: '
.
$result
[
'curl_error_no'
]
.
"
\n
"
;
$
object
=
json_decode
(
$result2
[
'content'
],
true
);
$this
->
assert
NotNull
(
$object
,
'Parsing of json result must no be null
'
);
$this
->
assertEquals
(
'401'
,
$object
[
'error'
][
'cod
e'
]
);
echo
__METHOD__
.
' curl_error_no: '
.
$result
2
[
'curl_error_no'
]
.
"
\n
"
;
$object2
=
json_decode
(
$result2
[
'content'
],
true
);
$
this
->
assertNotNull
(
$object2
,
'Parsing of json result must no be null'
);
$this
->
assert
Equals
(
$result2
[
'curl_error_no'
],
'
'
);
$this
->
assertEquals
(
$result2
[
'content'
],
'tru
e'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment