From 74dafc653a8faea69057a6f268b7828d1a8bb1f7 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 16 Jan 2018 11:04:12 -0700 Subject: [PATCH] Tests for customfields read options from file --- api/tests/Storage/CustomfieldsTest.php | 69 +++++++++++++++++++ api/tests/fixtures/Storage/greek_options.php | 29 ++++++++ .../fixtures/Storage/infolog_subs_option.php | 5 ++ 3 files changed, 103 insertions(+) create mode 100644 api/tests/fixtures/Storage/greek_options.php create mode 100644 api/tests/fixtures/Storage/infolog_subs_option.php diff --git a/api/tests/Storage/CustomfieldsTest.php b/api/tests/Storage/CustomfieldsTest.php index 51dc6fcb81..9389574c8c 100644 --- a/api/tests/Storage/CustomfieldsTest.php +++ b/api/tests/Storage/CustomfieldsTest.php @@ -172,6 +172,75 @@ class CustomfieldsTest extends LoggedInTest Customfields::save(self::APP, $fields); } + /** + * Test getting options from a file + * + * @dataProvider fileOptionProvider + */ + public function testGetOptionsFromGoodFile($expected, $file) + { + // Load + $options = Customfields::get_options_from_file('api/tests/fixtures/Storage/'.$file); + + // Check + $this->assertInternalType('array', $options); + $this->assertEquals($expected, $options); + } + + /** + * Provide some options (duplicated in the files) to check loading + * + * @return array + */ + public function fileOptionProvider() + { + // Expected options, file + return array( + array(array( + '' => 'Select', + 'Α'=> 'α Alpha', + 'Β'=> 'β Beta', + 'Γ'=> 'γ Gamma', + 'Δ'=> 'δ Delta', + 'Ε'=> 'ε Epsilon', + 'Ζ'=> 'ζ Zeta', + 'Η'=> 'η Eta', + 'Θ'=> 'θ Theta', + 'Ι'=> 'ι Iota', + 'Κ'=> 'κ Kappa', + 'Λ'=> 'λ Lambda', + 'Μ'=> 'μ Mu', + 'Ν'=> 'ν Nu', + 'Ξ'=> 'ξ Xi', + 'Ο'=> 'ο Omicron', + 'Π'=> 'π Pi', + 'Ρ'=> 'ρ Rho', + 'Σ'=> 'σ Sigma', + 'Τ'=> 'τ Tau', + 'Υ'=> 'υ Upsilon', + 'Φ'=> 'φ Phi', + 'Χ'=> 'χ Chi', + 'Ψ'=> 'ψ Psi', + 'Ω'=> 'ω Omega' + ), 'greek_options.php'), + array(array( + 'View Subs' => "egw_open('','infolog','list',{action:'sp',action_id:widget.getRoot().getArrayMgr('content').getEntry('info_id')},'infolog','infolog');" + ), 'infolog_subs_option.php') + ); + } + + /** + * A file that is not found or cannot be read should return an array + * with an error message, and not error. It's impossible to deal with an + * actual invalid file though, they just cause Fatal Errors. + */ + public function testGetOptionsFromMissingFile() + { + $options = Customfields::get_options_from_file('totally invalid'); + $this->assertInternalType('array', $options); + $this->assertCount(1, $options); + } + protected function create_private_field() { // Create field diff --git a/api/tests/fixtures/Storage/greek_options.php b/api/tests/fixtures/Storage/greek_options.php new file mode 100644 index 0000000000..5ecaed7537 --- /dev/null +++ b/api/tests/fixtures/Storage/greek_options.php @@ -0,0 +1,29 @@ + 'Select', + 'Α'=> 'α Alpha', + 'Β'=> 'β Beta', + 'Γ'=> 'γ Gamma', + 'Δ'=> 'δ Delta', + 'Ε'=> 'ε Epsilon', + 'Ζ'=> 'ζ Zeta', + 'Η'=> 'η Eta', + 'Θ'=> 'θ Theta', + 'Ι'=> 'ι Iota', + 'Κ'=> 'κ Kappa', + 'Λ'=> 'λ Lambda', + 'Μ'=> 'μ Mu', + 'Ν'=> 'ν Nu', + 'Ξ'=> 'ξ Xi', + 'Ο'=> 'ο Omicron', + 'Π'=> 'π Pi', + 'Ρ'=> 'ρ Rho', + 'Σ'=> 'σ Sigma', + 'Τ'=> 'τ Tau', + 'Υ'=> 'υ Upsilon', + 'Φ'=> 'φ Phi', + 'Χ'=> 'χ Chi', + 'Ψ'=> 'ψ Psi', + 'Ω'=> 'ω Omega' + ); \ No newline at end of file diff --git a/api/tests/fixtures/Storage/infolog_subs_option.php b/api/tests/fixtures/Storage/infolog_subs_option.php new file mode 100644 index 0000000000..d0e95254a8 --- /dev/null +++ b/api/tests/fixtures/Storage/infolog_subs_option.php @@ -0,0 +1,5 @@ + "egw_open('','infolog','list',{action:'sp',action_id:widget.getRoot().getArrayMgr('content').getEntry('info_id')},'infolog','infolog');" + );