Skip to content
Snippets Groups Projects
Commit 2f5e6dc2 authored by llaffont's avatar llaffont
Browse files

Import Agenda SQY: sauvegarde des catégories / articles importés

parent 98fbc4a5
No related merge requests found
......@@ -44,7 +44,20 @@ Trait Trait_Agenda_SQY_ItemWrapper {
public static function getWrappedInstance($id) {
return isset(static::$_instances[$id]) ? static::$_instances[$id] : null;
if (!isset(static::$_instances[$id]))
return null;
$wrapper = static::$_instances[$id];
return $wrapper->_wrapped_instance;
}
public static function getWrappedInstances() {
$wrapped_instances = [];
foreach(static::$_instances as $instance) {
$wrapped_instances []= $instance->_wrapped_instance;
}
return $wrapped_instances;
}
......@@ -57,7 +70,6 @@ Trait Trait_Agenda_SQY_ItemWrapper {
public function initialize() {}
public function __call($method, $args) {
return isset(static::$_method_map[$method])
? call_user_func_array([$this->_wrapped_instance, static::$_method_map[$method]],
......@@ -126,7 +138,7 @@ class Class_Agenda_SQY_EventWrapper {
$category_id = explode(',', $category_id)[0];
$category = Class_Agenda_SQY_CategoryWrapper::getWrappedInstance($category_id);
$this->_wrapped_instance->setCategorie($category);
$category->addArticle($this->_wrapped_instance);
return $this;
}
......@@ -162,6 +174,14 @@ class Class_Agenda_SQY_CategoryWrapper {
static::originalResetInstances();
static::newInstance(['INDEX' => 0])->setTitle('Portail');
}
public static function saveInstances() {
$instances = static::getWrappedInstances();
foreach($instances as $category) {
$category->save();
}
}
}
......@@ -207,6 +227,7 @@ class Class_Agenda_SQY {
$this->_xml_parser = (new Class_WebService_XMLParser())->setElementHandler($this);
$this->_xml_parser->parse($xml);
Class_Agenda_SQY_EventWrapper::mapLocationsAndCategories();
Class_Agenda_SQY_CategoryWrapper::saveInstances();
return $this;
}
......
......@@ -45,9 +45,9 @@ $path = dirname(__FILE__);
$parts = explode(DIRECTORY_SEPARATOR, $path);
$parts = array_reverse($parts);
define("BASE_URL", "/" . $parts[1]);
define("URL_IMG", BASE_URL . "/public/opac/skins/original/images/");
define("URL_SHARED_IMG", BASE_URL . "/public/opac/images");
defineConstant("BASE_URL", "/" . $parts[1]);
defineConstant("URL_IMG", BASE_URL . "/public/opac/skins/original/images/");
defineConstant("URL_SHARED_IMG", BASE_URL . "/public/opac/images");
setupOpac();
......
......@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class AgendaSQYImportTest extends Storm_Test_ModelTestCase {
protected $_categories;
protected $_events;
......@@ -26,6 +27,16 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase {
public function setUp() {
parent::setUp();
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
->whenCalled('save')->answers(true);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_ArticleCategorie')
->whenCalled('save')->answers(true);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Lieu')
->whenCalled('save')->answers(true);
$xml = file_get_contents(realpath(dirname(__FILE__)). '/../../fixtures/agenda-sqy.xml');
$agenda = (new Class_Agenda_SQY())->importFromXML($xml);
$this->_categories = $agenda->getCategories();
......@@ -144,6 +155,16 @@ class AgendaSQYImportTest extends Storm_Test_ModelTestCase {
}
/**
* @test
* @depends firstEventTitreShouldBeRevonsLaVille
*/
public function firstEventShouldHaveBeenSaved($event_revons) {
$this->assertEquals('"Rêvons la ville"',
Class_Article::getFirstAttributeForMethodCallAt('save', 0)->getTitre());
}
/** @test */
public function fourthEventLocationShouldBeMuseeNational() {
$event_infinis = $this->_events[3992];
......
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