| @@ 854-905 (lines=52) @@ | ||
| 851 | $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); |
|
| 852 | } |
|
| 853 | ||
| 854 | public function testAltersQualityOnApply() |
|
| 855 | { |
|
| 856 | $originalContent = 'aOriginalContent'; |
|
| 857 | $expectedQuality = 80; |
|
| 858 | ||
| 859 | $binary = new Binary($originalContent, 'image/png', 'png'); |
|
| 860 | ||
| 861 | $thumbConfig = array( |
|
| 862 | 'size' => array(180, 180), |
|
| 863 | 'mode' => 'outbound', |
|
| 864 | ); |
|
| 865 | ||
| 866 | $image = $this->getMockImage(); |
|
| 867 | $image |
|
| 868 | ->expects($this->once()) |
|
| 869 | ->method('get') |
|
| 870 | ->with('png', array('quality' => $expectedQuality)) |
|
| 871 | ->will($this->returnValue('aFilteredContent')) |
|
| 872 | ; |
|
| 873 | ||
| 874 | $imagineMock = $this->createImagineMock(); |
|
| 875 | $imagineMock |
|
| 876 | ->expects($this->once()) |
|
| 877 | ->method('load') |
|
| 878 | ->will($this->returnValue($image)) |
|
| 879 | ; |
|
| 880 | ||
| 881 | $loader = $this->getMockLoader(); |
|
| 882 | $loader |
|
| 883 | ->expects($this->once()) |
|
| 884 | ->method('load') |
|
| 885 | ->with($this->identicalTo($image), $thumbConfig) |
|
| 886 | ->will($this->returnArgument(0)) |
|
| 887 | ; |
|
| 888 | ||
| 889 | $filterManager = new FilterManager( |
|
| 890 | $this->createFilterConfigurationMock(), |
|
| 891 | $imagineMock, |
|
| 892 | $this->getMockMimeTypeGuesser() |
|
| 893 | ); |
|
| 894 | $filterManager->addLoader('thumbnail', $loader); |
|
| 895 | ||
| 896 | $filteredBinary = $filterManager->apply($binary, array( |
|
| 897 | 'quality' => $expectedQuality, |
|
| 898 | 'filters' => array( |
|
| 899 | 'thumbnail' => $thumbConfig, |
|
| 900 | ), |
|
| 901 | 'post_processors' => array(), |
|
| 902 | )); |
|
| 903 | ||
| 904 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); |
|
| 905 | } |
|
| 906 | ||
| 907 | public function testAlters100QualityIfNotSetOnApply() |
|
| 908 | { |
|
| @@ 907-957 (lines=51) @@ | ||
| 904 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); |
|
| 905 | } |
|
| 906 | ||
| 907 | public function testAlters100QualityIfNotSetOnApply() |
|
| 908 | { |
|
| 909 | $originalContent = 'aOriginalContent'; |
|
| 910 | $expectedQuality = 100; |
|
| 911 | ||
| 912 | $binary = new Binary($originalContent, 'image/png', 'png'); |
|
| 913 | ||
| 914 | $thumbConfig = array( |
|
| 915 | 'size' => array(180, 180), |
|
| 916 | 'mode' => 'outbound', |
|
| 917 | ); |
|
| 918 | ||
| 919 | $image = $this->getMockImage(); |
|
| 920 | $image |
|
| 921 | ->expects($this->once()) |
|
| 922 | ->method('get') |
|
| 923 | ->with('png', array('quality' => $expectedQuality)) |
|
| 924 | ->will($this->returnValue('aFilteredContent')) |
|
| 925 | ; |
|
| 926 | ||
| 927 | $imagineMock = $this->createImagineMock(); |
|
| 928 | $imagineMock |
|
| 929 | ->expects($this->once()) |
|
| 930 | ->method('load') |
|
| 931 | ->will($this->returnValue($image)) |
|
| 932 | ; |
|
| 933 | ||
| 934 | $loader = $this->getMockLoader(); |
|
| 935 | $loader |
|
| 936 | ->expects($this->once()) |
|
| 937 | ->method('load') |
|
| 938 | ->with($this->identicalTo($image), $thumbConfig) |
|
| 939 | ->will($this->returnArgument(0)) |
|
| 940 | ; |
|
| 941 | ||
| 942 | $filterManager = new FilterManager( |
|
| 943 | $this->createFilterConfigurationMock(), |
|
| 944 | $imagineMock, |
|
| 945 | $this->getMockMimeTypeGuesser() |
|
| 946 | ); |
|
| 947 | $filterManager->addLoader('thumbnail', $loader); |
|
| 948 | ||
| 949 | $filteredBinary = $filterManager->apply($binary, array( |
|
| 950 | 'filters' => array( |
|
| 951 | 'thumbnail' => $thumbConfig, |
|
| 952 | ), |
|
| 953 | 'post_processors' => array(), |
|
| 954 | )); |
|
| 955 | ||
| 956 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filteredBinary); |
|
| 957 | } |
|
| 958 | ||
| 959 | public function testApplyPostProcessor() |
|
| 960 | { |
|