[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/tests/phpunit/testcases/core/ -> attachments.php (source)

   1  <?php
   2  
   3  /**
   4   * @group core
   5   */
   6  
   7  class BP_Tests_Core_Attachments extends BP_UnitTestCase {
   8      /**
   9       * @group bp_attachments_list_directory_files
  10       */
  11  	public function test_bp_attachments_list_directory_files() {
  12          $files = bp_attachments_list_directory_files( BP_TESTS_DIR . 'assets' );
  13  
  14          $expected_keys = array( 'name', 'path', 'size', 'type', 'mime_type', 'last_modified', 'latest_access_date', 'id' );
  15  
  16          $directories = wp_filter_object_list( $files, array( 'mime_type' => 'directory' ) );
  17          $directory   = reset( $directories );
  18  
  19          $keys = array_keys( get_object_vars( $directory ) );
  20          sort( $keys );
  21          sort( $expected_keys );
  22  
  23          $this->assertSame( $keys, $expected_keys );
  24  
  25          $images = wp_filter_object_list( $files, array( 'mime_type' => 'image/jpeg' ) );
  26          $this->assertNotEmpty( $images );
  27  
  28          $scripts = wp_filter_object_list( $files, array( 'mime_type' => 'text/x-php' ) );
  29          $this->assertEmpty( $scripts );
  30      }
  31  
  32      /**
  33       * @group bp_attachments_list_directory_files_recursively
  34       */
  35      public function test_bp_attachments_list_directory_files_recursively() {
  36          add_filter( 'mime_types', array( $this, 'filter_mime_types' ) );
  37          $files = bp_attachments_list_directory_files_recursively( BP_TESTS_DIR . 'assets', 'index' );
  38          remove_filter( 'mime_types', array( $this, 'filter_mime_types' ) );
  39  
  40          $this->assertTrue( 1 === count( $files ) );
  41          $this->assertTrue( isset( $files['templates/index'] ) );
  42      }
  43  
  44  	public function filter_mime_types( $mime_types ) {
  45          $mime_types['php'] = 'text/x-php';
  46          return $mime_types;
  47      }
  48  }


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1