mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00

Conflicts: composer.lock lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Command/Setup/H264MappingGenerator.php lib/Alchemy/Phrasea/Controller/AbstractDelivery.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Edit.php lib/Alchemy/Phrasea/Controller/Prod/Story.php lib/Alchemy/Phrasea/Controller/Prod/Upload.php lib/Alchemy/Phrasea/Controller/Report/Activity.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Account.php lib/Alchemy/Phrasea/Core/PhraseaEvents.php lib/Alchemy/Phrasea/Core/Version.php lib/classes/API/V1/adapter.php lib/classes/User/Adapter.php lib/classes/databox.php lib/classes/media/subdef.php lib/classes/module/report.php lib/classes/module/report/activity.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/module/report/nav.php lib/classes/module/report/question.php lib/classes/module/report/sqlaction.php lib/classes/module/report/sqlconnexion.php lib/classes/module/report/sqldownload.php lib/classes/module/report/sqlfilter.php lib/classes/task/abstract.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/prod/index.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php tests/classes/api/v1/api_v1_adapterTest.php tests/classes/report/activityTest.php tests/classes/report/editTest.php
186 lines
6.2 KiB
PHP
186 lines
6.2 KiB
PHP
<?php
|
|
|
|
class report_editTest extends \PhraseanetAuthenticatedTestCase
|
|
{
|
|
protected $ret;
|
|
protected $dmin;
|
|
protected $dmax;
|
|
protected $report;
|
|
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
$date = new Datetime();
|
|
$this->dmax = $date->format("Y-m-d H:i:s");
|
|
$date->modify('-6 month');
|
|
$this->dmin = $date->format("Y-m-d H:i:s");
|
|
$databoxes = self::$DI['app']['phraseanet.appbox']->get_databoxes();
|
|
$this->ret = [];
|
|
foreach ($databoxes as $databox) {
|
|
$colls = $databox->get_collections();
|
|
$rett = [];
|
|
foreach ($colls as $coll) {
|
|
$rett[$coll->get_coll_id()] = $coll->get_coll_id();
|
|
}
|
|
$this->ret[$databox->get_sbas_id()] = implode(',', $rett);
|
|
}
|
|
}
|
|
|
|
public function testBuildReport()
|
|
{
|
|
<<<<<<< HEAD
|
|
$conf = [
|
|
'user' => ["", 1, 0, 1, 1],
|
|
'date' => ["", 1, 0, 1, 1],
|
|
'record_id' => ["", 1, 1, 1, 1],
|
|
'file' => ["", 1, 0, 1, 1],
|
|
'mime' => ["", 1, 0, 1, 1],
|
|
'size' => ["", 1, 0, 1, 1]
|
|
];
|
|
=======
|
|
$conf = array(
|
|
'user' => array("", 1, 0, 1, 1),
|
|
'date' => array("", 1, 0, 1, 1),
|
|
'record_id' => array("", 1, 1, 1, 1),
|
|
'file' => array("", 1, 0, 1, 1),
|
|
'mime' => array("", 1, 0, 1, 1),
|
|
);
|
|
>>>>>>> 3.8
|
|
|
|
foreach ($this->ret as $sbasid => $collections) {
|
|
$this->report = new module_report_edit(
|
|
self::$DI['app'],
|
|
$this->dmin,
|
|
$this->dmax,
|
|
$sbasid,
|
|
$collections
|
|
);
|
|
|
|
$result = $this->report->buildReport($conf);
|
|
|
|
$this->reporttestPage($result);
|
|
if (count($result['result']) > 0)
|
|
$this->reporttestConf($conf);
|
|
if (count($result['result']) > 0)
|
|
$this->reporttestResult($result, $conf);
|
|
|
|
$this->ColFilter();
|
|
}
|
|
|
|
foreach ($this->ret as $sbasid => $collections) {
|
|
$this->report = new module_report_edit(
|
|
self::$DI['app'],
|
|
$this->dmin,
|
|
$this->dmax,
|
|
$sbasid,
|
|
$collections
|
|
);
|
|
|
|
$this->ColFilter();
|
|
|
|
$result = $this->report->buildReport(false, 'user');
|
|
$this->reporttestPage($result);
|
|
if (count($result['result']) > 0)
|
|
$this->reporttestConf($conf, 'user');
|
|
if (count($result['result']) > 0)
|
|
$this->reporttestResult($result, $conf, 'user');
|
|
}
|
|
}
|
|
|
|
public function ColFilter()
|
|
{
|
|
$ret = $this->report->colFilter('user');
|
|
$this->manyCol($ret);
|
|
$ret = $this->report->colFilter('getter');
|
|
$this->manyCol($ret);
|
|
$ret = $this->report->colFilter('date');
|
|
$this->manyCol($ret);
|
|
$ret = $this->report->colFilter('size');
|
|
$this->manyCol($ret);
|
|
}
|
|
|
|
public function manyCol($ret)
|
|
{
|
|
$this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $ret);
|
|
foreach ($ret as $result) {
|
|
$this->assertArrayHasKey('val', $result);
|
|
$this->assertArrayHasKey('value', $result);
|
|
}
|
|
}
|
|
|
|
public function reporttestPage($report)
|
|
{
|
|
$this->assertLessThanOrEqual($this->report->getNbRecord(), count($report['result']));
|
|
|
|
$nbPage = $this->report->getTotal() / $this->report->getNbRecord();
|
|
|
|
if ($this->report->getTotal() > $this->report->getNbRecord())
|
|
$this->assertTrue($report['display_nav']);
|
|
else
|
|
$this->assertFalse($report['display_nav']);
|
|
|
|
if ($report['page'] == 1)
|
|
$this->assertFalse($report['previous_page']);
|
|
else
|
|
$this->assertEquals($report['page'] - 1, $report['previous_page']);
|
|
|
|
if (intval(ceil($nbPage)) == $report['page'] || intval(ceil($nbPage)) == 0)
|
|
$this->assertFalse($report['next_page']);
|
|
else
|
|
$this->assertEquals($report['page'] + 1, $report['next_page']);
|
|
}
|
|
|
|
public function reporttestConf($conf, $groupby = false)
|
|
{
|
|
if ($groupby)
|
|
$this->assertEquals(count($this->report->getDisplay()), 2);
|
|
else
|
|
$this->assertEquals(count($this->report->getDisplay()), count($conf));
|
|
|
|
if (! $groupby) {
|
|
foreach ($this->report->getDisplay() as $col => $colconf) {
|
|
$this->assertArrayHaskey($col, $conf);
|
|
$this->assertTrue(is_array($colconf));
|
|
$this->assertArrayHasKey('title', $colconf);
|
|
$this->assertArrayHasKey('sort', $colconf);
|
|
$this->assertArrayHasKey('bound', $colconf);
|
|
$this->assertArrayHasKey('filter', $colconf);
|
|
$this->assertArrayHasKey('groupby', $colconf);
|
|
$i = 0;
|
|
foreach ($colconf as $key => $value) {
|
|
if ($i == 1)
|
|
$this->assertEquals($conf[$col][$i], $value);
|
|
elseif ($i == 2)
|
|
$this->assertEquals($conf[$col][$i], $value);
|
|
elseif ($i == 3)
|
|
$this->assertEquals($conf[$col][$i], $value);
|
|
elseif ($i == 4)
|
|
$this->assertEquals($conf[$col][$i], $value);
|
|
$i ++;
|
|
}
|
|
}
|
|
} else {
|
|
$this->assertArrayHasKey($groupby, $this->report->getDisplay());
|
|
$this->assertArrayHasKey('nombre', $this->report->getDisplay());
|
|
}
|
|
}
|
|
|
|
public function reporttestResult($report, $conf, $groupby = false)
|
|
{
|
|
if (! $groupby) {
|
|
foreach ($report['result'] as $row) {
|
|
foreach ($conf as $key => $value) {
|
|
$this->assertArrayHasKey($key, $row);
|
|
$condition = is_string($row[$key]) || is_int($row[$key]);
|
|
$this->assertTrue($condition);
|
|
}
|
|
}
|
|
} else {
|
|
foreach ($report['result'] as $row) {
|
|
$this->assertArrayHasKey($groupby, $row);
|
|
$this->assertArrayHasKey('nombre', $row);
|
|
}
|
|
}
|
|
}
|
|
}
|