| 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 | global $wpdb; |
| 729 | |
| 730 | return array( |
| 731 | 'division by zero is prevented' => array( |
| 732 | 'fraction' => '0/0', |
| 733 | 'expect' => '0/0', |
| 734 | ), |
| 735 | 'typical fnumber' => array( |
| 736 | 'fraction' => '4.8', |
| 737 | 'expect' => '4.8', |
| 738 | ), |
| 739 | 'typical focal length' => array( |
| 740 | 'fraction' => '37 mm', |
| 741 | 'expect' => '37 mm', |
| 742 | ), |
| 743 | 'typical exposure time' => array( |
| 744 | 'fraction' => '1/350', |
| 745 | 'expect' => 0.002857142857142857, |
| 746 | ), |
| 747 | 'division by text prevented' => array( |
| 748 | 'fraction' => '0/abc', |
| 749 | 'expect' => '0/abc', |
| 750 | ), |
| 751 | 'non fraction returns original value' => array( |
| 752 | 'fraction' => '0.0', |
| 753 | 'expect' => '0.0', |
| 754 | ), |
| 755 | 'non fraction returns original value' => array( |
| 756 | 'fraction' => '010', |
| 757 | 'expect' => '010', |
| 758 | ), |
| 759 | 'non fraction returns original value' => array( |
| 760 | 'fraction' => 10.123, |
| 761 | 'expect' => 10.123, |
| 762 | ), |
| 763 | 'valid fraction' => array( |
| 764 | 'fraction' => '50/100', |
| 765 | 'expect' => 0.5, |
| 766 | ), |
| 767 | 'valid fraction 2' => array( |
| 768 | 'fraction' => '25/100', |
| 769 | 'expect' => .25, |
| 770 | ), |
| 771 | 'valid fraction 3' => array( |
| 772 | 'fraction' => '4/2', |
| 773 | 'expect' => 2, |
| 774 | ), |
| 775 | 'non fraction returns original value' => array( |
| 776 | 'fraction' => '0', |
| 777 | 'expect' => '0', |
| 778 | ), |
| 779 | 'division by zero is prevented' => array( |
| 780 | 'fraction' => '100/0', |
| 781 | 'expect' => '100/0', |
| 782 | ), |
| 783 | 'text is prevented' => array( |
| 784 | 'fraction' => 'path/to/file', |
| 785 | 'expect' => 'path/to/file', |
| 786 | ), |
| 787 | 'text is prevented' => array( |
| 788 | 'fraction' => '123notafraction', |
| 789 | 'expect' => '123notafraction', |
| 790 | ), |
| 791 | 'invalid input prevented' => array( |
| 792 | 'fraction' => '/', |
| 793 | 'expect' => '/', |
| 794 | ), |
| 795 | 'invalid input prevented 2' => array( |
| 796 | 'fraction' => '1/2/3', |
| 797 | 'expect' => '1/2/3', |
| 798 | ), |
| 799 | 'invalid input prevented 3' => array( |
| 800 | 'fraction' => '///', |
| 801 | 'expect' => '///', |
| 802 | ), |
| 803 | ); |
| 804 | } |