mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00

Conflicts: lib/Alchemy/Phrasea/Controller/Admin/Publications.php lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php lib/Alchemy/Phrasea/Controller/Api/V1.php lib/Alchemy/Phrasea/Controller/Lightbox.php lib/Alchemy/Phrasea/Controller/Permalink.php lib/Alchemy/Phrasea/Controller/Prod/Feed.php lib/Alchemy/Phrasea/Controller/Prod/Order.php lib/Alchemy/Phrasea/Controller/Prod/Push.php lib/Alchemy/Phrasea/Controller/Prod/Share.php lib/Alchemy/Phrasea/Controller/Root/Login.php lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php lib/Alchemy/Phrasea/Controller/Root/Session.php lib/Alchemy/Phrasea/Controller/Setup.php lib/Alchemy/Phrasea/Core/CLIProvider/LessBuilderServiceProvider.php lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php lib/classes/Feed/Entry/Item.php lib/classes/record/adapter.php lib/classes/task/Scheduler.php lib/classes/task/manager.php lib/classes/task/period/RecordMover.php lib/classes/task/period/archive.php lib/classes/task/period/cindexer.php lib/classes/task/period/ftp.php lib/classes/task/period/ftpPull.php lib/classes/task/period/subdef.php lib/classes/task/period/writemeta.php tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php tests/classes/Feed/Entry/Feed_Entry_ItemTest.php tests/classes/PhraseanetPHPUnitAbstract.php
182 lines
6.6 KiB
PHP
182 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\Controller\Prod;
|
|
|
|
/**
|
|
* @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail
|
|
*/
|
|
class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
|
|
{
|
|
protected $client;
|
|
protected static $GV_activeFTP;
|
|
|
|
public function tearDown()
|
|
{
|
|
if (self::$GV_activeFTP) {
|
|
self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', true, \registry::TYPE_BOOLEAN);
|
|
}
|
|
|
|
self::$GV_activeFTP = null;
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::displayMultiExport
|
|
*/
|
|
public function testDisplayMultiExport()
|
|
{
|
|
self::$DI['client']->request('POST', '/prod/export/multi-export/', array('lst' => self::$DI['record_1']->get_serialize_key()));
|
|
$response = self::$DI['client']->getResponse();
|
|
$this->assertTrue($response->isOk());
|
|
unset($response);
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion
|
|
*/
|
|
public function testTestFtpConnexion()
|
|
{
|
|
$framework = $this;
|
|
self::$DI['app']['phraseanet.ftp.client'] = self::$DI['app']->protect(function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) use ($framework) {
|
|
return $framework->getMockBuilder('\ftpclient')
|
|
->setMethods(array('login', 'close'))
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
});
|
|
|
|
$this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
|
|
$response = self::$DI['client']->getResponse();
|
|
$datas = (array) json_decode($response->getContent());
|
|
$this->assertArrayHasKey('success', $datas);
|
|
$this->assertTrue($datas['success']);
|
|
$this->assertArrayHasKey('message', $datas);
|
|
unset($response, $datas);
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::testFtpConnexion
|
|
*/
|
|
public function testFtpConnexionNoXMLHTTPRequests()
|
|
{
|
|
$framework = $this;
|
|
self::$DI['app']['phraseanet.ftp.client'] = self::$DI['app']->protect(function ($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) use ($framework) {
|
|
$ftpStub = $framework->getMockBuilder('\ftpclient')
|
|
->setMethods(array('login', 'close'))
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
|
|
$ftpStub->expects($framework->once())
|
|
->method('login')
|
|
->will($framework->throwException(new \Exception()));
|
|
|
|
return $ftpStub;
|
|
});
|
|
|
|
self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
|
|
$response = self::$DI['client']->getResponse();
|
|
$datas = (array) json_decode($response->getContent());
|
|
|
|
$this->assertBadResponse(self::$DI['client']->getResponse());
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
|
|
*/
|
|
public function testExportFtpNoDocs()
|
|
{
|
|
self::$DI['client']->request('POST', '/prod/export/ftp/', array(
|
|
'address' => 'test.ftp',
|
|
'login' => 'login',
|
|
'dest_folder' => 'documents',
|
|
'prefix_folder' => 'documents',
|
|
'obj' => array('preview')
|
|
));
|
|
$response = self::$DI['client']->getResponse();
|
|
$this->assertTrue($response->isOk());
|
|
$datas = (array) json_decode($response->getContent());
|
|
$this->assertArrayHasKey('success', $datas);
|
|
$this->assertArrayHasKey('message', $datas);
|
|
$this->assertFalse($datas['success']);
|
|
unset($response, $datas);
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
|
|
* @dataProvider getMissingArguments
|
|
*/
|
|
public function testExportFtpBadRequest($params)
|
|
{
|
|
self::$DI['client']->request('POST', '/prod/export/ftp/', $params);
|
|
|
|
$this->assertBadResponse(self::$DI['client']->getResponse());
|
|
}
|
|
|
|
public function getMissingArguments()
|
|
{
|
|
return array(
|
|
array(array()),
|
|
array(array('address' => '')),
|
|
array(array('address' => '', 'login' => '')),
|
|
array(array('address' => '', 'login' => '', 'dest_folder' => '')),
|
|
array(array('address' => '', 'login' => '', 'dest_folder' => '', 'prefix_folder' => '')),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
|
|
*/
|
|
public function testExportFtp()
|
|
{
|
|
if (!self::$DI['app']['phraseanet.registry']->get('GV_activeFTP')) {
|
|
self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', true, \registry::TYPE_BOOLEAN);
|
|
self::$GV_activeFTP = true;
|
|
}
|
|
//inserted rows from this function are deleted in tearDownAfterClass
|
|
self::$DI['client']->request('POST', '/prod/export/ftp/', array(
|
|
'lst' => self::$DI['record_1']->get_serialize_key(),
|
|
'user_dest' => self::$DI['user']->get_id(),
|
|
'address' => 'local.phrasea.test',
|
|
'login' => self::$DI['user']->get_email(),
|
|
'dest_folder' => '/home/test/',
|
|
'prefix_folder' => 'test2/',
|
|
'obj' => array('preview')
|
|
));
|
|
|
|
$response = self::$DI['client']->getResponse();
|
|
$this->assertTrue($response->isOk());
|
|
$datas = (array) json_decode($response->getContent());
|
|
$this->assertArrayHasKey('success', $datas);
|
|
$this->assertArrayHasKey('message', $datas);
|
|
$this->assertTrue($datas['success']);
|
|
unset($response, $datas);
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportMail
|
|
*/
|
|
public function testExportMail()
|
|
{
|
|
$this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailRecordsExport');
|
|
|
|
self::$DI['client']->request('POST', '/prod/export/mail/', array(
|
|
'lst' => self::$DI['record_1']->get_serialize_key(),
|
|
'destmail' => 'user@example.com',
|
|
'obj' => array('preview'),
|
|
));
|
|
|
|
$response = self::$DI['client']->getResponse();
|
|
$this->assertTrue($response->isOk());
|
|
}
|
|
|
|
/**
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::connect
|
|
* @covers Alchemy\Phrasea\Controller\Prod\Export::call
|
|
*/
|
|
public function testRequireAuthentication()
|
|
{
|
|
$this->logout(self::$DI['app']);
|
|
self::$DI['client']->request('POST', '/prod/export/multi-export/');
|
|
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
|
}
|
|
}
|