From 63d08a2bab78e185bc164487a36986de0d044f09 Mon Sep 17 00:00:00 2001 From: Alex Arnaud <alex.arnaud@biblibre.com> Date: Thu, 17 Sep 2015 10:55:16 +0200 Subject: [PATCH] Dev #26120 - fix errors while updating and improve mapping articles with categories --- library/Class/Import/Typo3.php | 8 +++-- tests/library/Class/Import/Typo3Fixture.php | 38 +++++++++++++++++++-- tests/library/Class/Import/Typo3Test.php | 8 +++-- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/library/Class/Import/Typo3.php b/library/Class/Import/Typo3.php index 295f5984d85..c95975b0dad 100644 --- a/library/Class/Import/Typo3.php +++ b/library/Class/Import/Typo3.php @@ -503,8 +503,12 @@ class Class_Import_Typo3 { return; } - $id_cat = ArticleCategoriesMap::getCategoryOrDefaultCategory($new['category']) - ->getId(); + $id_cat = 0; + $t3catIds = $this->t3db->findAllForeignUidForNewsCat($new['uid']); + + foreach ($t3catIds as $t3catId) { + $id_cat = ArticleCategoriesMap::getCategoryOrDefaultCategory($t3catId['uid_foreign'])->getId(); + } $block = function() use ($new, $id_cat){ if ($article = $this->_getArticle($new['uid'])) diff --git a/tests/library/Class/Import/Typo3Fixture.php b/tests/library/Class/Import/Typo3Fixture.php index 6b0c5cc7b3a..f9d42dccab4 100644 --- a/tests/library/Class/Import/Typo3Fixture.php +++ b/tests/library/Class/Import/Typo3Fixture.php @@ -222,10 +222,24 @@ class MockTypo3DB { $articles[5]['title']='Crash Test'; $articles[1]['deleted']=1; $articles[0]['title']='Tous à bord du bateau pirate'; - $articles[0]['category']=777; $articles[0]['bodytext']="MODIFY".$articles[0]['bodytext']; $articles[4]['bodytext']="MODIFIED".$articles[4]['bodytext']; - return [$articles[0],$articles[1], $articles[5], $articles[4]]; + + $new_article = ['uid' => 992, + 'title' => 'souquez les artimuses', + 'crdate' => 141277461, + 'datetime' => 141277461, + 'cruser_id' => 43, + 'starttime' => 1415110980, + 'endtime' => 1422973380, + 'short' => 'fooo', + 'category' => 1, + 'deleted' => 0,'hidden' => 0, + 'bodytext' => 'Fooooooooooooooo', + 'image' => 'bateau.jpg', + 'tx_danpextendnews_tags' => 'Asterix', + ]; + return [$articles[0],$articles[1], $articles[5], $articles[4], $new_article]; } @@ -411,7 +425,7 @@ La collection<span style="text-decoration: none"><span style="font-style: normal } public function findAllForeignUidForNewsCat($uid) { - if (in_array($uid , [14488, 14418])) + if (in_array($uid , [14488, 14418, 992])) return [[ 'uid_foreign' => 867 ]]; if ($uid==14477) @@ -550,3 +564,21 @@ La collection<span style="text-decoration: none"><span style="font-style: normal } } + + +class MockTypo3DBForUpdate extends MockTypo3DB { + + public function findAllForeignUidForNewsCat($uid) { + if (in_array($uid , [14488, 14418, 992])) + return [[ 'uid_foreign' => 867 ]]; + + if ($uid==14477) + return [[ 'uid_foreign' => 36 ]]; + + return [ + ['uid_foreign' => 81], + ['uid_foreign' => 43], + ['uid_foreign' => 777] + ]; + } +} diff --git a/tests/library/Class/Import/Typo3Test.php b/tests/library/Class/Import/Typo3Test.php index 38efa977bfc..8d4ee5b1da5 100644 --- a/tests/library/Class/Import/Typo3Test.php +++ b/tests/library/Class/Import/Typo3Test.php @@ -642,6 +642,7 @@ class Import_Typo3UpdateArticleTest extends Import_Typo3TestCase { Class_CustomField_Value::clearCache(); Class_ArticleCategorie::clearCache(); + $this->migration->setTypo3DB(new MockTypo3DBForUpdate()); $this->migration->updateArticlePages(888); $this->migration->updateArticles(888); @@ -754,8 +755,11 @@ class Import_Typo3UpdateArticleTest extends Import_Typo3TestCase { } - - + /** @test */ + public function categoryForSouquezLesArtimusesShouldBeActionCulturelle() { + $article=Class_Article::findFirstBy(['titre' => 'souquez les artimuses']); + $this->assertEquals('Action Culturelle', $article->getCategorie()->getLibelle()); + } } -- GitLab