Skip to content
Snippets Groups Projects
Commit 3a2df9e2 authored by Patrick Barroca's avatar Patrick Barroca
Browse files

rel RF #12805 : StatController coverage

parent a413971e
Branches
Tags
2 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!32Ft/Rf12808
......@@ -48,6 +48,7 @@ class Admin_StatController extends Zend_Controller_Action {
public function palmaresvisunoticeAction() {
$this->view->titre = 'Palmarès des visualisations de notices';
$this->view->table_stat = $this->cls_stat->getPalmaresVisu($this->_getParam('type_doc'));
$this->view->type_doc = $this->_getParam('type_doc');
}
......
<table>
<tr>
<td style="text-align:right">Type de document : </td>
<td style="text-align:left" width="70%"><?php echo $this->ComboCodification('type_doc', $_REQUEST["type_doc"],'onchange="window.location.replace(\''.BASE_URL.'/admin/stat/palmaresvisunotice?type_doc=\' + this.value);"'); ?></td>
<td style="text-align:left" width="70%">
<?php
echo $this->ComboCodification('type_doc',
$this->type_doc,
'onchange="window.location.replace(\''.BASE_URL.'/admin/stat/palmaresvisunotice?type_doc=\' + this.value);"'); ?>
</td>
</tr>
</table>
......@@ -15,15 +20,12 @@
<th class="stat" width="9%">Vue</th>
</tr>
<?php
$rang=0;
$last_nombre=0;
if($this->table_stat)
{
foreach($this->table_stat as $notice)
{
$rang = 0;
$last_nombre = 0;
if($this->table_stat) {
foreach($this->table_stat as $notice) {
// Calcul n° de rang
if($notice["nombre"] != $last_nombre)
{
if($notice["nombre"] != $last_nombre) {
$last_nombre=$notice["nombre"];
$rang++;
}
......
<?PHP
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
......@@ -60,14 +60,13 @@ class Class_StatsNotices {
if ($annee)
$msg .= ' ' . $annee;
if ($msg) {
$msg = 'en ' . $msg;
} else {
if ($annee = fetchOne('select min(annee) from stats_notices'))
$mois = fetchOne('select min(mois) from stats_notices where annee=' . $annee);
$msg = 'depuis ' . $this->lib_mois[$mois] . ' ' . $annee;
}
return $msg;
if ($msg)
return 'en ' . $msg;
if ($annee = fetchOne('select min(annee) from stats_notices'))
$mois = fetchOne('select min(mois) from stats_notices where annee=' . $annee);
return 'depuis ' . $this->lib_mois[$mois] . ' ' . $annee;
}
......@@ -95,22 +94,17 @@ class Class_StatsNotices {
public function getPalmaresVisu($type_doc) {
if ($type_doc)
$where = ' and type_doc=' . $type_doc;
// Lancer la requete
$req = "select id_notice,nb_visu from notices Where nb_visu > 0".$where." order by 2 desc LIMIT 0,50";
$liste = fetchAll($req);
foreach($liste as $item) {
$id_notice = $item["id_notice"];
$nombre = $item["nb_visu"];
$notice = ($model = Class_Notice::find($id_notice))
? $model->getNotice('JA') : [];
$lig["id_notice"] = $id_notice;
$lig["nombre"] = $nombre;
$lig["type_doc"] = $notice["type_doc"];
$lig["titre"] = $notice["J"];
$lig["auteur"] = $notice["A"];
$liste = Class_Notice::findAllBy(['where' => 'nb_visu > 0 ' . (($type_doc) ? ' and type_doc=' . $type_doc : ''),
'order' => 'nb_visu desc',
'limit' => 50]);
$ret = [];
foreach($liste as $model) {
$notice = $model->getNotice('JA');
$lig['id_notice'] = $model->getId();
$lig['nombre'] = $model->getNbVisu();
$lig['type_doc'] = $notice['type_doc'];
$lig['titre'] = $notice['J'];
$lig['auteur'] = $notice['A'];
$ret[] = $lig;
}
return $ret;
......@@ -179,14 +173,19 @@ class Class_StatsNotices {
protected function _isBlackListed() {
$robots = explode(';', getVar('BLACK_LIST_ROBOT'));
$client = null;
if (array_isset('REMOTE_HOST', $_SERVER))
$client = $_SERVER['REMOTE_HOST'];
if (!$client and array_isset('REMOTE_ADDR', $_SERVER))
$client = str_replace('-', '.', $_SERVER['REMOTE_ADDR']);
if (!$client) return true;
if (!$client)
return true;
foreach($robots as $robot)
if (trim($robot) and striPos($client, $robot) !== false) return true;
if (trim($robot) and striPos($client, $robot) !== false)
return true;
return false;
}
}
......
......@@ -118,4 +118,44 @@ class Admin_StatControllerVisunoticeTest extends Admin_AbstractControllerTestCas
}
}
class Admin_StatControllerPalmaresVisunoticeTest extends Admin_AbstractControllerTestCase{
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_TypeDoc')
->whenCalled('findUsedTypeDocIds')
->answers([]);
$this->fixture('Class_Notice', ['id' => 1,
'nb_visu' => 600,
'titre_principal' => 'Captain Harlock']);
$this->dispatch('/admin/stat/palmaresvisunotice', true);
}
/** @test */
public function titleShouldBePalmares() {
$this->assertXPathContentContains('//h1', 'Palmarès des visualisations de notices');
}
/** @test */
public function docTypeSelectorShouldBePresent() {
$this->assertXPath('//select[@id="select_type_doc"]');
}
/** @test */
public function harlockShouldBeInPalmares() {
$this->assertXPathContentContains('//td', 'Captain Harlock');
}
/** @test */
public function harlockShouldHaveBeenViewed600Times() {
$this->assertXPathContentContains('//td', '600', $this->_response->getBody());
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment