Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1167969
unit_formatterTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Sep 24, 6:18 AM
Size
2 KB
Mime Type
text/x-php
Expires
Fri, Sep 26, 6:18 AM (1 d, 1 m)
Engine
blob
Format
Raw Data
Handle
756593
Attached To
rINP In-Portal
unit_formatterTest.php
View Options
<?php
/**
* The class name must match the file name for Phabricator-invoked PHPUnit to run this test.
*
* TODO: Once "unit_formatter.php" file is renamed we can rename this class/filename as well.
*/
final
class
unit_formatterTest
extends
AbstractTestCase
// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
{
/**
* Fixture of the kDBItem class.
*
* @var kDBItem
*/
protected
$dbItemFixture
;
/**
* @before
*/
protected
function
setUpTest
()
{
$db_item
=
new
kDBItem
();
$db_item
->
Init
(
'stop-word'
,
''
);
// Existing unit used for the "ValidatorClass" unit config option to work.
$db_item
->
SetFieldOptions
(
'SampleField'
,
array
());
$db_item
->
SetFieldOptions
(
'SampleField_a'
,
array
());
$db_item
->
SetFieldOptions
(
'SampleField_b'
,
array
());
$this
->
dbItemFixture
=
$db_item
;
/** @var LanguagesItem $regional */
$regional
=
$this
->
Application
->
recallObject
(
'lang.current'
);
$regional
->
SetDBField
(
'UnitSystem'
,
2
);
}
public
function
testNonNumericUpdateSubFields
()
{
$unit_formatter
=
new
kUnitFormatter
();
$options
=
array
();
$unit_formatter
->
UpdateSubFields
(
'SampleField'
,
'non-numeric'
,
$options
,
$this
->
dbItemFixture
);
$this
->
assertSame
(
0.0
,
$this
->
dbItemFixture
->
GetDBField
(
'SampleField_a'
));
$this
->
assertSame
(
0.0
,
$this
->
dbItemFixture
->
GetDBField
(
'SampleField_b'
));
}
/**
* @dataProvider nonNumericUpdateMasterFieldsDataProvider
*/
public
function
testNonNumericUpdateMasterFields
(
$pounds
,
$ounces
,
$expected
)
{
$unit_formatter
=
new
kUnitFormatter
();
$options
=
array
();
$this
->
dbItemFixture
->
SetDBField
(
'SampleField_a'
,
$pounds
);
$this
->
dbItemFixture
->
SetDBField
(
'SampleField_b'
,
$ounces
);
$unit_formatter
->
UpdateMasterFields
(
'SampleField'
,
'non-numeric'
,
$options
,
$this
->
dbItemFixture
);
$this
->
assertSame
(
$expected
,
$this
->
dbItemFixture
->
GetDBField
(
'SampleField'
));
}
public
static
function
nonNumericUpdateMasterFieldsDataProvider
()
{
return
array
(
'pounds numeric, ounces non-numeric'
=>
array
(
1.5
,
'non-numeric'
,
0.68039
),
'pounds non-numeric, ounces numeric'
=>
array
(
'non-numeric'
,
24
,
0.68039
),
'both pounds and ounces non-numeric'
=>
array
(
'non-numeric'
,
'non-numeric'
,
0.0
),
);
}
}
Event Timeline
Log In to Comment