diff --git a/VERSIONS_WIP/dev#18291_sitemap b/VERSIONS_WIP/dev#18291_sitemap new file mode 100644 index 0000000000000000000000000000000000000000..2c1e9b244c72428568ef5bc082b8c9a89aa80b8c --- /dev/null +++ b/VERSIONS_WIP/dev#18291_sitemap @@ -0,0 +1,6 @@ +- ticket: #18291: + - Profil: Les profils public (uniquement) peuvent être ajoutés au plan du site + Ajout d'une checkbox pour ajouter/enlever le profil du plan. + + - Batch: Ajout d'un nouveau batch: "Régénère le sitemap XML". + + - Sitemap: Le plan du site est visible via le chemin /sitemap.xml. \ No newline at end of file diff --git a/application/modules/admin/controllers/ProfilController.php b/application/modules/admin/controllers/ProfilController.php index 3b60396de63bee6d090f0380abceb8d7225dd8a4..54e0c9795605427eccc78e914645fc12a2de738d 100644 --- a/application/modules/admin/controllers/ProfilController.php +++ b/application/modules/admin/controllers/ProfilController.php @@ -311,6 +311,7 @@ class Admin_ProfilController extends ZendAfi_Controller_Action { $enreg = $this->_parseSaveContentString($cfg_module); $enreg["use_parent_css"] = $this->_getParam('use_parent_css', $profil->getUseParentCss()); + $enreg['sitemap'] = $this->_getParam('sitemap'); $enreg["page_css"]=$this->_getParam('page_css'); $profil->setRewriteUrl($this->_getParam('rewrite_url')); diff --git a/application/modules/admin/views/scripts/profil/accueil.phtml b/application/modules/admin/views/scripts/profil/accueil.phtml index df29dfc0c96b8acf91e1ff1d281986a85e8b6f4e..0bf31068521502f1457f34c7fe7c7814d7c06132 100644 --- a/application/modules/admin/views/scripts/profil/accueil.phtml +++ b/application/modules/admin/views/scripts/profil/accueil.phtml @@ -36,6 +36,17 @@ array('1', '0')) ?> </td> </tr> + <tr> + <td class="droite"> + <?php echo $this->_("Ajouter au plan du site"); ?> + </td> + <td class="gauche"> + <?php echo $this->formCheckbox('sitemap', + $this->profil->getCfgAccueilParam('sitemap'), + null, + array('1', '0')) ?> + </td> + </tr> <tr> <td class="droite"><?php echo $this->traduire('Page css:'); ?></td> <td class="gauche" style="padding-left:5px"> diff --git a/application/modules/opac/controllers/IndexController.php b/application/modules/opac/controllers/IndexController.php index c74fc8a767d4d0f4c278e6c82e322c505c36aec3..a56bbc4cbd41fffaf541a055d9db22db7df9e2c5 100644 --- a/application/modules/opac/controllers/IndexController.php +++ b/application/modules/opac/controllers/IndexController.php @@ -86,6 +86,19 @@ class IndexController extends Zend_Controller_Action { public function formulairecontactsentAction() {} + public function sitemapAction() { + if (!Class_Sitemap::sitemap_exists()) { + $this->_redirect('/index'); + return; + } + + $xml = Class_Sitemap::getSitemap(); + + $this->getHelper('ViewRenderer')->setNoRender(); + $this->_response->setHeader('Content-Type', 'text/xml; charset=utf-8', true); + $this->_response->setBody($xml); + } + protected function _sendFormulaireContact() { $mail_address = ($bib = Class_Bib::find($this->_getParam('bib_selector', 0))) diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 0393cf289fcdf3e8d08d91c92b6a2eb8e271d722..68e104fcfe3248f8f64fa3d462b18b02880b0ad0 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php // Constantes error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","226"); +define("PATCH_LEVEL","228"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_228.php b/cosmogramme/sql/patch/patch_228.php new file mode 100644 index 0000000000000000000000000000000000000000..f821461c778e35438eb7cebe5bb9b1857bf3e91b --- /dev/null +++ b/cosmogramme/sql/patch/patch_228.php @@ -0,0 +1,7 @@ +<?php + +$profiles = Class_Profil::findAll(); + +foreach ($profiles as $profile) { + $profile->setCfgAccueilParam('sitemap', 1)->save(); +} \ No newline at end of file diff --git a/includes.php b/includes.php index 4394d33ac6305a588d56f39882d5acec366859c5..1a94e05e5bf8edc65a3f54ef5ccb6dab6cf3db94 100644 --- a/includes.php +++ b/includes.php @@ -35,6 +35,13 @@ if(!file_exists("../" . end($parts))) { define("BASE_URL", "/" . $site) ; +function rootUrl() { + return (!$_SERVER['HTTPS'] || $_SERVER['HTTPS'] == 'off' ? 'http://' : 'https://') + . $_SERVER['SERVER_NAME'] + . ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'.$_SERVER['SERVER_PORT']); +} +define('ROOT_URL', rootUrl()); + include_once "fonctions/fonctions.php"; require_once "Zend/Loader.php"; require_once "library/startup.php"; diff --git a/library/Class/Batch.php b/library/Class/Batch.php index 864b4938d8e88ba266a5afb29790010d5c4b22ec..43729e2926a8c315bde4bf608ac7277c8a123ea9 100644 --- a/library/Class/Batch.php +++ b/library/Class/Batch.php @@ -29,7 +29,8 @@ class Class_BatchLoader extends Storm_Model_Loader{ 'COMMENT_REALLOCATION'=> new Class_Batch_AvisNotice(), 'INDEX_RESSOURCES_NUMERIQUES' => new Class_Batch_IndexRessourcesNumeriques(), 'AUTOCOMPLETE_RECORD_TITLE' => new Class_Batch_AutocompleteRecordTitle(), - 'AUTOCOMPLETE_RECORD_AUTHOR' => new Class_Batch_AutocompleteRecordAuthor() + 'AUTOCOMPLETE_RECORD_AUTHOR' => new Class_Batch_AutocompleteRecordAuthor(), + 'BUILD_SITE_MAP' => new Class_Batch_BuildSiteMap() ]); } diff --git a/library/Class/Batch/BuildSiteMap.php b/library/Class/Batch/BuildSiteMap.php new file mode 100644 index 0000000000000000000000000000000000000000..3f1558dfa8b888bcab7f64b8f20a5e0b2dd49be4 --- /dev/null +++ b/library/Class/Batch/BuildSiteMap.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Batch_BuildSiteMap extends Class_Batch_Abstract { + public function getLabel() { + return $this->_('Régénère le sitemap XML'); + } + + public function run() { + + $sitemap = new Class_Sitemap(); + $profiles = $this->sitemapProfiles(); + + if (empty($profiles)) { + Class_Sitemap::removeSitemap(); + return; + } + + foreach ($profiles as $profile) { + $sitemap->addUrl($profile['url'], $profile['priority']); + } + + $sitemap->save(); + } + + protected function sitemapProfiles() { + $profiles = Class_Profil::findAll(); + $sitemap_profiles = []; + foreach ($profiles as $profile) { + if (!$profile->isPublic()) + continue; + + if (0 == (int) $profile->getCfgAccueilParam('sitemap')) + continue; + + $url = ROOT_URL . BASE_URL . ($profile->getRewriteUrl() ? '/'.$profile->getRewriteUrl() : '?id_profil='.$profile->getId()); + + $priority = $profile->hasParentProfil() ? '0.5' : '0.8'; + $priority = $profile->getId() == 1 ? '1.0' : $priority; + $sitemap_profiles[$profile->getId()] = ['url' => $url, + 'priority' => $priority]; + } + return $sitemap_profiles; + } +} diff --git a/library/Class/Profil.php b/library/Class/Profil.php index 967955ec9da752bd4d6c4268ffe7a5c99a61c804..880b7ec61fddecff66e496642f622026dac71161 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -194,7 +194,8 @@ class Class_Profil extends Storm_Model_Abstract { ['cfg_site' => '', 'cfg_accueil' => ZendAfi_Filters_Serialize::serialize([ 'page_css' => null, 'use_parent_css' => true, - 'modules' => []]), + 'modules' => [], + 'sitemap' => 1]), 'cfg_menus' => ZendAfi_Filters_Serialize::serialize(['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', 'menus' => []], @@ -963,6 +964,18 @@ class Class_Profil extends Storm_Model_Abstract { } + /** + * @param string $param + * @param mixed $value + * @return Class_Profil + */ + public function setCfgAccueilParam($param, $value) { + $cfg_accueil = $this->getCfgAccueilAsArray(); + $cfg_accueil[$param] = $value; + return $this->setCfgAccueil(ZendAfi_Filters_Serialize::serialize($cfg_accueil)); + } + + /** * @param string $param * @return bool diff --git a/library/Class/Sitemap.php b/library/Class/Sitemap.php new file mode 100644 index 0000000000000000000000000000000000000000..8d6f452c05c1ba9e9145b881b149010ebf04c535 --- /dev/null +++ b/library/Class/Sitemap.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class Class_Sitemap { + use Trait_StaticFileSystem; + + protected $xml; + protected $urls; + + public static function sitemap_exists() { + return static::getFileSystem()->file_exists(static::getSitemapPath()); + } + + public static function getSitemap() { + return static::getFileSystem()->file_get_contents(static::getSitemapPath()); + } + + public static function removeSitemap() { + return static::getFileSystem()->unlink(static::getSitemapPath()); + } + + public static function getSitemapPath() { + return PATH_TEMP . 'sitemap.xml'; + } + + public function __construct() { + $this->xml = new DOMDocument('1.0', 'UTF-8'); + $this->xml->formatOutput = true; + $this->urls = []; + } + + public function addUrl($url, $priority) { + $this->urls[] = ['url' => $url, 'priority' => $priority]; + } + + public function save() { + $xmlns = $this->xml->createAttribute('xmlns'); + $xmlns->value = 'http://www.sitemaps.org/schemas/sitemap/0.9'; + + $urlset = $this->xml->createElement('urlset'); + $urlset->appendChild($xmlns); + + foreach ($this->urls as $u) { + $url = $this->xml->createElement('url'); + $loc = $this->xml->createElement('loc', $u['url']); + $priority = $this->xml->createElement('priority', $u['priority']); + $changefreq = $this->xml->createElement('changefreq', 'weekly'); + $url->appendChild($loc); + $url->appendChild($priority); + $url->appendChild($changefreq); + + $urlset->appendChild($url); + } + + $this->xml->appendChild($urlset); + + $handle = static::getFileSystem()->fopen(static::getSitemapPath(), 'w'); + static::getFileSystem()->fwrite($handle, $this->xml->saveXML()); + } +} diff --git a/library/Class/Testing/FileSystem.php b/library/Class/Testing/FileSystem.php index b36fbee3a46e5d47c0f2171a02eb1cf9454bb60c..40b87f0ac49350a9244aaa94f944165f8f473ae3 100644 --- a/library/Class/Testing/FileSystem.php +++ b/library/Class/Testing/FileSystem.php @@ -26,7 +26,7 @@ class Class_Testing_FileSystem { 'filesize', 'fclose', 'ftell', 'fread', 'feof', 'getcwd', 'file_exists', 'scandir', 'is_dir', 'opendir', 'readdir', 'closedir', 'mkdir','glob','file', 'fwrite','rename', - 'getimagesize' + 'getimagesize', 'file_get_contents' ]; diff --git a/library/startup.php b/library/startup.php index 36e759503aab8ec5c4740cb289640129afdbb7d1..80c714782e24ade4e14abe45bd9d5cccaed757d7 100644 --- a/library/startup.php +++ b/library/startup.php @@ -327,7 +327,13 @@ function setupRoutes($front_controller, $cfg) { 'flash/:action/*', array('module' => 'opacpriv', 'controller' => 'flash', - 'action' => 'index'))); + 'action' => 'index'))) + ->addRoute('sitemap', + new Zend_Controller_Router_Route_Static( + 'sitemap.xml', + array('module' => 'opac', + 'controller' => 'index', + 'action' => 'sitemap'))); return $front_controller; } diff --git a/tests/application/modules/admin/controllers/BatchControllerTest.php b/tests/application/modules/admin/controllers/BatchControllerTest.php index 5a8004b51057e2b583061577f35ea50ea22176bd..d30c1c065778acff98df45eddb90fa02f41f0718 100644 --- a/tests/application/modules/admin/controllers/BatchControllerTest.php +++ b/tests/application/modules/admin/controllers/BatchControllerTest.php @@ -128,6 +128,12 @@ class BatchControllerAddTest extends BatchControllerTestCase { public function selectElementShouldContainsIndexAutocompleteRecordAuthor(){ $this->assertXPath('//select[@name="type"]/option[@value="AUTOCOMPLETE_RECORD_AUTHOR"][@label="Indexer les auteurs de notice pour l\'autocompletion"][not(@selected)]',$this->_response->getBody()); } + + + /** @test */ + public function selectElementShouldContainsRegenereLeSiteMapXML(){ + $this->assertXPath('//select[@name="type"]/option[@value="BUILD_SITE_MAP"][@label="Régénère le sitemap XML"][not(@selected)]',$this->_response->getBody()); + } } diff --git a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php index 42e4733aa2c1600992183900d344e366f5f0cb21..51a1d8fcaf97da0404e7b11171fce4f2fdca4bb7 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php @@ -29,6 +29,7 @@ abstract class Admin_ProfilControllerPageAccueilJeunesseTestCase extends Admin_A $cfg_accueil = [ 'page_css' => '', 'use_parent_css' => 1, + 'sitemap' => 1, 'modules' => ['1' => ['division' => 4, 'type_module' => 'RECH_SIMPLE', 'preferences' => []], @@ -213,7 +214,13 @@ class Admin_ProfilControllerPageAccueilJeunesseTest extends Admin_ProfilControll /** @test **/ public function useParentCssCheckboxShouldBeChecked() { - $this->assertXPath('//input[@name="use_parent_css"][contains(@value,1)]'); + $this->assertXPath('//input[@name="use_parent_css"][@checked="checked"]'); + } + + + /** @test **/ + public function sitemapCheckboxShouldBeChecked() { + $this->assertXPath('//input[@name="sitemap"][@checked="checked"]'); } @@ -222,6 +229,29 @@ class Admin_ProfilControllerPageAccueilJeunesseTest extends Admin_ProfilControll $this->assertXPath('//input[@name="page_css"][contains(@value,"")]',$this->_response->getBody()); } + /** @test */ + public function postingDataWithSitemapModification() { + $this + ->getRequest() + ->setMethod('POST') + ->setPost(array('sitemap' => 0)); + $this->dispatch('/admin/profil/accueil/id_profil/7'); + + $this->assertTrue($this->profil_wrapper->methodHasBeenCalled('save')); + $this->assertRedirect('/admin/profil/accueil/id_profil/7'); + + return $this->profil_jeunesse; + } + + /** + * @depends postingDataWithSitemapModification + * @test + */ + public function shouldEnabledSitemap($profil_jeunesse) { + $sitemap = $profil_jeunesse->getCfgAccueilParam('sitemap'); + $this->assertEquals(0, $sitemap); + } + /** @test */ public function postingDataWithNoModifications() { @@ -743,6 +773,7 @@ abstract class Admin_ProfilControllerPageAccueilNoBoitePanierTestCase extends Ad $cfg_accueil = ['page_css' => '', 'use_parent_css' => 1, + 'sitemap' => 1, 'modules' => ['1' => ['division' => 4, 'type_module' => 'RECH_SIMPLE', 'preferences' => []], diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php index 92616bd2638b0037762c9a281c8a443133a24f1c..9f90a1fe56347097a9f35b7348128dd94f59196e 100644 --- a/tests/application/modules/opac/controllers/IndexControllerTest.php +++ b/tests/application/modules/opac/controllers/IndexControllerTest.php @@ -178,4 +178,58 @@ class IndexControllerAsPhoneWithNoPhoneProfilTest extends AbstractControllerTest } } + + +class IndexControllerSitemapTest extends AbstractControllerTestCase { + protected $_file_system; + protected $_sitemap; + + public function setUp() { + parent::setUp(); + + $this->_sitemap = '<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> + <url> + <loc>'.BASE_URL.'?id_profil=1</loc> + <priority>1.0</priority> + </url> + <url> + <loc>'.BASE_URL.'?id_profil=2</loc> + <priority>0.5</priority> + </url> +</urlset> +'; + + $this->_file_system = $this->mock() + ->whenCalled('file_exists')->answers(true) + ->whenCalled('file_get_contents')->answers($this->_sitemap); + Class_Sitemap::setFileSystem($this->_file_system); + + $this->dispatch('/sitemap.xml', true); + } + + + /** @test */ + public function contentShouldBeXml() { + $this->assertHeaderContains('Content-Type', 'text/xml; charset=utf-8'); + } + + + /** @test */ + public function withNoSitemapShouldRedirectToIndex() { + $this->_file_system = $this->mock() + ->whenCalled('file_exists')->answers(false); + Class_Sitemap::setFileSystem($this->_file_system); + $this->dispatch('/sitemap.xml', true); + + $this->assertRedirectTo('/index'); + } + + /** @test */ + public function contentShouldBeAsExpected() { + $this->assertEquals($this->_response->getBody(), $this->_sitemap); + } + +} + ?> \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index fe6b9427f662c64aa5b7a249d920e454daaac460..3c0d2efbce70b23edbe35f5b77b13775ba9123f8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -50,6 +50,7 @@ $parts = explode(DIRECTORY_SEPARATOR, $path); $parts = array_reverse($parts); defineConstant("BASE_URL", "/" . $parts[1]); +defineConstant('ROOT_URL', 'http://localhost'); defineConstant("URL_IMG", BASE_URL . "/public/opac/skins/original/images/"); defineConstant("URL_SHARED_IMG", BASE_URL . "/public/opac/images"); diff --git a/tests/library/Class/BatchTest.php b/tests/library/Class/BatchTest.php index d49a372259bd9ff995fd644cfcd85e73cbf1e143..0fb348a3652c68f897c0c86a503fda324926b6c7 100644 --- a/tests/library/Class/BatchTest.php +++ b/tests/library/Class/BatchTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -28,13 +28,13 @@ class BatchModelTest extends Storm_Test_ModelTestCase { 'type' => 'MOISSONNAGE_VODECLIC', 'last_run' => '2012-05-01 10:23:00']); - $this->batch_artevod = $this->fixture('Class_Batch', - ['id' => 3, + $this->batch_artevod = $this->fixture('Class_Batch', + ['id' => 3, 'type' => 'MOISSONNAGE_ARTEVOD', 'last_run' => '2012-05-01 10:23:00']); - $this->batch_IndexRessourcesNumeriques = $this->fixture('Class_Batch', - ['id' => 3, + $this->batch_IndexRessourcesNumeriques = $this->fixture('Class_Batch', + ['id' => 3, 'type' => 'INDEX_RESSOURCES_NUMERIQUES', 'last_run' => '2014-04-02 17:11:00']); } @@ -89,7 +89,7 @@ class BatchLoaderWithoutRessourcesNumeriquesTest extends Storm_Test_ModelTestCas public function availableTypeShouldNotContainRessourcesNumeriques(){ $types = Class_Batch::getAvailableType(); foreach(array_keys($types) as $type) { - if (0 === strpos($type, 'MOISSONNAGE_')) + if (0 === strpos($type, 'MOISSONNAGE_')) $this->fail(); } } @@ -102,7 +102,7 @@ class BatchLoaderWithRessourcesNumeriquesTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); - + Class_Batch::beVolatile(); Class_AdminVar::beVolatile(); RessourcesNumeriquesFixtures::activate(); @@ -140,4 +140,70 @@ class BatchIndexRessourcesNumeriquesTest extends Storm_Test_ModelTestCase { $this->assertTrue($this->cache->methodHasBeenCalled('clean')); } } + + + +class BatchBuildSitemapTest extends Storm_Test_ModelTestCase { + protected $_file_system; + protected $_profiles; + + public function setUp() { + $this->_profiles[1] = $this->fixture('Class_Profil', ['id' => 1, + 'libelle' => 'Portail', + 'cfg_accueil' => ZendAfi_Filters_Serialize::serialize(['sitemap' => 1])]); + $this->_profiles[2] = $this->fixture('Class_Profil', ['id' => 2, + 'libelle' => 'Médiathèque foo', + 'cfg_accueil' => ZendAfi_Filters_Serialize::serialize(['sitemap' => 1])]); + $this->_profiles[3] = $this->fixture('Class_Profil', ['id' => 3, + 'libelle' => 'Services', + 'parent_id' => '2', + 'cfg_accueil' => ZendAfi_Filters_Serialize::serialize(['sitemap' => 0])]); + Class_Profil::beVolatile(); + + $this->handle = new stdClass; + $this->_file_system = $this->mock() + ->whenCalled('fopen')->with(ROOT_PATH.'temp/sitemap.xml', 'w')->answers($this->handle) + ->whenCalled('fwrite')->answers(null) + ->whenCalled('unlink')->answers(null); + + Class_Sitemap::setFileSystem($this->_file_system); + + } + + + /** @test */ + public function sitemapShouldBeHasExpected() { + (new Class_Batch_BuildSiteMap())->run(); + $expected = '<?xml version="1.0" encoding="UTF-8"?> +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> + <url> + <loc>' . ROOT_URL . BASE_URL . '?id_profil=1</loc> + <priority>1.0</priority> + <changefreq>weekly</changefreq> + </url> + <url> + <loc>' . ROOT_URL . BASE_URL . '?id_profil=2</loc> + <priority>0.8</priority> + <changefreq>weekly</changefreq> + </url> +</urlset> +'; + + $this->assertTrue($this->_file_system + ->methodHasBeenCalledWithParams('fwrite', + [$this->handle, $expected])); + } + + /** @test */ + public function sitemapFileShouldBeRemoved() { + $this->_profiles[1]->setCfgAccueilParam('sitemap', 0); + $this->_profiles[2]->setCfgAccueilParam('sitemap', 0); + (new Class_Batch_BuildSiteMap())->run(); + $this->assertTrue($this->_file_system + ->methodHasBeenCalledWithParams('unlink', + [PATH_TEMP .'sitemap.xml'])); + } + +} + ?> diff --git a/tests/library/Class/ProfilTest.php b/tests/library/Class/ProfilTest.php index 23f8a0811e3c1a8a635cf31d8801b472660a7d42..bbcd9b6c72e3dba6557fb4fbdbf39f18403c465a 100644 --- a/tests/library/Class/ProfilTest.php +++ b/tests/library/Class/ProfilTest.php @@ -30,7 +30,8 @@ class ProfilVideTest extends ModelTestCase { public function cfgAccueilShouldReturnArrayWithModules() { $this->assertEquals(['page_css' => null, 'use_parent_css' => true, - 'modules' => []], + 'modules' => [], + 'sitemap' => 1], $this->profil_vide->getCfgAccueilAsArray()); } diff --git a/tests/library/Class/Testing/FileSystemTest.php b/tests/library/Class/Testing/FileSystemTest.php index b5f28db7f361cb1476bba53b42efe62aaa8fa3c5..a60586f05c177387d87daa591a9d1ebcad333b08 100644 --- a/tests/library/Class/Testing/FileSystemTest.php +++ b/tests/library/Class/Testing/FileSystemTest.php @@ -93,6 +93,11 @@ class Class_Testing_FileSystemTest extends PHPUnit_Framework_TestCase { $this->shouldSupport('feof'); } + /** @test */ + public function shouldSupportFileGetContents() { + $this->shouldSupport('file_get_contents'); + } + protected function shouldSupport($method) { try {