From 671154cdbadb6541a7d71ae01f18476cc6013e6b Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Mon, 1 Dec 2014 11:21:30 +0100 Subject: [PATCH] dev #17990 event categories attribution --- library/Class/Import/Typo3.php | 44 +++++++++++---------- tests/library/Class/Import/Typo3Fixture.php | 10 ++++- tests/library/Class/Import/Typo3Test.php | 33 +++++++++++----- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/library/Class/Import/Typo3.php b/library/Class/Import/Typo3.php index 83d90b5620c..0bde7644aec 100644 --- a/library/Class/Import/Typo3.php +++ b/library/Class/Import/Typo3.php @@ -68,7 +68,7 @@ class Class_Import_Typo3 { $this->importArticlesPages(); echo "Importing events\n"; - $this->import_calendar(); + $this->importCalendar(); echo "Importing sites\n"; $this->import_sites(); @@ -228,18 +228,8 @@ class Class_Import_Typo3 { Class_Import_Typo3_Logs::getInstance()->incrementArticlesSaved(); - $t3_news_domains = $this->t3db->findAllForeignUidForNewsCat($new['uid']); - $domains = [$this->domaine_map->findOrCreateDomaine($element->getCategorie())]; - foreach ($t3_news_domains as $t3_domain) { - if (!$category = $this->news_categories_map->find($t3_domain['uid_foreign'])) - $category = $this->sites_categories_map->find($t3_domain['uid_foreign']); - $domains[] = $this->domaine_map->findOrCreateDomaine($category); - } - - if (isset($category)) { - $element->setCategorie($category); - } - $element->setDomaines($domains)->save(); + $this->news_categories_map->setDomainsFor($element, + $this->t3db->findAllForeignUidForNewsCat($new['uid'])); } Class_Import_Typo3_Logs::getInstance()->setArticlesLog(); @@ -265,7 +255,7 @@ class Class_Import_Typo3 { } - public function import_calendar() { + public function importCalendar() { $cal_news = $this->t3db->findAllCalendarEvents(); @@ -299,13 +289,8 @@ class Class_Import_Typo3 { $this->report['calendar_created']++; - $t3_news_domains = $this->t3db->findAllForeignUidForCalendarEventCategory($new['uid']); - $domains = []; - foreach ($t3_news_domains as $t3_domain) { - $category = $this->cal_categories_map->find($t3_domain['uid_foreign']); - $domains[] = $this->domaine_map->findOrCreateDomaine($category); - } - $element->setDomaines($domains)->save(); + $this->cal_categories_map->setDomainsFor($element, + $this->t3db->findAllForeignUidForCalendarEventCategory($new['uid'])); } return $this; @@ -476,6 +461,23 @@ abstract class CategoriesMap { ? $this->map[$t3id] : $this->default_cat; } + + + + + public function setDomainsFor($model, $t3_news_domains) { + $domains = [$this->domaine_map->findOrCreateDomaine($model->getCategorie())]; + foreach ($t3_news_domains as $t3_domain) { + $category = $this->find($t3_domain['uid_foreign']); + $domains[] = $this->domaine_map->findOrCreateDomaine($category); + } + + if (isset($category)) { + $model->setCategorie($category); + } + + $model->setDomaines($domains)->save(); + } } diff --git a/tests/library/Class/Import/Typo3Fixture.php b/tests/library/Class/Import/Typo3Fixture.php index 3f96c5a6b32..9131f90c2db 100644 --- a/tests/library/Class/Import/Typo3Fixture.php +++ b/tests/library/Class/Import/Typo3Fixture.php @@ -91,7 +91,11 @@ class MockTypo3DB { ['uid' => 24, 'title' => 'Lecture', 'parent_category' => 6 - ] + ], + ['uid' => 26, + 'title' => 'Pont', + 'parent_category' => 0 + ], ]; } @@ -266,7 +270,9 @@ La collection<span style="text-decoration: none"><span style="font-style: normal } public function findAllForeignUidForCalendarEventCategory($uid) { - return []; + return [ + ['uid_foreign' => 26], + ]; } diff --git a/tests/library/Class/Import/Typo3Test.php b/tests/library/Class/Import/Typo3Test.php index 67686d38066..35444d73066 100644 --- a/tests/library/Class/Import/Typo3Test.php +++ b/tests/library/Class/Import/Typo3Test.php @@ -288,33 +288,46 @@ class Import_Typo3CalendarTest extends Import_Typo3TestCase { $this->migration->import_user(); $this->migration->import_categories(); - $this->migration->import_calendar(); + $this->migration->importCalendar(); + + $this->event_bridge = Class_Article::findFirstBy(['titre' => 'Découvrir le Bridge en 10 minutes']); } /** @test */ public function decouvrirBridgeEventShouldBeImported() { - $this->assertNotNull(Class_Article::findFirstBy('titre' > 'Découvrir le Bridge en 10 minutes')); + $this->assertNotNull($this->event_bridge); } /** @test */ public function decouvrirBridgeEventShouldBelongToToto() { - $id_user = Class_Article::findFirstBy(['titre' => 'Découvrir le Bridge en 10 minutes'])->getIdUser(); + $id_user = $this->event_bridge->getIdUser(); $this->assertEquals('toto', Class_Users::findFirstBy(['id_user' => $id_user])->getLogin()); } /** @test */ public function decouvrirBridgeCreationDateShouldBe12Septembre2007() { - $this->assertEquals('2007-09-12 10:50:56', Class_Article::findFirstBy(['titre' => 'Découvrir le Bridge en 10 minutes'])->getDateCreation()); + $this->assertEquals('2007-09-12 10:50:56', $this->event_bridge->getDateCreation()); } /** @test */ public function decouvrirBridgeShouldHaveCategoryAtelier() { - $id_cat = Class_Article::findFirstBy(['titre' => 'Découvrir le Bridge en 10 minutes'])->getIdCat(); - $this->assertEquals('Atelier', Class_ArticleCategorie::findFirstBy(['id' => $id_cat])->getLibelle()); + $id_cat = $this->event_bridge->getIdCat(); + $this->assertEquals('Pont', Class_ArticleCategorie::findFirstBy(['id' => $id_cat])->getLibelle()); + } + + + /** @test */ + public function decouvrirBridgeShouldBeInDomainsAtelierPont() { + $domaine_ids = $this->event_bridge->getDomaineIds(); + $domaines = []; + foreach (explode(';', $domaine_ids) as $id) { + $domaines[] = Class_Catalogue::findFirstBy(['id_catalogue' => $id])->getLibelle(); + } + $this->assertEquals(['Atelier', 'Pont'], $domaines); } @@ -442,7 +455,7 @@ class Import_Typo3LogsTest extends Import_Typo3TestCase { /** @test */ public function logsShouldContainsSavedArticleCategories() { - $this->assertContains("Typo3 Article categories saved: 8", Class_Import_Typo3_Logs::getInstance()->getLogs()); + $this->assertContains("Typo3 Article categories saved: 9", Class_Import_Typo3_Logs::getInstance()->getLogs()); } @@ -460,13 +473,13 @@ class Import_Typo3LogsTest extends Import_Typo3TestCase { /** @test */ public function logsShouldContainsSavedDomains() { - $this->assertContains("Typo3 Domains saved: 9", Class_Import_Typo3_Logs::getInstance()->getLogs()); + $this->assertContains("Typo3 Domains saved: 10", Class_Import_Typo3_Logs::getInstance()->getLogs()); } /** @test */ - public function logsShouldContains1SavedArticles() { - $this->assertContains("Typo3 Articles saved: 5", Class_Import_Typo3_Logs::getInstance()->getLogs()); + public function logsShouldContains8SavedArticles() { + $this->assertContains("Typo3 Articles saved: 8", Class_Import_Typo3_Logs::getInstance()->getLogs()); } -- GitLab