You are here

UploadTest.php in IMCE 8

Same filename and directory in other branches
  1. 8.2 tests/src/Kernel/Plugin/ImcePlugin/UploadTest.php

File

tests/src/Kernel/Plugin/ImcePlugin/UploadTest.php
View source
<?php

namespace Drupal\Tests\imce\Kernel\Plugin\ImcePlugin;

use Drupal\imce\ImcePluginInterface;
use Drupal\imce\Plugin\ImcePlugin\Upload;
use Drupal\Tests\imce\Kernel\Plugin\KernelTestBasePlugin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

/**
 * Kernel tests for Imce plugins for Imce Plugin Core.
 *
 * @group imce
 */
class UploadTest extends KernelTestBasePlugin {

  /**
   * The Imce ckeditor plugin.
   *
   * @var \Drupal\imce\Plugin\ImcePlugin\Upload
   */
  public $upload;

  /**
   * The Imce file manager.
   *
   * @var \Drupal\imce\ImceFM
   */
  public $imceFM;

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'user',
    'system',
    'imce',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->imceFM = $this
      ->getImceFM();
    $this->upload = new Upload([], "upload", $this
      ->getPluginDefinations());
  }

  /**
   * {@inheritDoc}
   */
  public function getRequest() {
    $request = Request::create("/imce", 'POST', [
      'jsop' => 'upload',
      'token' => 'LLuA1R0aUOzoduSJkJxN5aoHVdJnQk8LbTBgdivOU4Y',
      'active_path' => '.',
      'files[imce][]' => 'file.txt',
    ]);
    $session = new Session();
    $session
      ->set('imce_active_path', '.');
    $request
      ->setSession($session);
    return $request;
  }

  /**
   * This method will be removed.
   */
  public function test() {
    $this
      ->assertEquals('test', 'test');
  }

  /**
   * Test Upload::permissionInfo()
   */
  public function testPermissionInfo() {
    $permissionInfo = $this->upload
      ->permissionInfo();
    $this
      ->assertTrue(is_array($permissionInfo));
    $this
      ->assertTrue(in_array('Upload files', $permissionInfo));
  }

  /**
   * Teste messages on context ImcePlugin\Upload.
   */
  public function testMessages() {
    $messages = $this->imceFM
      ->getMessages();
    $this
      ->assertTrue(is_array($messages));
    $this
      ->assertEquals([], $messages);
  }

  /**
   * Test Upload type.
   */
  public function testCore() {
    $this
      ->assertInstanceOf(ImcePluginInterface::class, $this->upload);
  }

  /**
   * Test upload operation.
   */
  public function testOperation() {
    $this
      ->assertEquals($this->imceFM
      ->getOp(), 'upload');
  }

}

Classes

Namesort descending Description
UploadTest Kernel tests for Imce plugins for Imce Plugin Core.