Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jakob Diel
Stud.IP
Commits
bbaa4429
Commit
bbaa4429
authored
3 years ago
by
Elmar Ludwig
Browse files
Options
Downloads
Patches
Plain Diff
revert changes to StudipPdoTest, re #147
parent
e2929ffd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/lib/classes/StudipPdoTest.php
+24
-43
24 additions, 43 deletions
tests/unit/lib/classes/StudipPdoTest.php
with
24 additions
and
43 deletions
tests/unit/lib/classes/StudipPdoTest.php
+
24
−
43
View file @
bbaa4429
<?php
/*
* studip_pdo_test.php - unit tests for the StudipPDO class
*
...
...
@@ -13,94 +12,76 @@
* @category Stud.IP
*/
class
StudipP
doTest
extends
\Codeception\Test\Unit
abstract
class
Test
StudipP
DO
extends
StudipPDO
{
public
function
setUp
():
void
{
$dsn
=
'mysql:host='
.
$GLOBALS
[
'DB_STUDIP_HOST'
]
.
';dbname='
.
$GLOBALS
[
'DB_STUDIP_DATABASE'
]
.
';charset=utf8mb4'
;
$username
=
$GLOBALS
[
'DB_STUDIP_USER'
];
$password
=
$GLOBALS
[
'DB_STUDIP_PASSWORD'
];
$this
->
testPdo
=
new
class
(
$dsn
,
$username
,
$password
)
extends
StudipPDO
{
public
static
function
doReplaceStrings
(
$statement
)
{
return
parent
::
replaceStrings
(
$statement
);
}
};
$this
->
testPdo
->
beginTransaction
();
}
public
function
tearDown
():
void
public
static
function
doReplaceStrings
(
$statement
)
{
$this
->
testPdo
->
rollBack
(
);
return
parent
::
replaceStrings
(
$statement
);
}
}
class
StudipPDOTest
extends
\Codeception\Test\Unit
{
public
function
testSimpleString
()
{
$query
=
'SELECT * FROM bar'
;
$query
=
'SELECT * FROM bar'
;
$expect
=
$query
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
public
function
testDoubleQuotedString
()
{
$query
=
'SELECT "\'foo""\\"" FROM bar WHERE foo = "\\\\"'
;
$query
=
'SELECT "\'foo""\\"" FROM bar WHERE foo = "\\\\"'
;
$expect
=
'SELECT ? FROM bar WHERE foo = ?'
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
$query
=
str_repeat
(
$query
,
100
);
$query
=
str_repeat
(
$query
,
100
);
$expect
=
str_repeat
(
$expect
,
100
);
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
public
function
testSingleQuotedString
()
{
$query
=
'SELECT \'"foo\'\'\\\'\' FROM bar WHERE foo = \'\\\\\''
;
$query
=
'SELECT \'"foo\'\'\\\'\' FROM bar WHERE foo = \'\\\\\''
;
$expect
=
'SELECT ? FROM bar WHERE foo = ?'
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
$query
=
str_repeat
(
$query
,
100
);
$query
=
str_repeat
(
$query
,
100
);
$expect
=
str_repeat
(
$expect
,
100
);
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
public
function
testMixedQuotedString
()
{
$query
=
'SELECT """\'", \'"\' FROM bar WHERE foo IN (\'\'\'"\'"")'
;
$query
=
'SELECT """\'", \'"\' FROM bar WHERE foo IN (\'\'\'"\'"")'
;
$expect
=
'SELECT ?, ? FROM bar WHERE foo IN (??)'
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
$query
=
str_repeat
(
$query
,
100
);
$query
=
str_repeat
(
$query
,
100
);
$expect
=
str_repeat
(
$expect
,
100
);
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
public
function
testUnterminatedSingleQuote
()
{
$query
=
'SELECT \'1\' ORDER BY \'au.username asc'
;
$query
=
'SELECT \'1\' ORDER BY \'au.username asc'
;
$expect
=
'SELECT ? ORDER BY \'au.username asc'
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
public
function
testUnterminatedDoubleQuote
()
{
$query
=
'SELECT "1" ORDER BY "au.username asc'
;
$query
=
'SELECT "1" ORDER BY "au.username asc'
;
$expect
=
'SELECT ? ORDER BY "au.username asc'
;
$this
->
assertEquals
(
$expect
,
$this
->
testPdo
::
doReplaceStrings
(
$query
));
$this
->
assertEquals
(
$expect
,
TestStudipPDO
::
doReplaceStrings
(
$query
));
}
}
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