Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
b434c20c
Commit
b434c20c
authored
12 years ago
by
Thomas Tanghus
Browse files
Options
Downloads
Patches
Plain Diff
Added unit test testinsertIfNotExistDontOverwrite.
parent
5fc0c89a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/lib/db.php
+37
-0
37 additions, 0 deletions
tests/lib/db.php
with
37 additions
and
0 deletions
tests/lib/db.php
+
37
−
0
View file @
b434c20c
...
@@ -93,4 +93,41 @@ class Test_DB extends UnitTestCase {
...
@@ -93,4 +93,41 @@ class Test_DB extends UnitTestCase {
$this
->
assertTrue
(
$result
);
$this
->
assertTrue
(
$result
);
$this
->
assertEqual
(
$result
->
numRows
(),
'4'
);
$this
->
assertEqual
(
$result
->
numRows
(),
'4'
);
}
}
public
function
testinsertIfNotExistDontOverwrite
()
{
$fullname
=
'fullname test'
;
$uri
=
'uri_1'
;
$carddata
=
'This is a vCard'
;
// Normal test to have same known data inserted.
$query
=
OC_DB
::
prepare
(
'INSERT INTO *PREFIX*'
.
$this
->
table2
.
' (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)'
);
$result
=
$query
->
execute
(
array
(
$fullname
,
$uri
,
$carddata
));
$this
->
assertTrue
(
$result
);
$query
=
OC_DB
::
prepare
(
'SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'
.
$this
->
table2
.
' WHERE `uri` = ?'
);
$result
=
$query
->
execute
(
array
(
$uri
));
$this
->
assertTrue
(
$result
);
$row
=
$result
->
fetchRow
();
$this
->
assertArrayHasKey
(
'carddata'
,
$row
);
$this
->
assertEqual
(
$row
[
'carddata'
],
$carddata
);
$this
->
assertEqual
(
$result
->
numRows
(),
'1'
);
// Try to insert a new row
$result
=
OC_DB
::
insertIfNotExist
(
'*PREFIX*'
.
$this
->
table2
,
array
(
'fullname'
=>
$fullname
,
'uri'
=>
$uri
,
));
$this
->
assertTrue
(
$result
);
$query
=
OC_DB
::
prepare
(
'SELECT `fullname`, `uri`, `carddata` FROM *PREFIX*'
.
$this
->
table2
.
' WHERE `uri` = ?'
);
$result
=
$query
->
execute
(
array
(
$uri
));
$this
->
assertTrue
(
$result
);
$row
=
$result
->
fetchRow
();
$this
->
assertArrayHasKey
(
'carddata'
,
$row
);
// Test that previously inserted data isn't overwritten
$this
->
assertEqual
(
$row
[
'carddata'
],
$carddata
);
// And that a new row hasn't been inserted.
$this
->
assertEqual
(
$result
->
numRows
(),
'1'
);
}
}
}
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