View source
<?php
namespace Drupal\Tests\imce\Kernel\Plugin\ImcePlugin;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\imce\ImceFolder;
use Drupal\imce\ImcePluginInterface;
use Drupal\imce\Plugin\ImcePlugin\Resize;
use Drupal\Tests\imce\Kernel\Plugin\KernelTestBasePlugin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
class ResizeTest extends KernelTestBasePlugin {
use StringTranslationTrait;
public $resize;
public $imceFM;
public static $modules = [
'user',
'config',
'file',
'system',
'imce',
];
protected function setUp() {
parent::setUp();
$this->imceFM = $this
->getImceFM();
$this
->getTestFileUri();
$this->resize = new Resize([], 'resize', []);
$this
->setSelection();
}
public function test() {
$this
->assertEquals('test', 'test');
}
public function getRequest() {
$request = Request::create("/imce", 'POST', [
'jsop' => 'resize',
'token' => 'LLuA1R0aUOzoduSJkJxN5aoHVdJnQk8LbTBgdivOU4Y',
'active_path' => '.',
'selection' => [
'./ciandt.jpg',
],
'width' => '315',
'height' => '210',
'copy' => '0',
]);
$session = new Session();
$session
->set('imce_active_path', '.');
$request
->setSession($session);
return $request;
}
public function setSelection() {
$this->imceFM->selection[] = $this->imceFM
->createItem('file', "ciandt.jpg", [
'path' => '.',
]);
$this->imceFM->selection[0]->parent = new ImceFolder('.', $this
->getConf());
$this->imceFM->selection[0]->parent
->setFm($this->imceFM);
$this->imceFM->selection[0]->parent
->setPath('.');
}
public function getConf() {
return [
'permissions' => [
'all' => TRUE,
],
];
}
public function setParameterCopy($copy) {
$this->imceFM->request->request
->add([
'copy' => $copy,
]);
}
public function getPluginDefinations() {
return [
'weight' => 0,
'operations' => [
'resize' => 'opResize',
],
'id' => 'resize',
'label' => 'Resize',
'class' => 'Drupal\\imce\\Plugin\\ImcePlugin\\Resize',
'provider' => 'imce',
];
}
public function testPermissiomInfo() {
$permissionInfo = $this->resize
->permissionInfo();
$this
->assertTrue(is_array($permissionInfo));
$this
->assertTrue(in_array($this
->t('Resize images'), $permissionInfo));
}
public function testResizeImageWithCopy() {
$this
->setParameterCopy(1);
$this->resize
->opResize($this->imceFM);
list($width, $height) = getimagesize(PublicStream::basePath() . '/ciandt_0.jpg');
$this
->assertEqual($width, 315);
$this
->assertEqual($height, 210);
}
public function testResizeImageWithoutCopy() {
$this
->setParameterCopy(0);
$this->resize
->opResize($this->imceFM);
list($width, $height) = getimagesize(PublicStream::basePath() . '/ciandt.jpg');
$this
->assertEqual($width, 315);
$this
->assertEqual($height, 210);
}
public function testMessages() {
$messages = $this->imceFM
->getMessages();
$this
->assertTrue(is_array($messages));
$this
->assertEquals([], $messages);
}
public function testCore() {
$this
->assertInstanceOf(ImcePluginInterface::class, $this->resize);
}
public function testOperation() {
$this
->assertEquals($this->imceFM
->getOp(), 'resize');
}
}