From b7b0bdbdd8d08453c95b37a81d7c5bddd317bbfe Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 15 Mar 2021 17:56:15 +0400 Subject: [PATCH] Both Book::update() methods update the category --- src/book.cpp | 2 ++ test/book.cpp | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/book.cpp b/src/book.cpp index e8c4e0f47..02c82a735 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -61,6 +61,7 @@ bool Book::update(const kiwix::Book& other) m_name = other.m_name; m_flavour = other.m_flavour; m_tags = other.m_tags; + m_category = other.m_category; m_origId = other.m_origId; m_articleCount = other.m_articleCount; m_mediaCount = other.m_mediaCount; @@ -88,6 +89,7 @@ void Book::update(const kiwix::Reader& reader) m_name = reader.getName(); m_flavour = reader.getFlavour(); m_tags = reader.getTags(); + m_category = getCategoryFromTags(); m_origId = reader.getOrigId(); m_articleCount = reader.getArticleCount(); m_mediaCount = reader.getMediaCount(); diff --git a/test/book.cpp b/test/book.cpp index 3c4a67790..22eca5428 100644 --- a/test/book.cpp +++ b/test/book.cpp @@ -144,3 +144,25 @@ TEST(BookTest, updateFromXMLCategoryHandlingTest) EXPECT_EQ(book.getCategory(), "category_attribute_overrides_tags"); } } + +TEST(BookTest, setTagsDoesntAffectCategory) +{ + kiwix::Book book; + + book.setTags("_category:youtube"); + ASSERT_EQ("", book.getCategory()); +} + +TEST(BookTest, updateCopiesCategory) +{ + const XMLDoc xml(R"()"); + + kiwix::Book book; + book.updateFromXml(xml.child("book"), ""); + + kiwix::Book newBook; + newBook.setId("abcd"); + EXPECT_EQ(newBook.getCategory(), ""); + newBook.update(book); + EXPECT_EQ(newBook.getCategory(), "ted"); +}