From cf5a0c615e43197c40b4780c33304cff4693c942 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Fri, 1 Jan 2016 17:38:36 -0500 Subject: [PATCH] Release 2.3.1 --- CHANGELOG.md | 4 + README.md | 33 +- admin/partials/book-review-admin-meta-box.php | 2 +- book-review.php | 2 +- includes/class-book-review-activator.php | 2 +- includes/class-book-review-book-info.php | 60 ++- includes/class-book-review.php | 2 +- languages/book-review.pot | 28 +- public/class-book-review-public.php | 17 - public/partials/book-review-public.php | 24 +- tests/test-book-review-book-info.php | 342 +++++++++++++++--- tests/test-book-review-public.php | 20 - 12 files changed, 401 insertions(+), 135 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2ec135..d3a8b4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log # +## 2.3.1 ## +* New: Add new `book_review_links_meta` filter for returning links meta used in the *Book Info* meta box. +* Fix: Change `book_review_links` filter to return links HTML. + ## 2.3.0 ## * New: Add support for custom fields. * Tweak: Improved validation when saving settings and post meta. diff --git a/README.md b/README.md index 278d301..2ed27a1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # Book Review # +## Review More Than Just Books ## +One of the most powerful features of Book Review is the ability to add custom fields to each of your reviews. Custom fields enable you to review movies, music, TV shows and so much more! + ## Save Time ## Book Review saves you time when writing your reviews. No more copying and pasting or manually entering the details of a book. Instead, you provide the ISBN, and Book Review will automatically populate information like title, author, and even the cover photo for you. @@ -56,18 +59,26 @@ OR ## Screenshots ## -###Book Review Settings### -![Book Review Settings](https://cloud.githubusercontent.com/assets/1190420/5692227/a2c1d80c-98ba-11e4-865d-4667943fed02.png) -###Book Info### -![Book Info](https://cloud.githubusercontent.com/assets/1190420/5692230/a2c64090-98ba-11e4-8326-d111d87c7f1a.png) -###Sample Post### -![Book Info on a Sample Post](https://cloud.githubusercontent.com/assets/1190420/5692229/a2c5fae0-98ba-11e4-9323-e690aa648fea.png) -###Archives by Title### +### Settings - Appearance ### +![Settings - Appearance](https://cloud.githubusercontent.com/assets/1190420/12072461/aa3c6d16-b0ad-11e5-85b9-efb284f44328.png) +### Settings - Rating Images ### +![Settings - Rating Images](https://cloud.githubusercontent.com/assets/1190420/12072467/aa474812-b0ad-11e5-86c8-3ca31844f9c5.png) +### Settings - Links ### +![Settings - Links](https://cloud.githubusercontent.com/assets/1190420/12072466/aa40fcb4-b0ad-11e5-8324-df75ae1db768.png) +### Settings - Custom Fields ### +![Settings - Custom Fields](https://cloud.githubusercontent.com/assets/1190420/12072463/aa400cb4-b0ad-11e5-8eda-821050ed8371.png) +### Settings - Advanced ### +![Settings - Advanced](https://cloud.githubusercontent.com/assets/1190420/12072464/aa406b8c-b0ad-11e5-9106-98ac8fa9e791.png) +### Book Info ### +![Book Info](https://cloud.githubusercontent.com/assets/1190420/12072462/aa3efa40-b0ad-11e5-9845-62aa7de7c1e8.png) +### Sample Post ### +![Sample Post](https://cloud.githubusercontent.com/assets/1190420/12072465/aa409134-b0ad-11e5-8323-ecf0365d5274.png) +### Archives by Title ### ![Archives by Title](https://cloud.githubusercontent.com/assets/1190420/5692228/a2c37a0e-98ba-11e4-9f34-789dac88c24b.png) -###Archives by Genre### +### Archives by Genre ### ![Archives by Genre](https://cloud.githubusercontent.com/assets/1190420/5692231/a2c73978-98ba-11e4-8534-1a140584bfec.png) -###Google Search Results Page### -![Google Search Results Page](https://cloud.githubusercontent.com/assets/1190420/5770126/1a086cd6-9cf4-11e4-9881-fc517d73b29e.png) +### Google Search Result ### +![Google Search Result](https://cloud.githubusercontent.com/assets/1190420/5770126/1a086cd6-9cf4-11e4-9881-fc517d73b29e.png) ## Contributions ## Anyone is welcome to contribute to the WordPress Book Review Plugin, but please read the [contribution guidelines](https://github.com/donnapep/book-review/blob/master/CONTRIBUTING.md) first. @@ -86,6 +97,6 @@ There are various ways to get involved: * Follow me on [Google+](https://plus.google.com/u/0/+DonnaPeplinskie/posts), [Twitter](https://twitter.com/donnapep) or [LinkedIn](http://www.linkedin.com/in/donnapeplinskie). ## About Me ## -* I’m the founder of [WP Review Plugins](http://wpreviewplugins.com/). +* I’m the founder of [WP Review Plugins](http://wpreviewplugins.com/), a company specializing in creating review plugins for WordPress. * I blog about web and professional development at [donnapeplinskie.com](http://donnapeplinskie.com/). * I'm an avid reader and a fan of young adult fiction. \ No newline at end of file diff --git a/admin/partials/book-review-admin-meta-box.php b/admin/partials/book-review-admin-meta-box.php index f190ab1..41018c7 100755 --- a/admin/partials/book-review-admin-meta-box.php +++ b/admin/partials/book-review-admin-meta-box.php @@ -130,7 +130,7 @@ book_info->get_book_review_links( $post->ID ); + $links = $this->book_info->get_book_review_links_meta( $post->ID ); foreach ( $links as $link ): ?> diff --git a/book-review.php b/book-review.php index 03180a5..1385cad 100755 --- a/book-review.php +++ b/book-review.php @@ -16,7 +16,7 @@ * Plugin Name: Book Review * Plugin URI: http://wpreviewplugins.com/downloads/book-review/ * Description: Add book information such as title, author, publisher and cover photo to enhance your review posts. - * Version: 2.3.0 + * Version: 2.3.1 * Author: Donna Peplinskie * Author URI: http://donnapeplinskie.com/ * Text Domain: book-review diff --git a/includes/class-book-review-activator.php b/includes/class-book-review-activator.php index faac943..24c749b 100755 --- a/includes/class-book-review-activator.php +++ b/includes/class-book-review-activator.php @@ -28,7 +28,7 @@ class Book_Review_Activator { * @access protected * @var string */ - const VERSION = '2.3.0'; + const VERSION = '2.3.1'; /** * Fired when the plugin is activated. diff --git a/includes/class-book-review-book-info.php b/includes/class-book-review-book-info.php index 5b59d83..487c49d 100755 --- a/includes/class-book-review-book-info.php +++ b/includes/class-book-review-book-info.php @@ -197,25 +197,73 @@ public function get_book_review_field( $post_id, $field_id ) { } /** - * Retrieve the links. + * Retrieve the links meta that displays in the Book Info meta box. * - * @since 2.3.0 + * @since 2.3.1 * * @param string $post_id ID of the current post. */ - public function get_book_review_links( $post_id ) { + public function get_book_review_links_meta( $post_id ) { global $wpdb; - // Get the link text and link URLs. $sql = "SELECT links.custom_link_id, links.text, links.image_url, urls.url FROM {$wpdb->book_review_custom_links} AS links LEFT OUTER JOIN {$wpdb->book_review_custom_link_urls} AS urls ON links.custom_link_id = urls.custom_link_id AND urls.post_id = $post_id WHERE links.active = 1"; - $links = $wpdb->get_results( $sql ); + $links_meta = $wpdb->get_results( $sql ); + + return apply_filters( 'book_review_links_meta', $links_meta, $post_id ); + } + + /** + * Retrieve the links. + * + * @since 2.3.0 + * + * @param string $post_id ID of the current post. + */ + public function get_book_review_links_html( $post_id ) { + global $wpdb; + + $html = array(); + $links_option = $this->settings->get_book_review_links_option(); + $links = $this->get_book_review_links_meta( $post_id ); + + // Construct the HTML for each link. + foreach ( $links as $link ) { + if ( !empty( $link->url ) ) { + if ( !empty( $link->image_url ) ) { + array_push( $html, '
  • get_link_target() . '>' . '' .
