Skip to content
Snippets Groups Projects
Commit 0a8a2b7c authored by efalcy's avatar efalcy Committed by Ghislain Loas
Browse files

hotline #88480 : fix error when not category associatedd to external agenda

parent 7e7ca8fd
Branches
Tags
5 merge requests!3297WIP: Master,!3107Master,!3106Master,!3105Hotline,!3096hotline #88480 : fix error when not category associatedd to external agenda
Pipeline #6877 passed with stage
in 35 minutes and 28 seconds
- ticket #88480 : Administration : correction de l'affichage de la liste des agendas externes.
\ No newline at end of file
......@@ -31,7 +31,7 @@ $category = function($model, $attribs) {
return $this->tagAnchor($this->url(['controller' => 'cms',
'action' => 'index',
'id_cat' => $cat_id]),
Class_ArticleCategorie::find($cat_id)->getLibelle());
$model->getCategoryLabel());
};
$description = (new Class_TableDescription('agendas'))
......
......@@ -65,8 +65,10 @@ class Class_ExternalAgenda extends Storm_Model_Abstract {
$results['new'] = $events->select('isNew');
$results['update'] = $events->reject('isNew');
$results['new']->eachDo('save');
if (!Class_AdminVar::get('AGENDA_KEEP_LOCAL_CONTENT'))
$results['update']->eachDo('save');
return $results;
}
......@@ -77,6 +79,9 @@ class Class_ExternalAgenda extends Storm_Model_Abstract {
public function newEvent() {
if (!$category = $this->getCategory())
$this->_initDefaultCategory();
return Class_Article::newInstance(['categorie' => $this->getCategory(),
'repository_origine' => $this->getRepositoryKey(),
'lieu' => $this->getLocation(),
......@@ -100,4 +105,23 @@ class Class_ExternalAgenda extends Storm_Model_Abstract {
Class_ArticleCategorie::clean($this->getCatId());
return $this;
}
public function getCategoryLabel() {
return ($category = $this->getCategory())
? $category->getLibelle()
: '';
}
protected function _initDefaultCategory() {
if (!$default_category = Class_ArticleCategorie::findFirstBy(['libelle' => $this->_('Agendas externes')])) {
$default_category = Class_ArticleCategorie::newInstance(['libelle' => $this->_('Agendas externes')]);
$default_category->save();
}
$this->setCategory($default_category);
$this->save();
return $this;
}
}
......@@ -153,6 +153,9 @@ class Class_WebService_ICalendar extends Class_WebService_Abstract {
protected function _ensureCategory($label) {
if (!$category = $this->_current_event->getCategorie())
return null;
if ($category = $this->_current_event->getCategorie()->findByPath($label))
return $category;
......
......@@ -37,6 +37,12 @@ abstract class ExternalAgendasAdminTestCase extends Admin_AbstractControllerTest
['id' => 2,
'libelle' => 'Others',
'bib' => $this->valleiry]);
$lost_category = $this->fixture('Class_ArticleCategorie',
['id' => 3,
'libelle' => "I'm lost",
'bib' => $this->valleiry]);
$this->fixture('Class_Lieu',
['id' => 22,
......@@ -49,11 +55,15 @@ abstract class ExternalAgendasAdminTestCase extends Admin_AbstractControllerTest
'status' => Class_Article::STATUS_DRAFT,
'category' => $this->events_category]);
Class_WebService_ICalendar::setDefaultHttpClient($this->mock()
->whenCalled('open_url')
->with('http://my.server.com/calendar.ics')
->answers(file_get_contents(__DIR__.'/ical-event-first.ics'))
->whenCalled('open_url')
->with('http://my.server.com/april-calendar.ics')
->answers(file_get_contents(__DIR__.'/ical-event-first.ics'))
->beStrict());
}
......@@ -72,12 +82,37 @@ class ExternalAgendasAdminIndexTest extends ExternalAgendasAdminTestCase {
public function setUp() {
parent::setUp();
Class_ExternalAgenda::find(124)->import($this);
$this->fixture('Class_ArticleCategorie',
['id' => 2,
'libelle' => 'April Events',
'bib' => $this->valleiry]);
$this->fixture('Class_ExternalAgenda',
['id' => 125,
'label' => 'Uncategorised agenda',
'url' => 'http://my.server.com/april-calendar.ics',
'status' => Class_Article::STATUS_DRAFT,
'cat_id' => 2]);
Class_ArticleCategorie::find(2)->delete();
Class_ExternalAgenda::find(125)->import($this);
$this->dispatch('/admin/external-agendas', true);
}
/** @test */
public function pageShouldContainsUncategorisedAgenda() {
$this->assertXPathContentContains('//table[@id="agendas"]//td', 'Uncategorised agenda');
}
/** @test */
public function pageShouldContainsAgendasExternesCategory() {
$this->assertXPathContentContains('//table//td', 'Agendas externes');
}
/** @test */
public function pageTitleShouldBeGestionDesAgendasExternes() {
$this->assertXPathContentContains('//h1', 'Gestion des agendas externes');
......
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