Skip to content
Snippets Groups Projects
Commit 7fe5ae9a authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #33614 : add error message when url is not valid

parent f35957bf
Branches
Tags
7 merge requests!1553Master,!1502Master,!1501Stable,!1324Master,!1323Hotline master,!1308Hotline#33614 sitotheque site non sauvegarde a l ajout si l url n est pas valide,!1307Hotline#33614 sitotheque site non sauvegarde a l ajout si l url n est pas valide
- ticket #33614 : Gestion sitothèque: Ajout d'un messages d'erreur si l'url n'est pas valide
\ No newline at end of file
......@@ -229,17 +229,19 @@ class Class_Sitotheque extends Storm_Model_Abstract {
public function validate() {
$this->checkAttribute('titre',
$this->getTitre() && mb_strlen($this->getTitre(),'UTF-8') <= 255,
$this->_('Le champ "Titre" doit être renseigné et inférieur à 255 caractères'));
$this->checkAttribute('titre', $this->getTitre() && mb_strlen($this->getTitre(),'UTF-8') <= 255,
$this->_("Le champ 'Titre' doit être renseigné et inférieur à 255 caractères"));
$this->checkAttribute('url',
$this->getUrl() && mb_strlen($this->getUrl(),'UTF-8') <= 250,
$this->_('Vous devez compléter le champ "Url" et il doit être inférieur à 250 caractères'));
$this->checkAttribute('url',$this->getUrl() && mb_strlen($this->getUrl(),'UTF-8') <= 250,
$this->_("Vous devez compléter le champ 'Url' et il doit être inférieur à 250 caractères"));
$url_validator = new ZendAfi_Validate_Url();
if (!$url_validator->isValid($this->getUrl())) {
$messages = $url_validator->getMessages();
foreach($messages as $message)
$this->addError($message);
$this->addAttributeError('url', $message);
}
}
......
......@@ -26,8 +26,10 @@ class ZendAfi_Validate_Url extends Zend_Validate_Abstract {
public function isValid($value) {
if ('' === $valueString = (string) $value)
return true;
if (false == strpos($valueString,'://'))
$valueString='http:/'.$valueString;
$valueString = 'http://' . $valueString;
$this->_setValue($value);
if (!Zend_Uri::check($valueString)) {
......
......@@ -21,34 +21,33 @@
require_once 'AdminAbstractControllerTestCase.php';
abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
protected $_le_monde;
public function setUp() {
parent::setUp();
$this->setupCustomFields();
$this->setupDomaines();
Class_Exemplaire::beVolatile();
Class_Notice::beVolatile();
Class_CodifThesaurus::beVolatile();
Storm_Model_Loader::defaultToVolatile();
$categorie_informations = $this->fixture('Class_SitothequeCategorie',
['id' => 2,
'libelle' => 'Informations',
'id_site' => 3,
'sous_categories' => [],
'sitotheques' => [
$this->fixture('Class_Sitotheque',
['id' => 22,
'titre' => 'Le Canard',
'url' => 'http://www.canard.fr',
'description' => 'indépendant',
'domaine_ids' => [10]]),
$this->_le_monde = $this->fixture('Class_Sitotheque',
['id' => 23,
'titre' => 'Le Monde',
'url' => 'http://www.monde.fr'])]
]);
$categorie_informations = $this
->fixture('Class_SitothequeCategorie',
['id' => 2,
'libelle' => 'Informations',
'id_site' => 3,
'sous_categories' => [],
'sitotheques' => [
$this->fixture('Class_Sitotheque',
['id' => 22,
'titre' => 'Le Canard',
'url' => 'http://www.canard.fr',
'description' => 'indépendant',
'domaine_ids' => [10]]),
$this->_le_monde = $this->fixture('Class_Sitotheque',
['id' => 23,
'titre' => 'Le Monde',
'url' => 'http://www.monde.fr'])]
]);
$bib_annecy = $this->fixture('Class_Bib',
......@@ -61,7 +60,6 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest
public function setupCustomFields() {
Class_CustomField_Meta::beVolatile();
$theme = $this->fixture('Class_CustomField',
['id' => 2,
'priority' => 3,
......@@ -71,17 +69,9 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest
'model' => 'Sitotheque']);
$theme->getMeta()->setIndexable(true)->save();
}
public function tearDown() {
Storm_Model_Loader::defaultToDb();
parent::tearDown();
}
public function setupDomaines() {
$this->fixture('Class_Catalogue', ['id' => 10,
'libelle' => 'Histoire',
......@@ -215,7 +205,6 @@ class SitothequeControllerSitoEditTest extends SitothequeControllerTestCase {
public function customFieldShouldBeDisplayed() {
$this->assertXPathContentContains('//select[@id="field_2"]//option', 'web links', $this->_response->getBody());
}
}
......@@ -279,12 +268,10 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase
public function setUp() {
parent::setUp();
$this->cache = Storm_Test_ObjectWrapper::mock()
->whenCalled('save')
->answers(true)
$this->cache = $this->mock()
->whenCalled('save')->answers(true)
->whenCalled('clean')->answers(true);
->whenCalled('clean')
->answers(true);
Storm_Cache::setDefaultZendCache($this->cache);
$this->postDispatch('/admin/sito/add/id_cat/2',
......@@ -334,6 +321,7 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase
$this->assertContains('HCFCF0001', Class_Notice::find(1)->getFacettes());
}
/** @test */
public function cacheShouldHaveBeenCleaned() {
$this->assertTrue($this->cache->methodHasBeenCalled('clean'));
......@@ -362,6 +350,7 @@ class SitothequeControllerNotIndexedPostAddActionTest extends SitothequeControll
true);
}
/** @test */
public function siteShouldNotBeIndexed() {
$this->assertNull(Class_Sitotheque::findFirstBy(['order'=>'titre desc'])->getNotice());
......@@ -372,14 +361,30 @@ class SitothequeControllerNotIndexedPostAddActionTest extends SitothequeControll
class SitothequeControllerInvalidPostActionTest extends SitothequeControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/add/id_cat/2', [], true);
protected function _assertError($message) {
$this->assertXPathContentContains('//ul[@class="errors"]/li', $message,
$this->_response->getBody());
}
/** @test */
public function titleShouldBeRequired() {
$this->postDispatch('/admin/sito/add/id_cat/2', []);
$this->_assertError('Le champ "Titre" doit être renseigné et inférieur à 255 caractères');
}
/** @test */
public function urlShouldBeRequired() {
$this->postDispatch('/admin/sito/add/id_cat/2', []);
$this->_assertError('Vous devez compléter le champ "Url"');
}
/** @test */
public function pageShouldContainsErrorValeurRequise() {
$this->assertXPathContentContains('//ul[@class="errors"]/li', "Le champ 'Titre' doit être renseigné et inférieur à 255 caractères",$this->_response->getBody());
public function urlShouldBeValid() {
$this->postDispatch('/admin/sito/add/id_cat/2', ['url' => 'http://|']);
$this->_assertError('n\'est pas une URL valide');
}
}
......@@ -389,9 +394,8 @@ class SitothequeControllerInvalidPostActionTest extends SitothequeControllerTest
class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/edit/id/23',
['titre' => 'Times'],
true);
$this->postDispatch('/admin/sito/edit/id/23', ['titre' => 'Times']);
Class_Sitotheque::clearCache();
$this->_le_monde = Class_Sitotheque::find(23);
}
......@@ -407,8 +411,6 @@ class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTe
public function anwersShouldRedirectToSitoEdit23() {
$this->assertRedirectTo('/admin/sito/edit/id/23');
}
}
......@@ -439,8 +441,7 @@ class SitothequeControllerSitoDeleteLeMondeTest extends SitothequeControllerTest
class SitothequeControllerActionErrorsTest extends SitothequeControllerTestCase {
public function errorUrls() {
return [['/admin/sito/catdel/id_cat/-1'],
['/admin/sito/catedit/id_cat/-1']
];
['/admin/sito/catedit/id_cat/-1']];
}
......@@ -482,9 +483,9 @@ class SitothequeControllerEditCategorieInformationsTest extends SitothequeContro
class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/catedit/id/2',
['libelle' => 'News'],
true);
['libelle' => 'News']);
Class_SitothequeCategorie::clearCache();
}
......@@ -513,7 +514,8 @@ class SitothequeControllerAddCategorieTest extends SitothequeControllerTestCase
/** @test */
public function selectIdCatMereShouldHaveCategorieInformationsSelected() {
$this->assertXPathContentContains('//select/optgroup[@label="Annecy"]/option[@value="2"][@selected="selected"]', 'Informations',
$this->assertXPathContentContains('//select/optgroup[@label="Annecy"]/option[@value="2"][@selected="selected"]',
'Informations',
$this->_response->getBody());
}
}
......@@ -524,15 +526,14 @@ class SitothequeControllerAddCategorieTest extends SitothequeControllerTestCase
class SitothequeControllerPostAddEmptyCategorieTest extends SitothequeControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/catadd/id/2',
['libelle' => ''],
true);
$this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => '']);
}
/** @test */
public function pageShouldDisplayErrorNomVide() {
$this->assertXPathContentContains('//span[@class="error"]', 'Vous devez compléter le champ');
$this->assertXPathContentContains('//span[@class="error"]',
'Vous devez compléter le champ');
}
}
......@@ -545,10 +546,7 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/catadd/id/2',
['libelle' => 'Nationales'],
true);
$this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => 'Nationales']);
$this->_new_cat = Class_SitothequeCategorie::find(3);
}
......@@ -568,10 +566,7 @@ class SitothequeControllerPostAddCategorieInBibTest extends SitothequeController
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/sito/catadd/id_bib/5',
['libelle' => 'Dans la bib'],
true);
$this->postDispatch('/admin/sito/catadd/id_bib/5', ['libelle' => 'Dans la bib']);
$this->_new_cat = Class_SitothequeCategorie::find(3);
}
......@@ -615,6 +610,7 @@ protected
public function setUp() {
parent::setUp();
Class_WebService_SimpleWebClient::setInstance($this->mock()
->whenCalled('open_url')
->answers($this->_getContent()));
......@@ -739,7 +735,6 @@ class SitothequeControllerImportBnfFromUrlTest
/** @test */
public function titleShouldBeBnfDotFr() {
$this->assertEquals('http://www.bnf.fr',
$this->_album->getTitre());
$this->assertEquals('http://www.bnf.fr', $this->_album->getTitre());
}
}
\ 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