Skip to content

Commit

Permalink
Both Book::update() methods update the category
Browse files Browse the repository at this point in the history
  • Loading branch information
veloman-yunkan committed Mar 15, 2021
1 parent afd8906 commit 39842b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions test/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(<book id="abcd" category="ted"></book>)");

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");
}

0 comments on commit 39842b2

Please sign in to comment.