| 703 | |
| 704 | /** |
| 705 | * Test for wp_exif_frac2dec verified that it properly handles edge cases |
| 706 | * and always returns an int or float, or original value for failures. |
| 707 | * |
| 708 | * @param string $fraction The fraction to convert. |
| 709 | * @param string $expect The expected result. |
| 710 | * |
| 711 | * @ticket 54385 |
| 712 | * @dataProvider data_wp_exif_frac2dec |
| 713 | * |
| 714 | * @covers ::wp_exif_frac2dec |
| 715 | */ |
| 716 | public function test_wp_exif_frac2dec( $fraction, $expect ) { |
| 717 | $this->assertSame( $expect, wp_exif_frac2dec( $fraction ) ); |
| 718 | } |
| 719 | |
| 720 | |
| 721 | /** |
| 722 | * Data provider for testing `wp_exif_frac2dec()`. |
| 723 | * |
| 724 | * @return array { |
| 725 | * Arguments for testing `wp_exif_frac2dec()`. |
| 726 | */ |
| 727 | public function data_wp_exif_frac2dec() { |
| 728 | return array( |
| 729 | 'division by zero is prevented' => array( |
| 730 | 'fraction' => '0/0', |
| 731 | 'expect' => '0/0', |
| 732 | ), |
| 733 | 'division by zero is prevented 2' => array( |
| 734 | 'fraction' => '100/0', |
| 735 | 'expect' => '100/0', |
| 736 | ), |
| 737 | 'typical fnumber' => array( |
| 738 | 'fraction' => '4.8', |
| 739 | 'expect' => '4.8', |
| 740 | ), |
| 741 | 'typical focal length' => array( |
| 742 | 'fraction' => '37 mm', |
| 743 | 'expect' => '37 mm', |
| 744 | ), |
| 745 | 'typical exposure time' => array( |
| 746 | 'fraction' => '1/350', |
| 747 | 'expect' => 0.002857142857142857, |
| 748 | ), |
| 749 | 'division by text prevented' => array( |
| 750 | 'fraction' => '0/abc', |
| 751 | 'expect' => '0/abc', |
| 752 | ), |
| 753 | 'non fraction returns original value' => array( |
| 754 | 'fraction' => '0.0', |
| 755 | 'expect' => '0.0', |
| 756 | ), |
| 757 | 'non fraction returns original value 2' => array( |
| 758 | 'fraction' => '010', |
| 759 | 'expect' => '010', |
| 760 | ), |
| 761 | 'non fraction returns original value 3' => array( |
| 762 | 'fraction' => 10.123, |
| 763 | 'expect' => 10.123, |
| 764 | ), |
| 765 | 'valid fraction' => array( |
| 766 | 'fraction' => '50/100', |
| 767 | 'expect' => 0.5, |
| 768 | ), |
| 769 | 'valid fraction 2' => array( |
| 770 | 'fraction' => '25/100', |
| 771 | 'expect' => .25, |
| 772 | ), |
| 773 | 'valid fraction 3' => array( |
| 774 | 'fraction' => '4/2', |
| 775 | 'expect' => 2, |
| 776 | ), |
| 777 | 'non fraction returns original value' => array( |
| 778 | 'fraction' => '0', |
| 779 | 'expect' => '0', |
| 780 | ), |
| 781 | 'text is prevented' => array( |
| 782 | 'fraction' => 'path/to/file', |
| 783 | 'expect' => 'path/to/file', |
| 784 | ), |
| 785 | 'text is prevented 2' => array( |
| 786 | 'fraction' => '123notafraction', |
| 787 | 'expect' => '123notafraction', |
| 788 | ), |
| 789 | 'invalid input prevented' => array( |
| 790 | 'fraction' => '/', |
| 791 | 'expect' => '/', |
| 792 | ), |
| 793 | 'invalid input prevented 2' => array( |
| 794 | 'fraction' => '1/2/3', |
| 795 | 'expect' => '1/2/3', |
| 796 | ), |
| 797 | 'invalid input prevented 3' => array( |
| 798 | 'fraction' => '///', |
| 799 | 'expect' => '///', |
| 800 | ), |
| 801 | 'null value' => array( |
| 802 | 'fraction' => null, |
| 803 | 'expect' => null, |
| 804 | ), |
| 805 | 'empty array value' => array( |
| 806 | 'fraction' => array(), |
| 807 | 'expect' => array(), |
| 808 | ), |
| 809 | ); |
| 810 | } |