int main() { bool noTestFailed = true; models::Articles articlesModels(CPPCMSSKEL_TEST_NAME ".db"); CPPCMSSKEL_TEST_RESULT_WORK( "Try load the database ... " , articlesModels.import_sql_file(DB_SQL_FILE_PATH), noTestFailed ); // we first load some raw articles on the database CPPCMSSKEL_TEST_RESULT_WORK( "Try to load the database with some data ... " , articlesModels.import_sql_file(SQL_FILL_ARTICLES), noTestFailed ); // we should be able to get an article ... std::cout << "Try to get an article ... " ; results::Article article = articlesModels.get_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG ); if (article.id > 0 ) { std::cout << " [ok]" << std::endl; } else { std::cout << " [fail]" << std::endl; noTestFailed = false; } // if we request directly the group id of that article, that should be the same // value as when we request the entire articel std::cout << "We should get the same group id when requesting it directly ... " ; int groupId = articlesModels.get_group_id_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG ); if (article.groupId == groupId) { std::cout << " [ok]" << std::endl; } else { std::cout << " [fail]" << std::endl; noTestFailed = false; } if (noTestFailed) { return 0; } else { return 1; } }
int main() { bool noTestFailed = true; models::Articles articlesModels(TEST_NAME ".db"); CPPCMSSKEL_TEST_RESULT_WORK( "Try load the database ... " , articlesModels.import_sql_file(DB_SQL_FILE_PATH), noTestFailed ); // we first load some raw articles on the database CPPCMSSKEL_TEST_RESULT_WORK( "Try to load the database with some data ... " , articlesModels.import_sql_file(SQL_FILL_ARTICLES), noTestFailed ); // load them again should not work as it will not met // the unique(lang,slug) constraint CPPCMSSKEL_TEST_RESULT_NOT_WORK( "Load them again should not work ... " , articlesModels.import_sql_file(SQL_FILL_ARTICLES), noTestFailed ); // now we check if we can retrieve an article std::cout << "We try to get an article using get_from_lang_slug ... "; results::Article firstArticle = articlesModels.get_from_lang_and_slug( "fr", "page_principale" ); if ((!firstArticle.exists())) { noTestFailed = false; std::cout << " [fail]" << std::endl; } else { std::cout << " [ok]" << std::endl; } // now if we try to get an article with the id of the previous one // we should get (of course) the same one std::cout << "Using get_from_id to retrieve the same article ... "; results::Article secondArticle = articlesModels.get_from_id( firstArticle.id ); if ( !secondArticle.exists() || secondArticle.id != firstArticle.id || secondArticle.slug.compare(firstArticle.slug) != 0 || secondArticle.lang.compare(firstArticle.lang) != 0 ) { noTestFailed = false; std::cout << " [fail]" << std::endl; } else { std::cout << " [ok]" << std::endl; } if (noTestFailed) { return 0; } else { return 1; } }
int main() { bool noTestFailed = true; models::Articles articlesModels(TEST_NAME ".db"); CPPCMSSKEL_TEST_RESULT_WORK( "Try load the database ... " , articlesModels.import_sql_file(DB_SQL_FILE_PATH), noTestFailed ); // we should be able to add an article ... std::cout << "Try to add an article ... " ; int result = articlesModels.create_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG, TEST_ARTICLE_TITLE, TEST_ARTICLE_CONTENT ); if (result == TEST_ARTICLE_ID) { std::cout << " [ok]" << std::endl; } else { std::cout << " [fail]" << std::endl; noTestFailed = false; } // try to add the same article should fail std::cout << "Adding the same article twice should be forbidden ... " ; result = articlesModels.create_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG, TEST_ARTICLE_TITLE, TEST_ARTICLE_CONTENT ); if (result == ARTICLE_CREATION_ERROR) { std::cout << " [ok]" << std::endl; } else { std::cout << " [fail]" << std::endl; noTestFailed = false; } // try to retrieve the article we have added // now we check if we can retrieve them std::cout << "We now test if we can get it back ... "; results::Article firstArticle = articlesModels.get_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG ); if ( (firstArticle.id != TEST_ARTICLE_ID) || (firstArticle.lang.compare(TEST_ARTICLE_LANG) != 0) || (firstArticle.slug.compare(TEST_ARTICLE_SLUG) != 0) || (firstArticle.title.compare(TEST_ARTICLE_TITLE) != 0) || (firstArticle.content.compare(TEST_ARTICLE_CONTENT) != 0) ) { noTestFailed = false; std::cout << " [fail]" << std::endl; } else { std::cout << " [ok]" << std::endl; } //now we try to edit the article std::cout << "We now test if we can edit it ... "; bool requestSuccess = articlesModels.edit_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG, TEST_ARTICLE_NEW_TITLE, TEST_ARTICLE_NEW_CONTENT ); if(!requestSuccess) { noTestFailed = false; std::cout << " [fail]" << std::endl; } else { std::cout << " [ok]" << std::endl; } // if we try to get back the article, we shoud get the edited version std::cout << "The article should have been modfied ... "; results::Article editedArticle = articlesModels.get_from_lang_and_slug( TEST_ARTICLE_LANG, TEST_ARTICLE_SLUG ); if( editedArticle.id != TEST_ARTICLE_ID || editedArticle.content.compare(TEST_ARTICLE_NEW_CONTENT) != 0 || editedArticle.title.compare(TEST_ARTICLE_NEW_TITLE) != 0 ) { noTestFailed = false; std::cout << " [fail]" << std::endl; } else { std::cout << " [ok]" << std::endl; } if (noTestFailed) { return 0; } else { return 1; } }