| @@ 365-422 (lines=58) @@ | ||
| 362 | $this->assertEquals($expectedMimeType, $filteredBinary->getMimeType()); |
|
| 363 | } |
|
| 364 | ||
| 365 | public function testAltersQualityOnApplyFilter() |
|
| 366 | { |
|
| 367 | $originalContent = 'aOriginalContent'; |
|
| 368 | $expectedQuality = 80; |
|
| 369 | ||
| 370 | $binary = new Binary($originalContent, 'image/png', 'png'); |
|
| 371 | ||
| 372 | $thumbConfig = array( |
|
| 373 | 'size' => array(180, 180), |
|
| 374 | 'mode' => 'outbound', |
|
| 375 | ); |
|
| 376 | ||
| 377 | $config = $this->createFilterConfigurationMock(); |
|
| 378 | $config |
|
| 379 | ->expects($this->atLeastOnce()) |
|
| 380 | ->method('get') |
|
| 381 | ->with('thumbnail') |
|
| 382 | ->will($this->returnValue(array( |
|
| 383 | 'quality' => $expectedQuality, |
|
| 384 | 'filters' => array( |
|
| 385 | 'thumbnail' => $thumbConfig, |
|
| 386 | ), |
|
| 387 | 'post_processors' => array(), |
|
| 388 | ))) |
|
| 389 | ; |
|
| 390 | ||
| 391 | $image = $this->getMockImage(); |
|
| 392 | $image |
|
| 393 | ->expects($this->once()) |
|
| 394 | ->method('get') |
|
| 395 | ->with('png', array('quality' => $expectedQuality)) |
|
| 396 | ->will($this->returnValue('aFilteredContent')) |
|
| 397 | ; |
|
| 398 | ||
| 399 | $imagine = $this->createImagineMock(); |
|
| 400 | $imagine |
|
| 401 | ->expects($this->once()) |
|
| 402 | ->method('load') |
|
| 403 | ->will($this->returnValue($image)) |
|
| 404 | ; |
|
| 405 | ||
| 406 | $loader = $this->getMockLoader(); |
|
| 407 | $loader |
|
| 408 | ->expects($this->once()) |
|
| 409 | ->method('load') |
|
| 410 | ->with($this->identicalTo($image), $thumbConfig) |
|
| 411 | ->will($this->returnArgument(0)) |
|
| 412 | ; |
|
| 413 | ||
| 414 | $filterManager = new FilterManager( |
|
| 415 | $config, |
|
| 416 | $imagine, |
|
| 417 | $this->getMockMimeTypeGuesser() |
|
| 418 | ); |
|
| 419 | $filterManager->addLoader('thumbnail', $loader); |
|
| 420 | ||
| 421 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); |
|
| 422 | } |
|
| 423 | ||
| 424 | public function testAlters100QualityIfNotSetOnApplyFilter() |
|
| 425 | { |
|
| @@ 424-480 (lines=57) @@ | ||
| 421 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); |
|
| 422 | } |
|
| 423 | ||
| 424 | public function testAlters100QualityIfNotSetOnApplyFilter() |
|
| 425 | { |
|
| 426 | $originalContent = 'aOriginalContent'; |
|
| 427 | $expectedQuality = 100; |
|
| 428 | ||
| 429 | $binary = new Binary($originalContent, 'image/png', 'png'); |
|
| 430 | ||
| 431 | $thumbConfig = array( |
|
| 432 | 'size' => array(180, 180), |
|
| 433 | 'mode' => 'outbound', |
|
| 434 | ); |
|
| 435 | ||
| 436 | $config = $this->createFilterConfigurationMock(); |
|
| 437 | $config |
|
| 438 | ->expects($this->atLeastOnce()) |
|
| 439 | ->method('get') |
|
| 440 | ->with('thumbnail') |
|
| 441 | ->will($this->returnValue(array( |
|
| 442 | 'filters' => array( |
|
| 443 | 'thumbnail' => $thumbConfig, |
|
| 444 | ), |
|
| 445 | 'post_processors' => array(), |
|
| 446 | ))) |
|
| 447 | ; |
|
| 448 | ||
| 449 | $image = $this->getMockImage(); |
|
| 450 | $image |
|
| 451 | ->expects($this->once()) |
|
| 452 | ->method('get') |
|
| 453 | ->with('png', array('quality' => $expectedQuality)) |
|
| 454 | ->will($this->returnValue('aFilteredContent')) |
|
| 455 | ; |
|
| 456 | ||
| 457 | $imagine = $this->createImagineMock(); |
|
| 458 | $imagine |
|
| 459 | ->expects($this->once()) |
|
| 460 | ->method('load') |
|
| 461 | ->will($this->returnValue($image)) |
|
| 462 | ; |
|
| 463 | ||
| 464 | $loader = $this->getMockLoader(); |
|
| 465 | $loader |
|
| 466 | ->expects($this->once()) |
|
| 467 | ->method('load') |
|
| 468 | ->with($this->identicalTo($image), $thumbConfig) |
|
| 469 | ->will($this->returnArgument(0)) |
|
| 470 | ; |
|
| 471 | ||
| 472 | $filterManager = new FilterManager( |
|
| 473 | $config, |
|
| 474 | $imagine, |
|
| 475 | $this->getMockMimeTypeGuesser() |
|
| 476 | ); |
|
| 477 | $filterManager->addLoader('thumbnail', $loader); |
|
| 478 | ||
| 479 | $this->assertInstanceOf('Liip\ImagineBundle\Model\Binary', $filterManager->applyFilter($binary, 'thumbnail')); |
|
| 480 | } |
|
| 481 | ||
| 482 | public function testMergeRuntimeConfigWithOneFromFilterConfigurationOnApplyFilter() |
|
| 483 | { |
|