Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
50f97a05
Commit
50f97a05
authored
May 06, 2015
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for qa_format_number
parent
9d871fbb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
1 deletions
+74
-1
AppFormatTest.php
qa-tests/AppFormatTest.php
+74
-0
AppUsersTest.php
qa-tests/AppUsersTest.php
+0
-1
No files found.
qa-tests/AppFormatTest.php
0 → 100644
View file @
50f97a05
<?php
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
class
AppFormatTest
extends
PHPUnit_Framework_TestCase
{
/**
* Test basic number formatting (no compact numbers)
*/
public
function
test__qa_format_number
()
{
// set options/lang cache to bypass database
global
$qa_options_cache
,
$qa_phrases_custom
;
$qa_options_cache
[
'show_compact_numbers'
]
=
'0'
;
$qa_phrases_custom
[
'main'
][
'_decimal_point'
]
=
'.'
;
$qa_phrases_custom
[
'main'
][
'_thousands_separator'
]
=
','
;
$this
->
assertSame
(
'5.5'
,
qa_format_number
(
5.452
,
1
)
);
$this
->
assertSame
(
'5'
,
qa_format_number
(
5.452
,
0
)
);
$this
->
assertSame
(
'9,123'
,
qa_format_number
(
9123
,
0
));
$this
->
assertSame
(
'9,123.0'
,
qa_format_number
(
9123
,
1
));
// $compact parameter should have no effect here
$this
->
assertSame
(
'9,123.0'
,
qa_format_number
(
9123
,
1
,
true
));
$this
->
assertSame
(
'123,456,789'
,
qa_format_number
(
123456789
,
0
,
true
));
// change separators
$qa_phrases_custom
[
'main'
][
'_decimal_point'
]
=
','
;
$qa_phrases_custom
[
'main'
][
'_thousands_separator'
]
=
'.'
;
$this
->
assertSame
(
'5,5'
,
qa_format_number
(
5.452
,
1
));
$this
->
assertSame
(
'5'
,
qa_format_number
(
5.452
,
0
));
$this
->
assertSame
(
'9.123'
,
qa_format_number
(
9123
,
0
));
$this
->
assertSame
(
'9.123,0'
,
qa_format_number
(
9123
,
1
));
}
/**
* Test number formatting including compact numbers (e.g. 1.3k)
*/
public
function
test__qa_format_number__compact
()
{
// set options/lang cache to bypass database
global
$qa_options_cache
,
$qa_phrases_custom
;
$qa_options_cache
[
'show_compact_numbers'
]
=
'1'
;
$qa_phrases_custom
[
'main'
][
'_decimal_point'
]
=
'.'
;
$qa_phrases_custom
[
'main'
][
'_thousands_separator'
]
=
','
;
$qa_phrases_custom
[
'main'
][
'_thousands_suffix'
]
=
'k'
;
$qa_phrases_custom
[
'main'
][
'_millions_suffix'
]
=
'm'
;
$this
->
assertSame
(
'9.1k'
,
qa_format_number
(
9123
,
1
,
true
));
$this
->
assertSame
(
'9k'
,
qa_format_number
(
9123
,
0
,
true
));
$this
->
assertSame
(
'9k'
,
qa_format_number
(
9000
,
0
,
true
));
$this
->
assertSame
(
'9k'
,
qa_format_number
(
9000
,
1
,
true
));
$this
->
assertSame
(
'123m'
,
qa_format_number
(
123456789
,
0
,
true
));
$this
->
assertSame
(
'235m'
,
qa_format_number
(
234567891
,
0
,
true
));
$this
->
assertSame
(
'123m'
,
qa_format_number
(
123456789
,
1
,
true
));
$this
->
assertSame
(
'235m'
,
qa_format_number
(
234567891
,
1
,
true
));
$this
->
assertSame
(
'9,000'
,
qa_format_number
(
9000
,
0
,
false
));
$this
->
assertSame
(
'123,456,789'
,
qa_format_number
(
123456789
,
0
,
false
));
// change compact suffixes
$qa_phrases_custom
[
'main'
][
'_thousands_suffix'
]
=
'th'
;
$qa_phrases_custom
[
'main'
][
'_millions_suffix'
]
=
'mi'
;
$this
->
assertSame
(
'9.1th'
,
qa_format_number
(
9123
,
1
,
true
));
$this
->
assertSame
(
'9th'
,
qa_format_number
(
9123
,
0
,
true
));
$this
->
assertSame
(
'123mi'
,
qa_format_number
(
123456789
,
0
,
true
));
}
}
qa-tests/AppUsersTest.php
View file @
50f97a05
<?php
require_once
QA_INCLUDE_DIR
.
'app/users.php'
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
class
AppUsersTest
extends
PHPUnit_Framework_TestCase
{
...
...
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