Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
c9d81811
Commit
c9d81811
authored
Oct 13, 2019
by
Carsten Rose
Browse files
Implements #9352 - add unit tests
parent
cc4e74ff
Pipeline
#2470
passed with stages
in 2 minutes and 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
extension/Classes/Core/Form/FormAction.php
View file @
c9d81811
...
...
@@ -343,11 +343,9 @@ class FormAction {
*/
public
function
doSqlBeforeSlaveAfter
(
array
$fe
,
$recordId
,
$flagFeAction
)
{
// If given: fire a sqlBefore query
$this
->
evaluate
->
parse
(
$fe
[
FE_SQL_BEFORE
]);
$rcStatus
=
ACTION_ELEMENT_NO_CHANGE
;
// slaveId might be used in sqlBefore: get it first.
if
(
isset
(
$fe
[
FE_SLAVE_ID
]))
{
// Get the slaveId
$slaveId
=
$this
->
evaluate
->
parse
(
$fe
[
FE_SLAVE_ID
]);
...
...
@@ -363,7 +361,12 @@ class FormAction {
// Store the slaveId: it's used and replaced in the update statement.
$this
->
store
->
setVar
(
VAR_SLAVE_ID
,
$slaveId
,
STORE_VAR
,
true
);
}
// If given: fire a sqlBefore query
$this
->
evaluate
->
parse
(
$fe
[
FE_SQL_BEFORE
]);
if
(
isset
(
$fe
[
FE_SLAVE_ID
]))
{
$doInsert
=
(
$slaveId
==
0
);
$doUpdate
=
(
$slaveId
!=
0
);
$doDelete
=
(
$slaveId
!=
0
)
&&
!
empty
(
$fe
[
FE_SQL_DELETE
]);
...
...
extension/Tests/Unit/Core/SaveTest.php
View file @
c9d81811
...
...
@@ -107,7 +107,7 @@ class SaveTest extends AbstractDatabaseTest {
// Fake POST value
$this
->
store
::
setStore
([
'name'
=>
'DoeTmp'
,
'firstName'
=>
'John'
],
STORE_FORM
,
true
);
// ------------- Check -------------
// ------------- Check
: Insert
-------------
// 1) Expect INSERT into Person
$save
=
new
Save
(
$formSpec
,
[],
$feSpecNative
,
$feSpecNative
);
$save
->
process
();
...
...
@@ -120,27 +120,109 @@ class SaveTest extends AbstractDatabaseTest {
$this
->
assertEquals
(
'DoeTmpJohn'
,
$result
);
// // ------------- Check -------------
// $id=$this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id FROM Person WHERE name="DoeTmp"');
// // Fake POST value
// $this->store::setStore(['name' => 'DoeTmp', 'firstName' => 'JohnUpdate'], STORE_FORM, true);
// $this->store::setVar(SIP_RECORD_ID, $id,STORE_SIP, true);
//
// // 1) Expect UPDATE Person
// $save = new Save($formSpec, [], $feSpecNative, $feSpecNative);
// $save->process();
//
// // Get newly save record
// $sql = "SELECT name, firstName FROM Person WHERE name like 'DoeTmp'";
// $result = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_IMPLODE_ALL);
//
// // Compare
// $this->assertEquals('DoeTmpJohnUpdate' , $result);
// ------------- Check: Update -------------
$id
=
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
'SELECT id FROM Person WHERE name="DoeTmp"'
,
ROW_IMPLODE_ALL
);
// Fake POST value
$this
->
store
::
setStore
([
'name'
=>
'DoeTmp'
,
'firstName'
=>
'JohnUpdate'
],
STORE_FORM
,
true
);
$this
->
store
::
setVar
(
SIP_RECORD_ID
,
$id
,
STORE_SIP
,
true
);
// 1) Expect UPDATE Person
$save
->
process
();
// Get newly save record
$sql
=
"SELECT name, firstName FROM Person WHERE name like 'DoeTmp'"
;
$result
=
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
$sql
,
ROW_IMPLODE_ALL
);
// Compare
$this
->
assertEquals
(
'DoeTmpJohnUpdate'
,
$result
);
}
/**
* Test 'slaveId': Fake a form with two text inputs.
*
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
public
function
testSaveSlaveId
()
{
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
'DELETE FROM Address WHERE street="deleteMe"'
);
$formSpec
=
[
F_DB_INDEX
=>
DB_INDEX_DEFAULT
,
F_TABLE_NAME
=>
'Person'
,
F_MULTI_SQL
=>
''
,
F_PRIMARY_KEY
=>
F_PRIMARY_KEY_DEFAULT
,
];
$feSpecNative
=
[
[
FE_ID
=>
1
,
FE_TYPE
=>
FE_TYPE_TEXT
,
FE_NAME
=>
'name'
,
],
[
FE_ID
=>
2
,
FE_TYPE
=>
FE_TYPE_TEXT
,
FE_NAME
=>
'firstName'
,
FE_SQL_BEFORE
=>
'{{UPDATE Address SET city=CONCAT(city, "-") WHERE id={{slaveId:V}} }}'
,
FE_SLAVE_ID
=>
'{{SELECT id FROM Address WHERE street="deleteMe"}}'
,
FE_SQL_INSERT
=>
'{{INSERT INTO Address (street, city) VALUES ("deleteMe","Zurich")}}'
,
FE_SQL_UPDATE
=>
'{{UPDATE Address SET city=CONCAT(city, " Oerlikon") WHERE id={{slaveId:V}} }}'
,
FE_SQL_AFTER
=>
'{{UPDATE Address SET city=CONCAT(city, "+") WHERE id={{slaveId:V}} }}'
,
]
];
// Prepare Setup
$tableDefinition
=
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
getTableDefinition
(
'Person'
);
$this
->
store
->
fillStoreTableDefaultColumnType
(
$tableDefinition
);
// Init FE
$feSpecNative
=
HelperFormElement
::
formElementSetDefault
(
$feSpecNative
,
$formSpec
);
// Fake POST value
$this
->
store
::
setStore
([
'name'
=>
'DoeTmp'
,
'firstName'
=>
'John'
],
STORE_FORM
,
true
);
/*
* Check: sqlBefore/sqlInsert/sqlAfter
*
* slaveId becomes '0', cause there is no Address record 'street="deleteMe"'.
* sqlBefore does nothing, cause there is no Address record 'street="deleteMe"'.
* sqlInsert will create an Address record 'street="deleteMe"'.
* sqlAfter adds '+' after city name.
*/
$save
=
new
Save
(
$formSpec
,
[],
$feSpecNative
,
$feSpecNative
);
$save
->
process
();
// Get newly save record
$sql
=
"SELECT city FROM Address WHERE street like 'deleteMe'"
;
$result
=
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
$sql
,
ROW_IMPLODE_ALL
);
// Compare
$this
->
assertEquals
(
'Zurich+'
,
$result
);
/*
* Check: sqlBefore/sqlUpdate/sqlAfter - the previous 'deleteMe' record have to exist.
*
* slaveId becomes id of the previous created Address record 'street="deleteMe"'.
* sqlBefore adds '-' after city name.
* sqlUpdate adds ' Oerlikon' after city name.
* sqlAfter adds '+' after city name.
*/
$save
->
process
();
// Get newly save record
$sql
=
"SELECT city FROM Address WHERE street like 'deleteMe'"
;
$result
=
$this
->
dbArray
[
DB_INDEX_DEFAULT
]
->
sql
(
$sql
,
ROW_IMPLODE_ALL
);
// Compare
$this
->
assertEquals
(
'Zurich+- Oerlikon+'
,
$result
);
}
/**
* UNIT Tests
*
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment