View source
<?php
namespace Drupal\Tests\imce\Kernel\Plugin\ImcePlugin;
use Drupal\imce\Imce;
use Drupal\imce\ImcePluginInterface;
use Drupal\imce\Plugin\ImcePlugin\Newfolder;
use Drupal\Tests\imce\Kernel\Plugin\KernelTestBasePlugin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
class NewFolderTest extends KernelTestBasePlugin {
public $newFolder;
public $imceFM;
public static $modules = [
'user',
'config',
'file',
'system',
'imce',
];
protected function setUp() {
parent::setUp();
$this->imceFM = $this
->getImceFM();
$this->newFolder = new Newfolder([], 'newfolder', []);
$this->newFolder
->opNewfolder($this->imceFM);
}
public function getRequest() {
$request = Request::create("/imce", 'POST', [
'jsop' => 'newfolder',
'token' => 'LLuA1R0aUOzoduSJkJxN5aoHVdJnQk8LbTBgdivOU4Y',
'active_path' => '.',
'newfolder' => 'folder-test',
]);
$session = new Session();
$session
->set('imce_active_path', '.');
$request
->setSession($session);
return $request;
}
public function getConf() {
return [
'permissions' => [
'all' => TRUE,
],
];
}
public function getPluginDefinations() {
return [
'weight' => '-15',
'operations' => [
'newfolder' => "opNewfolder",
],
'id' => "newfolder",
'label' => "New Folder",
'class' => "Drupal\\imce\\Plugin\\ImcePlugin\\Newfolder",
'provider' => "imce",
];
}
public function testPermissiomInfo() {
$permissionInfo = $this->newFolder
->permissionInfo();
$this
->assertTrue(is_array($permissionInfo));
$this
->assertTrue(in_array('Create subfolders', $permissionInfo));
}
public function testFolderCreate() {
$uriFolder = Imce::joinPaths($this->imceFM->activeFolder
->getUri(), $this->imceFM
->getPost('newfolder'));
$this
->assertTrue(is_string($uriFolder));
$this
->assertTrue(file_exists($uriFolder));
}
public function testMessages() {
$messages = $this->imceFM
->getMessages();
$this
->assertTrue(is_array($messages));
$this
->assertEquals([], $messages);
}
public function testCore() {
$this
->assertInstanceOf(ImcePluginInterface::class, $this->newFolder);
}
public function testOperation() {
$this
->assertEquals($this->imceFM
->getOp(), 'newfolder');
}
}