pictcode / lib / Cake / Test / Case / View / MediaViewTest.php @ 4c96e5a3
履歴 | 表示 | アノテート | ダウンロード (3.065 KB)
| 1 | 
      <?php
     | 
  
|---|---|
| 2 | 
      /**
     | 
  
| 3 | 
       * MediaViewTest file
     | 
  
| 4 | 
       *
     | 
  
| 5 | 
       * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
     | 
  
| 6 | 
       * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
     | 
  
| 7 | 
       *
     | 
  
| 8 | 
       * Licensed under The MIT License
     | 
  
| 9 | 
       * For full copyright and license information, please see the LICENSE.txt
     | 
  
| 10 | 
       * Redistributions of files must retain the above copyright notice
     | 
  
| 11 | 
       *
     | 
  
| 12 | 
       * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
     | 
  
| 13 | 
       * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
     | 
  
| 14 | 
       * @package       Cake.Test.Case.View
     | 
  
| 15 | 
       * @since         CakePHP(tm) v 1.2.0.4206
     | 
  
| 16 | 
       * @license       http://www.opensource.org/licenses/mit-license.php MIT License
     | 
  
| 17 | 
       */
     | 
  
| 18 | 
       | 
  
| 19 | 
      App::uses('Controller', 'Controller');  | 
  
| 20 | 
      App::uses('MediaView', 'View');  | 
  
| 21 | 
      App::uses('CakeResponse', 'Network');  | 
  
| 22 | 
       | 
  
| 23 | 
      /**
     | 
  
| 24 | 
       * MediaViewTest class
     | 
  
| 25 | 
       *
     | 
  
| 26 | 
       * @package       Cake.Test.Case.View
     | 
  
| 27 | 
       */
     | 
  
| 28 | 
      class MediaViewTest extends CakeTestCase {  | 
  
| 29 | 
       | 
  
| 30 | 
      /**
     | 
  
| 31 | 
       * setUp method
     | 
  
| 32 | 
       *
     | 
  
| 33 | 
       * @return void
     | 
  
| 34 | 
       */
     | 
  
| 35 | 
      public function setUp() {  | 
  
| 36 | 
                      parent::setUp();
     | 
  
| 37 | 
      $this->MediaView = new MediaView();  | 
  
| 38 | 
      $this->MediaView->response = $this->getMock('CakeResponse', array(  | 
  
| 39 | 
                              'cache',
     | 
  
| 40 | 
                              'type',
     | 
  
| 41 | 
                              'disableCache',
     | 
  
| 42 | 
                              'file',
     | 
  
| 43 | 
                              'send',
     | 
  
| 44 | 
                              'compress',
     | 
  
| 45 | 
      ));  | 
  
| 46 | 
      }  | 
  
| 47 | 
       | 
  
| 48 | 
      /**
     | 
  
| 49 | 
       * tearDown method
     | 
  
| 50 | 
       *
     | 
  
| 51 | 
       * @return void
     | 
  
| 52 | 
       */
     | 
  
| 53 | 
      public function tearDown() {  | 
  
| 54 | 
                      parent::tearDown();
     | 
  
| 55 | 
      unset($this->MediaView);  | 
  
| 56 | 
      }  | 
  
| 57 | 
       | 
  
| 58 | 
      /**
     | 
  
| 59 | 
       * testRender method
     | 
  
| 60 | 
       *
     | 
  
| 61 | 
       * @return void
     | 
  
| 62 | 
       */
     | 
  
| 63 | 
      public function testRender() {  | 
  
| 64 | 
      $vars = array(  | 
  
| 65 | 
      'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,  | 
  
| 66 | 
      'id' => 'test_asset.css'  | 
  
| 67 | 
      );  | 
  
| 68 | 
      $this->MediaView->viewVars = $vars;  | 
  
| 69 | 
       | 
  
| 70 | 
      $this->MediaView->response->expects($this->once())  | 
  
| 71 | 
                              ->method('disableCache');
     | 
  
| 72 | 
       | 
  
| 73 | 
      $this->MediaView->response->expects($this->once())  | 
  
| 74 | 
                              ->method('file')
     | 
  
| 75 | 
      ->with(  | 
  
| 76 | 
      $vars['path'] . $vars['id'],  | 
  
| 77 | 
      array('name' => null, 'download' => null)  | 
  
| 78 | 
      );  | 
  
| 79 | 
       | 
  
| 80 | 
      $this->MediaView->render();  | 
  
| 81 | 
      }  | 
  
| 82 | 
       | 
  
| 83 | 
      /**
     | 
  
| 84 | 
       * Test render() when caching is on.
     | 
  
| 85 | 
       *
     | 
  
| 86 | 
       * @return void
     | 
  
| 87 | 
       */
     | 
  
| 88 | 
      public function testRenderCachingAndName() {  | 
  
| 89 | 
      $vars = array(  | 
  
| 90 | 
      'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS,  | 
  
| 91 | 
      'id' => 'test_asset.css',  | 
  
| 92 | 
      'cache' => '+1 day',  | 
  
| 93 | 
      'name' => 'something_special',  | 
  
| 94 | 
      'download' => true,  | 
  
| 95 | 
      );  | 
  
| 96 | 
      $this->MediaView->viewVars = $vars;  | 
  
| 97 | 
       | 
  
| 98 | 
      $this->MediaView->response->expects($this->never())  | 
  
| 99 | 
                              ->method('disableCache');
     | 
  
| 100 | 
       | 
  
| 101 | 
      $this->MediaView->response->expects($this->once())  | 
  
| 102 | 
                              ->method('cache')
     | 
  
| 103 | 
      ->with($this->anything(), $vars['cache']);  | 
  
| 104 | 
       | 
  
| 105 | 
      $this->MediaView->response->expects($this->once())  | 
  
| 106 | 
                              ->method('file')
     | 
  
| 107 | 
      ->with(  | 
  
| 108 | 
      $vars['path'] . $vars['id'],  | 
  
| 109 | 
                                      array(
     | 
  
| 110 | 
      'name' => 'something_special.css',  | 
  
| 111 | 
      'download' => true  | 
  
| 112 | 
      )  | 
  
| 113 | 
      );  | 
  
| 114 | 
       | 
  
| 115 | 
      $this->MediaView->render();  | 
  
| 116 | 
      }  | 
  
| 117 | 
       | 
  
| 118 | 
      /**
     | 
  
| 119 | 
       * Test downloading files with UPPERCASE extensions.
     | 
  
| 120 | 
       *
     | 
  
| 121 | 
       * @return void
     | 
  
| 122 | 
       */
     | 
  
| 123 | 
      public function testRenderUpperExtension() {  | 
  
| 124 | 
      $this->MediaView->viewVars = array(  | 
  
| 125 | 
      'path' => CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'img' . DS,  | 
  
| 126 | 
      'id' => 'test_2.JPG'  | 
  
| 127 | 
      );  | 
  
| 128 | 
       | 
  
| 129 | 
      $this->MediaView->response->expects($this->any())  | 
  
| 130 | 
                              ->method('type')
     | 
  
| 131 | 
                              ->with('jpg')
     | 
  
| 132 | 
      ->will($this->returnArgument(0));  | 
  
| 133 | 
       | 
  
| 134 | 
      $this->MediaView->render();  | 
  
| 135 | 
      }  | 
  
| 136 | 
       | 
  
| 137 | 
      }  |