+            esc_attr( $link->text ) . '' . '
  • ' ); + } + elseif ( !empty( $link->text ) ) { + array_push( $html, '
  • get_link_target() . '>' . esc_html( $link->text ) . '
  • ' ); + } + } + } + + return apply_filters( 'book_review_links', $html, $post_id, $links_option ); + } + + /** + * Retrieve the target attribute of a link. + * + * @since 2.3.1 + * + * @return string Target attribute or empty string if none. + */ + private function get_link_target() { + $links_option = $this->settings->get_book_review_links_option(); + + if ( $links_option['book_review_target'] == '1' ) { + return ' target="_blank"'; + } - return apply_filters( 'book_review_links', $links, $post_id ); + return ''; } /** diff --git a/includes/class-book-review.php b/includes/class-book-review.php index e66a5f1..5ce7b18 100755 --- a/includes/class-book-review.php +++ b/includes/class-book-review.php @@ -91,7 +91,7 @@ public static function get_instance() { */ private function __construct() { $this->plugin_name = 'book-review'; - $this->version = '2.3.0'; + $this->version = '2.3.1'; if ( !defined( 'BOOK_REVIEW_PLUGIN_DIR' ) ) { define( 'BOOK_REVIEW_PLUGIN_DIR', plugin_dir_path( dirname( __FILE__ ) ) ); diff --git a/languages/book-review.pot b/languages/book-review.pot index 0425cd4..075af9a 100644 --- a/languages/book-review.pot +++ b/languages/book-review.pot @@ -1,14 +1,14 @@ -# Copyright (C) 2015 Book Review +# Copyright (C) 2016 Book Review # This file is distributed under the same license as the Book Review package. msgid "" msgstr "" -"Project-Id-Version: Book Review 2.3.0\n" +"Project-Id-Version: Book Review 2.3.1\n" "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/book-review\n" -"POT-Creation-Date: 2015-12-20 18:23:09+00:00\n" +"POT-Creation-Date: 2016-01-01 16:37:03+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1280,47 +1280,47 @@ msgid "Get Book Info" msgstr "" #: admin/partials/book-review-admin-meta-box.php:32 -#: public/partials/book-review-public.php:36 +#: public/partials/book-review-public.php:42 msgid "Title" msgstr "" #: admin/partials/book-review-admin-meta-box.php:41 -#: public/partials/book-review-public.php:47 +#: public/partials/book-review-public.php:56 msgid "Series" msgstr "" #: admin/partials/book-review-admin-meta-box.php:50 -#: public/partials/book-review-public.php:58 +#: public/partials/book-review-public.php:70 msgid "Author" msgstr "" #: admin/partials/book-review-admin-meta-box.php:59 -#: public/partials/book-review-public.php:71 +#: public/partials/book-review-public.php:86 msgid "Genre" msgstr "" #: admin/partials/book-review-admin-meta-box.php:68 -#: public/partials/book-review-public.php:82 +#: public/partials/book-review-public.php:100 msgid "Publisher" msgstr "" #: admin/partials/book-review-admin-meta-box.php:78 -#: public/partials/book-review-public.php:93 +#: public/partials/book-review-public.php:114 msgid "Release Date" msgstr "" #: admin/partials/book-review-admin-meta-box.php:87 -#: public/partials/book-review-public.php:104 +#: public/partials/book-review-public.php:128 msgid "Format" msgstr "" #: admin/partials/book-review-admin-meta-box.php:96 -#: public/partials/book-review-public.php:115 +#: public/partials/book-review-public.php:142 msgid "Pages" msgstr "" #: admin/partials/book-review-admin-meta-box.php:105 -#: public/partials/book-review-public.php:126 +#: public/partials/book-review-public.php:156 msgid "Source" msgstr "" @@ -1356,7 +1356,7 @@ msgstr "" msgid "Dismiss this notice." msgstr "" -#: public/partials/book-review-public.php:30 +#: public/partials/book-review-public.php:33 msgid "Book Cover" msgstr "" diff --git a/public/class-book-review-public.php b/public/class-book-review-public.php index c10bc2e..8e89ad2 100755 --- a/public/class-book-review-public.php +++ b/public/class-book-review-public.php @@ -152,23 +152,6 @@ public function get_review_box_style() { return ''; } - /** - * Retrieve the target attribute of a link. - * - * @since 2.3.0 - * - * @return string Target attribute or empty string if none. - */ - public function get_link_target() { - $links_option = $this->settings->get_book_review_links_option(); - - if ( $links_option['book_review_target'] == '1' ) { - return 'target="_blank"'; - } - - return ''; - } - /** * Add rating to the excerpt. * diff --git a/public/partials/book-review-public.php b/public/partials/book-review-public.php index 4063238..bed1170 100755 --- a/public/partials/book-review-public.php +++ b/public/partials/book-review-public.php @@ -210,27 +210,11 @@ \ No newline at end of file diff --git a/tests/test-book-review-book-info.php b/tests/test-book-review-book-info.php index 61c79a5..323a86a 100644 --- a/tests/test-book-review-book-info.php +++ b/tests/test-book-review-book-info.php @@ -33,7 +33,7 @@ public function tearDown() { } /** - * @covers Book_Review_Admin::get_book_review_isbn + * @covers Book_Review_Book_Info::get_book_review_isbn */ public function testISBN() { update_post_meta( $this->post_id, 'book_review_isbn', '0525478817' ); @@ -42,14 +42,14 @@ public function testISBN() { } /** - * @covers Book_Review_Admin::get_book_review_isbn + * @covers Book_Review_Book_Info::get_book_review_isbn */ public function testNoISBN() { $this->assertSame( '', $this->book_info->get_book_review_isbn( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_title + * @covers Book_Review_Book_Info::get_book_review_title */ public function testTitle() { update_post_meta( $this->post_id, 'book_review_title', 'The Fault in Our Stars' ); @@ -58,14 +58,14 @@ public function testTitle() { } /** - * @covers Book_Review_Admin::get_book_review_title + * @covers Book_Review_Book_Info::get_book_review_title */ public function testNoTitle() { $this->assertSame( '', $this->book_info->get_book_review_title( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_series + * @covers Book_Review_Book_Info::get_book_review_series */ public function testSeries() { update_post_meta( $this->post_id, 'book_review_series', 'None' ); @@ -74,14 +74,14 @@ public function testSeries() { } /** - * @covers Book_Review_Admin::get_book_review_series + * @covers Book_Review_Book_Info::get_book_review_series */ public function testNoSeries() { $this->assertSame( '', $this->book_info->get_book_review_series( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_author + * @covers Book_Review_Book_Info::get_book_review_author */ public function testAuthor() { update_post_meta( $this->post_id, 'book_review_author', 'John Green' ); @@ -90,14 +90,14 @@ public function testAuthor() { } /** - * @covers Book_Review_Admin::get_book_review_author + * @covers Book_Review_Book_Info::get_book_review_author */ public function testNoAuthor() { $this->assertSame( '', $this->book_info->get_book_review_author( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_genre + * @covers Book_Review_Book_Info::get_book_review_genre */ public function testGenre() { update_post_meta( $this->post_id, 'book_review_genre', 'Young Adult' ); @@ -106,14 +106,14 @@ public function testGenre() { } /** - * @covers Book_Review_Admin::get_book_review_genre + * @covers Book_Review_Book_Info::get_book_review_genre */ public function testNoGenre() { $this->assertSame( '', $this->book_info->get_book_review_genre( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_publisher + * @covers Book_Review_Book_Info::get_book_review_publisher */ public function testPublisher() { update_post_meta( $this->post_id, 'book_review_publisher', 'Dutton Books' ); @@ -122,14 +122,14 @@ public function testPublisher() { } /** - * @covers Book_Review_Admin::get_book_review_publisher + * @covers Book_Review_Book_Info::get_book_review_publisher */ public function testNoPublisher() { $this->assertSame( '', $this->book_info->get_book_review_publisher( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_release_date + * @covers Book_Review_Book_Info::get_book_review_release_date */ public function testReleaseDate() { update_post_meta( $this->post_id, 'book_review_release_date', '2010-05-25' ); @@ -138,14 +138,14 @@ public function testReleaseDate() { } /** - * @covers Book_Review_Admin::get_book_review_release_date + * @covers Book_Review_Book_Info::get_book_review_release_date */ public function testNoReleaseDate() { $this->assertSame( '', $this->book_info->get_book_review_release_date( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_format + * @covers Book_Review_Book_Info::get_book_review_format */ public function testFormat() { update_post_meta( $this->post_id, 'book_review_format', 'Paperback' ); @@ -154,14 +154,14 @@ public function testFormat() { } /** - * @covers Book_Review_Admin::get_book_review_format + * @covers Book_Review_Book_Info::get_book_review_format */ public function testNoFormat() { $this->assertSame( '', $this->book_info->get_book_review_format( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_pages + * @covers Book_Review_Book_Info::get_book_review_pages */ public function testPages() { update_post_meta( $this->post_id, 'book_review_pages', '313' ); @@ -170,14 +170,14 @@ public function testPages() { } /** - * @covers Book_Review_Admin::get_book_review_pages + * @covers Book_Review_Book_Info::get_book_review_pages */ public function testNoPages() { $this->assertSame( '', $this->book_info->get_book_review_pages( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_source + * @covers Book_Review_Book_Info::get_book_review_source */ public function testSource() { update_post_meta( $this->post_id, 'book_review_source', 'Purchased' ); @@ -186,14 +186,14 @@ public function testSource() { } /** - * @covers Book_Review_Admin::get_book_review_source + * @covers Book_Review_Book_Info::get_book_review_source */ public function testNoSource() { $this->assertSame( '', $this->book_info->get_book_review_source( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_field + * @covers Book_Review_Book_Info::get_book_review_field */ public function testField() { update_post_meta( $this->post_id, 'book_review_565adc1c2d403', 'Charlie Adlard' ); @@ -203,7 +203,7 @@ public function testField() { } /** - * @covers Book_Review_Admin::get_book_review_field + * @covers Book_Review_Book_Info::get_book_review_field */ public function testNoField() { $this->assertSame( '', $this->book_info->get_book_review_field( $this->post_id, @@ -211,9 +211,9 @@ public function testNoField() { } /** - * @covers Book_Review_Admin::get_book_review_links + * @covers Book_Review_Book_Info::get_book_review_links_meta */ - public function testLinks() { + public function testLinksMeta() { global $wpdb; $this->create_tables(); @@ -240,7 +240,7 @@ public function testLinks() { array( '%d', '%s', '%s' ) ); - $links = $this->book_info->get_book_review_links( $this->post_id ); + $links = $this->book_info->get_book_review_links_meta( $this->post_id ); $this->assertSame( 1, count( $links ), 'Link count' ); // MySQL returns everything as strings regardless of data type. @@ -254,18 +254,271 @@ public function testLinks() { } /** - * @covers Book_Review_Admin::get_book_review_links + * @covers Book_Review_Book_Info::get_book_review_links_meta */ - public function testNoLinks() { + public function testNoLinksMeta() { $this->create_tables(); - $this->assertSame( array(), $this->book_info->get_book_review_links( $this->post_id ) ); + $this->assertSame( array(), $this->book_info->get_book_review_links_meta( $this->post_id ) ); $this->drop_tables(); } /** - * @covers Book_Review_Admin::get_book_review_cover_url + * @covers Book_Review_Book_Info::get_book_review_links_meta + */ + public function testNoActiveLinksMeta() { + global $wpdb; + + $this->create_tables(); + + // Add an inactive link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads', + 'image_url' => 'http://fakeurl.com/Goodreads.png', + 'active' => 0 + ), + array( '%d', '%s', '%s', '%d' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( array(), $this->book_info->get_book_review_links_meta( $this->post_id ) ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + */ + public function testImageLinkHtml() { + global $wpdb; + + $html[] = '
  • Goodreads
  • '; + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads', + 'image_url' => 'http://fakeurl.com/Goodreads.png' + ), + array( '%d', '%s', '%s' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( $html[0], $this->book_info->get_book_review_links_html( $this->post_id )[0] ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + */ + public function testTextLinkHtml() { + global $wpdb; + + $html[] = '
  • Goodreads
  • '; + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads' + ), + array( '%d', '%s', '%s' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( $html[0], $this->book_info->get_book_review_links_html( $this->post_id )[0] ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + */ + public function testNoUrlLinkHtml() { + global $wpdb; + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads', + 'image_url' => 'http://fakeurl.com/Goodreads.png' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( array(), $this->book_info->get_book_review_links_html( $this->post_id ) ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + */ + public function testNoImageUrlNoTextLinkHtml() { + global $wpdb; + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1 + ), + array( '%d', '%s', '%s' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( array(), $this->book_info->get_book_review_links_html( $this->post_id ) ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + * @covers Book_Review_Book_Info::get_link_target + */ + public function testImageLinkHtmlTarget() { + global $wpdb; + + $html[] = '
  • Goodreads
  • '; + + $links_option = array( + 'book_review_target' => '1' + ); + + add_option( 'book_review_links', $links_option ); + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads', + 'image_url' => 'http://fakeurl.com/Goodreads.png' + ), + array( '%d', '%s', '%s' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( $html[0], $this->book_info->get_book_review_links_html( $this->post_id )[0] ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_links_html + * @covers Book_Review_Book_Info::get_link_target + */ + public function testTextLinkHtmlTarget() { + global $wpdb; + + $html[] = '
  • Goodreads
  • '; + + $links_option = array( + 'book_review_target' => '1' + ); + + add_option( 'book_review_links', $links_option ); + + $this->create_tables(); + + // Add a link. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_links", + array( + 'custom_link_id' => 1, + 'text' => 'Goodreads' + ), + array( '%d', '%s', '%s' ) + ); + + // Add a link URL. + $wpdb->insert( + $wpdb->prefix . "book_review_custom_link_urls", + array( + 'post_id' => $this->post_id, + 'custom_link_id' => 1, + 'url' => 'https://www.goodreads.com/book/show/11870085-the-fault-in-our-stars' + ), + array( '%d', '%s', '%s' ) + ); + + $this->assertSame( $html[0], $this->book_info->get_book_review_links_html( $this->post_id )[0] ); + + $this->drop_tables(); + } + + /** + * @covers Book_Review_Book_Info::get_book_review_cover_url */ public function testCoverUrl() { $url = 'http://example.com/wp-content/uploads/2014/04/The_Fault_in_Our_Stars_Book_Cover.jpg'; @@ -276,14 +529,14 @@ public function testCoverUrl() { } /** - * @covers Book_Review_Admin::get_book_review_cover_url + * @covers Book_Review_Book_Info::get_book_review_cover_url */ public function testNoCoverUrl() { $this->assertSame( '', $this->book_info->get_book_review_cover_url( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_summary + * @covers Book_Review_Book_Info::get_book_review_summary */ public function testSummary() { $summary = 'Despite the tumor-shrinking medical miracle that has bought her a few years, Hazel has never been anything but terminal, her final chapter inscribed upon diagnosis. But when a gorgeous plot twist named Augustus Waters suddenly appears at Cancer Kid Support Group, Hazel\'s story is about to be completely rewritten.'; @@ -294,14 +547,14 @@ public function testSummary() { } /** - * @covers Book_Review_Admin::get_book_review_summary + * @covers Book_Review_Book_Info::get_book_review_summary */ public function testNoSummary() { $this->assertSame( '', $this->book_info->get_book_review_summary( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_rating + * @covers Book_Review_Book_Info::get_book_review_rating */ public function testRating() { update_post_meta( $this->post_id, 'book_review_rating', '4' ); @@ -310,14 +563,14 @@ public function testRating() { } /** - * @covers Book_Review_Admin::get_book_review_rating + * @covers Book_Review_Book_Info::get_book_review_rating */ public function testNoRating() { $this->assertSame( '', $this->book_info->get_book_review_rating( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_rating_image + * @covers Book_Review_Book_Info::get_book_review_rating_image */ public function testDefaultRatingImage() { update_post_meta( $this->post_id, 'book_review_rating', '4' ); @@ -326,7 +579,7 @@ public function testDefaultRatingImage() { } /** - * @covers Book_Review_Admin::get_book_review_rating_image + * @covers Book_Review_Book_Info::get_book_review_rating_image */ public function testNoDefaultRatingImage() { update_post_meta( $this->post_id, 'book_review_rating', '-1' ); @@ -335,7 +588,7 @@ public function testNoDefaultRatingImage() { } /** - * @covers Book_Review_Admin::get_book_review_rating_image + * @covers Book_Review_Book_Info::get_book_review_rating_image */ public function testCustomRatingImage() { $ratings_option = array( @@ -350,7 +603,7 @@ public function testCustomRatingImage() { } /** - * @covers Book_Review_Admin::get_book_review_rating_image + * @covers Book_Review_Book_Info::get_book_review_rating_image */ public function testNoCustomRatingImage() { $ratings_option = array( @@ -364,7 +617,7 @@ public function testNoCustomRatingImage() { } /** - * @covers Book_Review_Admin::get_book_review_rating_image + * @covers Book_Review_Book_Info::get_book_review_rating_image */ public function testCustomRatingImageNotSet() { $ratings_option = array( @@ -377,7 +630,7 @@ public function testCustomRatingImageNotSet() { } /** - * @covers Book_Review_Admin::get_book_review_archive_post + * @covers Book_Review_Book_Info::get_book_review_archive_post */ public function testArchivePostChecked() { update_post_meta( $this->post_id, 'book_review_archive_post', '1' ); @@ -386,7 +639,7 @@ public function testArchivePostChecked() { } /** - * @covers Book_Review_Admin::get_book_review_archive_post + * @covers Book_Review_Book_Info::get_book_review_archive_post */ public function testArchivePostNotChecked() { update_post_meta( $this->post_id, 'book_review_archive_post', '' ); @@ -395,14 +648,14 @@ public function testArchivePostNotChecked() { } /** - * @covers Book_Review_Admin::get_book_review_archive_post + * @covers Book_Review_Book_Info::get_book_review_archive_post */ public function testArchivePostNotSet() { $this->assertSame( '1', $this->book_info->get_book_review_archive_post( $this->post_id ) ); } /** - * @covers Book_Review_Admin::get_book_review_archive_post + * @covers Book_Review_Book_Info::get_book_review_archive_post */ public function testArchivePostNoMeta() { // Delete all post meta. @@ -429,7 +682,10 @@ private function create_tables() { private function drop_tables() { global $wpdb; + // Delete options manually since removing the filter below won't delete them in the teardown. delete_option( 'book_review_version' ); + delete_option( 'book_review_links' ); + remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'book_review_custom_links' ); diff --git a/tests/test-book-review-public.php b/tests/test-book-review-public.php index fda231b..0214db6 100644 --- a/tests/test-book-review-public.php +++ b/tests/test-book-review-public.php @@ -217,26 +217,6 @@ public function testNoBackgroundColor() { $this->assertSame( $style, $this->plugin_public->get_review_box_style() ); } - /** - * @covers Book_Review_Public::get_link_target - */ - public function testLinkTarget() { - $links_option = array( - 'book_review_target' => '1' - ); - - add_option( 'book_review_links', $links_option ); - - $this->assertSame( 'target="_blank"', $this->plugin_public->get_link_target() ); - } - - /** - * @covers Book_Review_Public::get_link_target - */ - public function testNoLinkTarget() { - $this->assertSame( '', $this->plugin_public->get_link_target() ); - } - /** * @covers Book_Review_Public::add_rating */