Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setDisabled example
$initialEngine
=
new
\
stdClass
(
)
;
$car
=
new
\
stdClass
(
)
;
$car
->engine =
$initialEngine
;
$engine
=
new
\
stdClass
(
)
;
$propertyPath
=
new
PropertyPath
(
'engine'
)
;
$config
=
new
FormConfigBuilder
(
'name', \stdClass::
class
,
$this
->dispatcher
)
;
$config
->
setByReference
(
true
)
;
$config
->
setPropertyPath
(
$propertyPath
)
;
$config
->
setData
(
$engine
)
;
$config
->
setDisabled
(
true
)
;
$form
=
new
SubmittedForm
(
$config
)
;
$this
->mapper->
mapFormsToData
(
new
\
ArrayIterator
(
[
$form
]
)
,
$car
)
;
self::
assertSame
(
$initialEngine
,
$car
->engine
)
;
}
public
function
testMapFormsToUninitializedProperties
(
)
{
$car
=
new
TypehintedPropertiesCar
(
)
;
$config
=
new
FormConfigBuilder
(
'engine', null,
$this
->dispatcher
)
;
public
function
testSubmitThrowsExceptionIfAlreadySubmitted
(
)
{
$this
->
expectException
(
AlreadySubmittedException::
class
)
;
$this
->form->
submit
(
[
]
)
;
$this
->form->
submit
(
[
]
)
;
}
public
function
testSubmitIsIgnoredIfDisabled
(
)
{
$form
=
$this
->
getBuilder
(
)
->
setDisabled
(
true
)
->
setData
(
'initial'
)
->
getForm
(
)
;
$form
->
submit
(
'new'
)
;
$this
->
assertEquals
(
'initial',
$form
->
getData
(
)
)
;
$this
->
assertTrue
(
$form
->
isSubmitted
(
)
)
;
}
public
function
testNeverRequiredIfParentNotRequired
(
)
{
$button
->
submit
(
''
)
;
$button
->
setParent
(
$this
->
getFormBuilder
(
)
->
getForm
(
)
)
;
}
/** * @dataProvider getDisabledStates */
public
function
testDisabledIfParentIsDisabled
(
$parentDisabled
,
$buttonDisabled
,
$result
)
{
$form
=
$this
->
getFormBuilder
(
)
->
setDisabled
(
$parentDisabled
)
->
getForm
(
)
;
$button
=
$this
->
getButtonBuilder
(
'button'
)
->
setDisabled
(
$buttonDisabled
)
->
getForm
(
)
;
$button
->
setParent
(
$form
)
;
$this
->
assertSame
(
$result
,
$button
->
isDisabled
(
)
)
;
}
abstract
class
BaseType
extends
AbstractType
{
/** * @return void */
public
function
buildForm
(
FormBuilderInterface
$builder
, array
$options
)
{
$builder
->
setDisabled
(
$options
[
'disabled'
]
)
;
$builder
->
setAutoInitialize
(
$options
[
'auto_initialize'
]
)
;
}
/** * @return void */
public
function
buildView
(
FormView
$view
, FormInterface
$form
, array
$options
)
{
$name
=
$form
->
getName
(
)
;
$blockName
=
$options
[
'block_name'
]
?:
$form
->
getName
(
)
;
$translationDomain
=
$options
[
'translation_domain'
]
;
'lastName' => 'Schussek',
]
)
;
$this
->form->
get
(
'lastName'
)
->
addError
(
new
FormError
(
'Invalid'
)
)
;
$this
->
assertFalse
(
$this
->form->
isValid
(
)
)
;
}
public
function
testDisabledFormsValidEvenIfChildrenInvalid
(
)
{
$form
=
$this
->
getBuilder
(
'person'
)
->
setDisabled
(
true
)
->
setCompound
(
true
)
->
setDataMapper
(
new
DataMapper
(
)
)
->
add
(
$this
->
getBuilder
(
'name'
)
)
->
getForm
(
)
;
$form
->
submit
(
[
'name' => 'Jacques Doe'
]
)
;
$form
->
get
(
'name'
)
->
addError
(
new
FormError
(
'Invalid'
)
)
;
$this
->
assertTrue
(
$form
->
isValid
(
)
)
;
}