Version Description
("Gutentag") = * 5.0 Compat: Hide core author inputs when using the Block Editor to limit confusion (h/t jonathanstegall).
Download this release
Release Info
Developer | batmoo |
Plugin | Co-Authors Plus |
Version | 3.3.1 |
Comparing to | |
See all releases |
Code changes from version 3.3.0 to 3.3.1
- .travis.yml +0 -14
- bin/install-wp-tests.sh +0 -112
- co-authors-plus.php +2 -2
- composer.json +0 -27
- css/co-authors-plus.css +6 -0
- phpunit.xml +0 -17
- readme.txt +5 -2
- tests/bootstrap.php +0 -17
- tests/coauthorsplus-testcase.php +0 -13
- tests/test-author-queried-object.php +0 -95
- tests/test-author-queries.php +0 -129
- tests/test-coauthors-guest-authors.php +0 -890
- tests/test-coauthors-plus.php +0 -679
- tests/test-manage-coauthors.php +0 -428
- tests/test-template-tags.php +0 -1068
.travis.yml
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
language: php
|
2 |
-
|
3 |
-
php:
|
4 |
-
- 5.3
|
5 |
-
- 5.5
|
6 |
-
|
7 |
-
env:
|
8 |
-
- WP_VERSION=latest
|
9 |
-
- WP_VERSION=3.7
|
10 |
-
|
11 |
-
before_script:
|
12 |
-
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
|
13 |
-
|
14 |
-
script: phpunit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bin/install-wp-tests.sh
DELETED
@@ -1,112 +0,0 @@
|
|
1 |
-
#!/usr/bin/env bash
|
2 |
-
|
3 |
-
if [ $# -lt 3 ]; then
|
4 |
-
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
|
5 |
-
exit 1
|
6 |
-
fi
|
7 |
-
|
8 |
-
DB_NAME=$1
|
9 |
-
DB_USER=$2
|
10 |
-
DB_PASS=$3
|
11 |
-
DB_HOST=${4-localhost}
|
12 |
-
WP_VERSION=${5-latest}
|
13 |
-
|
14 |
-
WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
|
15 |
-
WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
|
16 |
-
|
17 |
-
download() {
|
18 |
-
if [ `which curl` ]; then
|
19 |
-
curl -s "$1" > "$2";
|
20 |
-
elif [ `which wget` ]; then
|
21 |
-
wget -nv -O "$2" "$1"
|
22 |
-
fi
|
23 |
-
}
|
24 |
-
|
25 |
-
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
|
26 |
-
WP_TESTS_TAG="tags/$WP_VERSION"
|
27 |
-
else
|
28 |
-
# http serves a single offer, whereas https serves multiple. we only want one
|
29 |
-
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
|
30 |
-
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
|
31 |
-
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
|
32 |
-
if [[ -z "$LATEST_VERSION" ]]; then
|
33 |
-
echo "Latest WordPress version could not be found"
|
34 |
-
exit 1
|
35 |
-
fi
|
36 |
-
WP_TESTS_TAG="tags/$LATEST_VERSION"
|
37 |
-
fi
|
38 |
-
|
39 |
-
set -ex
|
40 |
-
|
41 |
-
install_wp() {
|
42 |
-
|
43 |
-
if [ -d $WP_CORE_DIR ]; then
|
44 |
-
return;
|
45 |
-
fi
|
46 |
-
|
47 |
-
mkdir -p $WP_CORE_DIR
|
48 |
-
|
49 |
-
if [ $WP_VERSION == 'latest' ]; then
|
50 |
-
local ARCHIVE_NAME='latest'
|
51 |
-
else
|
52 |
-
local ARCHIVE_NAME="wordpress-$WP_VERSION"
|
53 |
-
fi
|
54 |
-
|
55 |
-
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
|
56 |
-
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
|
57 |
-
|
58 |
-
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
|
59 |
-
}
|
60 |
-
|
61 |
-
install_test_suite() {
|
62 |
-
# portable in-place argument for both GNU sed and Mac OSX sed
|
63 |
-
if [[ $(uname -s) == 'Darwin' ]]; then
|
64 |
-
local ioption='-i .bak'
|
65 |
-
else
|
66 |
-
local ioption='-i'
|
67 |
-
fi
|
68 |
-
|
69 |
-
# set up testing suite if it doesn't yet exist
|
70 |
-
if [ ! -d $WP_TESTS_DIR ]; then
|
71 |
-
# set up testing suite
|
72 |
-
mkdir -p $WP_TESTS_DIR
|
73 |
-
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
|
74 |
-
fi
|
75 |
-
|
76 |
-
cd $WP_TESTS_DIR
|
77 |
-
|
78 |
-
if [ ! -f wp-tests-config.php ]; then
|
79 |
-
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
|
80 |
-
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
|
81 |
-
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
|
82 |
-
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
|
83 |
-
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
|
84 |
-
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
|
85 |
-
fi
|
86 |
-
|
87 |
-
}
|
88 |
-
|
89 |
-
install_db() {
|
90 |
-
# parse DB_HOST for port or socket references
|
91 |
-
local PARTS=(${DB_HOST//\:/ })
|
92 |
-
local DB_HOSTNAME=${PARTS[0]};
|
93 |
-
local DB_SOCK_OR_PORT=${PARTS[1]};
|
94 |
-
local EXTRA=""
|
95 |
-
|
96 |
-
if ! [ -z $DB_HOSTNAME ] ; then
|
97 |
-
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
|
98 |
-
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
|
99 |
-
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
|
100 |
-
EXTRA=" --socket=$DB_SOCK_OR_PORT"
|
101 |
-
elif ! [ -z $DB_HOSTNAME ] ; then
|
102 |
-
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
|
103 |
-
fi
|
104 |
-
fi
|
105 |
-
|
106 |
-
# create database
|
107 |
-
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
|
108 |
-
}
|
109 |
-
|
110 |
-
install_wp
|
111 |
-
install_test_suite
|
112 |
-
install_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
co-authors-plus.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Co-Authors Plus
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
|
5 |
Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter.
|
6 |
-
Version: 3.3.
|
7 |
Author: Mohammad Jangda, Daniel Bachhuber, Automattic
|
8 |
Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter
|
9 |
|
@@ -32,7 +32,7 @@ Co-author - in the context of a single post, a guest author or user assigned to
|
|
32 |
Author - user with the role of author
|
33 |
*/
|
34 |
|
35 |
-
define( 'COAUTHORS_PLUS_VERSION', '3.3.
|
36 |
|
37 |
require_once( dirname( __FILE__ ) . '/template-tags.php' );
|
38 |
require_once( dirname( __FILE__ ) . '/deprecated.php' );
|
3 |
Plugin Name: Co-Authors Plus
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/co-authors-plus/
|
5 |
Description: Allows multiple authors to be assigned to a post. This plugin is an extended version of the Co-Authors plugin developed by Weston Ruter.
|
6 |
+
Version: 3.3.1
|
7 |
Author: Mohammad Jangda, Daniel Bachhuber, Automattic
|
8 |
Copyright: 2008-2015 Shared and distributed between Mohammad Jangda, Daniel Bachhuber, Weston Ruter
|
9 |
|
32 |
Author - user with the role of author
|
33 |
*/
|
34 |
|
35 |
+
define( 'COAUTHORS_PLUS_VERSION', '3.3.1' );
|
36 |
|
37 |
require_once( dirname( __FILE__ ) . '/template-tags.php' );
|
38 |
require_once( dirname( __FILE__ ) . '/deprecated.php' );
|
composer.json
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"name" : "automattic/co-authors-plus",
|
3 |
-
"description": "Multiple bylines and Guest Authors for WordPress",
|
4 |
-
"homepage" : "http://wordpress.org/plugins/co-authors-plus/",
|
5 |
-
"type" : "wordpress-plugin",
|
6 |
-
"license" : "GPL-2.0+",
|
7 |
-
"authors" : [
|
8 |
-
{
|
9 |
-
"name": "Daniel Bachhuber",
|
10 |
-
"email": "d@danielbachhuber.com",
|
11 |
-
"homepage": "http://danielbachhuber.com",
|
12 |
-
"role": "Developer"
|
13 |
-
},
|
14 |
-
{
|
15 |
-
"name" : "Automattic",
|
16 |
-
"homepage": "http://automattic.com/"
|
17 |
-
}
|
18 |
-
],
|
19 |
-
"support" : {
|
20 |
-
"issues": "https://github.com/Automattic/Co-Authors-Plus/issues",
|
21 |
-
"source": "https://github.com/Automattic/Co-Authors-Plus",
|
22 |
-
"forum": "http://wordpress.org/support/plugin/co-authors-plus"
|
23 |
-
},
|
24 |
-
"require": {
|
25 |
-
"composer/installers": "~1.0"
|
26 |
-
}
|
27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css/co-authors-plus.css
CHANGED
@@ -109,3 +109,9 @@
|
|
109 |
margin-left: 30px;
|
110 |
font-size: 13px;
|
111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
109 |
margin-left: 30px;
|
110 |
font-size: 13px;
|
111 |
}
|
112 |
+
|
113 |
+
/** Block Editor Hack for 5.0: Hide the core author input **/
|
114 |
+
.block-editor label[for^="post-author-selector-"],
|
115 |
+
.block-editor select[id^="post-author-selector-"] {
|
116 |
+
display: none;
|
117 |
+
}
|
phpunit.xml
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<phpunit
|
2 |
-
bootstrap="tests/bootstrap.php"
|
3 |
-
backupGlobals="false"
|
4 |
-
colors="true"
|
5 |
-
convertErrorsToExceptions="true"
|
6 |
-
convertNoticesToExceptions="true"
|
7 |
-
convertWarningsToExceptions="true"
|
8 |
-
>
|
9 |
-
<php>
|
10 |
-
<const name="WP_TESTS_MULTISITE" value="1" />
|
11 |
-
</php>
|
12 |
-
<testsuites>
|
13 |
-
<testsuite>
|
14 |
-
<directory prefix="test-" suffix=".php">./tests/</directory>
|
15 |
-
</testsuite>
|
16 |
-
</testsuites>
|
17 |
-
</phpunit>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Co-Authors Plus ===
|
2 |
Contributors: batmoo, danielbachhuber, automattic
|
3 |
Tags: authors, users, multiple authors, coauthors, multi-author, publishing
|
4 |
-
Tested up to:
|
5 |
Requires at least: 4.1
|
6 |
-
Stable tag: 3.3.
|
7 |
|
8 |
Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box
|
9 |
|
@@ -57,6 +57,9 @@ Bug fixes and minor enhancements
|
|
57 |
|
58 |
== Changelog ==
|
59 |
|
|
|
|
|
|
|
60 |
= 3.3.0 ("Rebecca") =
|
61 |
* Fix private post viewing on front-end
|
62 |
* Reduce amount of sleep
|
1 |
=== Co-Authors Plus ===
|
2 |
Contributors: batmoo, danielbachhuber, automattic
|
3 |
Tags: authors, users, multiple authors, coauthors, multi-author, publishing
|
4 |
+
Tested up to: 5.0
|
5 |
Requires at least: 4.1
|
6 |
+
Stable tag: 3.3.1
|
7 |
|
8 |
Assign multiple bylines to posts, pages, and custom post types via a search-as-you-type input box
|
9 |
|
57 |
|
58 |
== Changelog ==
|
59 |
|
60 |
+
= 3.3.1 ("Gutentag") =
|
61 |
+
* 5.0 Compat: Hide core author inputs when using the Block Editor to limit confusion (h/t jonathanstegall).
|
62 |
+
|
63 |
= 3.3.0 ("Rebecca") =
|
64 |
* Fix private post viewing on front-end
|
65 |
* Reduce amount of sleep
|
tests/bootstrap.php
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
$_tests_dir = getenv( 'WP_TESTS_DIR' );
|
4 |
-
if ( ! $_tests_dir ) {
|
5 |
-
$_tests_dir = '/tmp/wordpress-tests-lib';
|
6 |
-
}
|
7 |
-
|
8 |
-
require_once $_tests_dir . '/includes/functions.php';
|
9 |
-
|
10 |
-
function _manually_load_plugin() {
|
11 |
-
require dirname( __FILE__ ) . '/../co-authors-plus.php';
|
12 |
-
}
|
13 |
-
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
14 |
-
|
15 |
-
require $_tests_dir . '/includes/bootstrap.php';
|
16 |
-
|
17 |
-
require dirname( __FILE__ ) . '/coauthorsplus-testcase.php';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/coauthorsplus-testcase.php
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Base unit test class for Co-Authors Plus
|
5 |
-
*/
|
6 |
-
class CoAuthorsPlus_TestCase extends WP_UnitTestCase {
|
7 |
-
public function setUp() {
|
8 |
-
parent::setUp();
|
9 |
-
|
10 |
-
global $coauthors_plus;
|
11 |
-
$this->_cap = $coauthors_plus;
|
12 |
-
}
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test-author-queried-object.php
DELETED
@@ -1,95 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Test Co-Authors Plus' modifications of author queries
|
4 |
-
*/
|
5 |
-
|
6 |
-
class Test_Author_Queried_Object extends CoAuthorsPlus_TestCase {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Set up for test
|
10 |
-
*
|
11 |
-
* Don't create tables as 'temporary'.
|
12 |
-
*
|
13 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/398
|
14 |
-
*/
|
15 |
-
function setUp() {
|
16 |
-
parent::setUp();
|
17 |
-
|
18 |
-
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
19 |
-
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
20 |
-
}
|
21 |
-
|
22 |
-
/**
|
23 |
-
* On author pages, the queried object should only be set
|
24 |
-
* to a user that's not a member of the blog if they
|
25 |
-
* have at least one published post. This matches core behavior.
|
26 |
-
*
|
27 |
-
* @see https://core.trac.wordpress.org/changeset/27290
|
28 |
-
*/
|
29 |
-
function test__author_queried_object_fix() {
|
30 |
-
global $wp_rewrite, $coauthors_plus;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* Set up
|
34 |
-
*/
|
35 |
-
$author1 = $this->factory->user->create( array( 'user_login' => 'msauthor1' ) );
|
36 |
-
$author2 = $this->factory->user->create( array( 'user_login' => 'msauthor2' ) );
|
37 |
-
$blog2 = $this->factory->blog->create( array( 'user_id' => $author1 ) );
|
38 |
-
|
39 |
-
switch_to_blog( $blog2 );
|
40 |
-
$wp_rewrite->init();
|
41 |
-
|
42 |
-
$blog2_post1 = $this->factory->post->create( array(
|
43 |
-
'post_status' => 'publish',
|
44 |
-
'post_content' => rand_str(),
|
45 |
-
'post_title' => rand_str(),
|
46 |
-
'post_author' => $author1,
|
47 |
-
) );
|
48 |
-
|
49 |
-
/**
|
50 |
-
* Author 1 is an author on the blog
|
51 |
-
*/
|
52 |
-
$this->go_to( get_author_posts_url( $author1 ) );
|
53 |
-
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
54 |
-
|
55 |
-
// Add the user to the blog
|
56 |
-
add_user_to_blog( $blog2, $author2, 'author' );
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Author 2 is now on the blog, but not yet published
|
60 |
-
*/
|
61 |
-
$this->go_to( get_author_posts_url( $author2 ) );
|
62 |
-
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
63 |
-
|
64 |
-
// Add the user as an author on the original post
|
65 |
-
$author2_obj = get_user_by( 'id', $author2 );
|
66 |
-
$coauthors_plus->add_coauthors( $blog2_post1, array( $author2_obj->user_login ), true );
|
67 |
-
|
68 |
-
/**
|
69 |
-
* Author 2 is now on the blog, and published
|
70 |
-
*/
|
71 |
-
$this->go_to( get_author_posts_url( $author2 ) );
|
72 |
-
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
73 |
-
|
74 |
-
// Remove the user from the blog
|
75 |
-
remove_user_from_blog( $author2, $blog2 );
|
76 |
-
|
77 |
-
/**
|
78 |
-
* Author 2 was removed from the blog, but still a published author
|
79 |
-
*/
|
80 |
-
$this->go_to( get_author_posts_url( $author2 ) );
|
81 |
-
$this->assertQueryTrue( 'is_author', 'is_archive' );
|
82 |
-
|
83 |
-
// Delete the user from the network
|
84 |
-
wpmu_delete_user( $author2 );
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Author 2 is no more
|
88 |
-
*/
|
89 |
-
$this->go_to( get_author_posts_url( $author2 ) );
|
90 |
-
$this->assertEquals( false, get_user_by( 'id', $author2 ) );
|
91 |
-
|
92 |
-
restore_current_blog();
|
93 |
-
|
94 |
-
}
|
95 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test-author-queries.php
DELETED
@@ -1,129 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Test_Author_Queries extends CoAuthorsPlus_TestCase {
|
4 |
-
|
5 |
-
public function test__author_arg__user_is_post_author() {
|
6 |
-
$author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
7 |
-
$author = get_userdata( $author_id );
|
8 |
-
$post_id = $this->factory->post->create( array(
|
9 |
-
'post_author' => $author_id,
|
10 |
-
'post_status' => 'publish',
|
11 |
-
'post_type' => 'post',
|
12 |
-
) );
|
13 |
-
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );
|
14 |
-
|
15 |
-
$query = new WP_Query( array(
|
16 |
-
'author' => $author_id,
|
17 |
-
) );
|
18 |
-
|
19 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
20 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
21 |
-
}
|
22 |
-
|
23 |
-
public function test__author_name_arg__user_is_post_author() {
|
24 |
-
$author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
25 |
-
$author = get_userdata( $author_id );
|
26 |
-
$post_id = $this->factory->post->create( array(
|
27 |
-
'post_author' => $author_id,
|
28 |
-
'post_status' => 'publish',
|
29 |
-
'post_type' => 'post',
|
30 |
-
) );
|
31 |
-
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );
|
32 |
-
|
33 |
-
$query = new WP_Query( array(
|
34 |
-
'author_name' => $author->user_login,
|
35 |
-
) );
|
36 |
-
|
37 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
38 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
39 |
-
}
|
40 |
-
|
41 |
-
public function test__author_name_arg__user_is_coauthor() {
|
42 |
-
$author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
43 |
-
$author1 = get_userdata( $author1_id );
|
44 |
-
$author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) );
|
45 |
-
$author2 = get_userdata( $author2_id );
|
46 |
-
|
47 |
-
$post_id = $this->factory->post->create( array(
|
48 |
-
'post_author' => $author1_id,
|
49 |
-
'post_status' => 'publish',
|
50 |
-
'post_type' => 'post',
|
51 |
-
) );
|
52 |
-
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );
|
53 |
-
|
54 |
-
$query = new WP_Query( array(
|
55 |
-
'author_name' => $author2->user_login,
|
56 |
-
) );
|
57 |
-
|
58 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
59 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
60 |
-
}
|
61 |
-
|
62 |
-
public function test__author_arg__user_is_coauthor__author_arg() {
|
63 |
-
return; // TODO: re-enable; fails currently because WordPress generates query as `post_author IN (id)` which doesn't match our regex in the posts_where filter.
|
64 |
-
|
65 |
-
$author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
66 |
-
$author1 = get_userdata( $author1_id );
|
67 |
-
$author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) );
|
68 |
-
$author2 = get_userdata( $author2_id );
|
69 |
-
|
70 |
-
$post_id = $this->factory->post->create( array(
|
71 |
-
'post_author' => $author1_id,
|
72 |
-
'post_status' => 'publish',
|
73 |
-
'post_type' => 'post',
|
74 |
-
) );
|
75 |
-
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );
|
76 |
-
|
77 |
-
$query = new WP_Query( array(
|
78 |
-
'author' => $author2_id,
|
79 |
-
) );
|
80 |
-
|
81 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
82 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
83 |
-
}
|
84 |
-
|
85 |
-
public function test__author_name_arg_plus_tax_query__user_is_post_author() {
|
86 |
-
$author_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
87 |
-
$author = get_userdata( $author_id );
|
88 |
-
$post_id = $this->factory->post->create( array(
|
89 |
-
'post_author' => $author_id,
|
90 |
-
'post_status' => 'publish',
|
91 |
-
'post_type' => 'post',
|
92 |
-
) );
|
93 |
-
$this->_cap->add_coauthors( $post_id, array( $author->user_login ) );
|
94 |
-
wp_set_post_terms( $post_id, 'test', 'post_tag' );
|
95 |
-
|
96 |
-
$query = new WP_Query( array(
|
97 |
-
'author_name' => $author->user_login,
|
98 |
-
'tag' => 'test',
|
99 |
-
) );
|
100 |
-
|
101 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
102 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
103 |
-
}
|
104 |
-
|
105 |
-
public function tests__author_name_arg_plus_tax_query__is_coauthor() {
|
106 |
-
return; // TODO: re-enable; fails currently because our posts_join_filter doesn't add an exclusive JOIN on relationships + taxonomy to match the query mods we make. We'd need aliased JOINs on relationships + taxonomy on top of the JOIN that the tax query already adds.
|
107 |
-
|
108 |
-
$author1_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'batman' ) );
|
109 |
-
$author1 = get_userdata( $author1_id );
|
110 |
-
$author2_id = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'superman' ) );
|
111 |
-
$author2 = get_userdata( $author2_id );
|
112 |
-
|
113 |
-
$post_id = $this->factory->post->create( array(
|
114 |
-
'post_author' => $author1_id,
|
115 |
-
'post_status' => 'publish',
|
116 |
-
'post_type' => 'post',
|
117 |
-
) );
|
118 |
-
$this->_cap->add_coauthors( $post_id, array( $author1->user_login, $author2->user_login ) );
|
119 |
-
wp_set_post_terms( $post_id, 'test', 'post_tag' );
|
120 |
-
|
121 |
-
$query = new WP_Query( array(
|
122 |
-
'author_name' => $author2->user_login,
|
123 |
-
'tag' => 'test',
|
124 |
-
) );
|
125 |
-
|
126 |
-
$this->assertEquals( 1, count( $query->posts ) );
|
127 |
-
$this->assertEquals( $post_id, $query->posts[ 0 ]->ID );
|
128 |
-
}
|
129 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test-coauthors-guest-authors.php
DELETED
@@ -1,890 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Test_CoAuthors_Guest_Authors extends CoAuthorsPlus_TestCase {
|
4 |
-
|
5 |
-
public function setUp() {
|
6 |
-
|
7 |
-
parent::setUp();
|
8 |
-
|
9 |
-
$this->admin1 = $this->factory->user->create_and_get( array( 'role' => 'administrator', 'user_login' => 'admin1' ) );
|
10 |
-
$this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) );
|
11 |
-
$this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) );
|
12 |
-
|
13 |
-
$this->post = $this->factory->post->create_and_get( array(
|
14 |
-
'post_author' => $this->author1->ID,
|
15 |
-
'post_status' => 'publish',
|
16 |
-
'post_content' => rand_str(),
|
17 |
-
'post_title' => rand_str(),
|
18 |
-
'post_type' => 'post',
|
19 |
-
) );
|
20 |
-
}
|
21 |
-
|
22 |
-
/**
|
23 |
-
* Checks a simulated WP_User object based on the post ID when key or value is empty.
|
24 |
-
*
|
25 |
-
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
26 |
-
*/
|
27 |
-
public function test_get_guest_author_by_with_empty_key_or_value() {
|
28 |
-
|
29 |
-
global $coauthors_plus;
|
30 |
-
|
31 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
32 |
-
|
33 |
-
// Fetch guest author without forcefully.
|
34 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', '' ) );
|
35 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '' ) );
|
36 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID ) );
|
37 |
-
|
38 |
-
// Fetch guest author forcefully.
|
39 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', '', true ) );
|
40 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', '', true ) );
|
41 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( '', $this->author1->ID, true ) );
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Checks a simulated WP_User object based on the post ID using cache.
|
46 |
-
*
|
47 |
-
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
48 |
-
*/
|
49 |
-
public function test_get_guest_author_by_using_cache() {
|
50 |
-
|
51 |
-
global $coauthors_plus;
|
52 |
-
|
53 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
54 |
-
|
55 |
-
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
56 |
-
|
57 |
-
$cache_key = $guest_author_obj->get_cache_key( 'ID', $guest_author_id );
|
58 |
-
|
59 |
-
// Checks when guest author does not exist in cache.
|
60 |
-
$this->assertFalse( wp_cache_get( $cache_key, $guest_author_obj::$cache_group ) );
|
61 |
-
|
62 |
-
// Checks when guest author exists in cache.
|
63 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
64 |
-
$guest_author_cached = wp_cache_get( $cache_key, $guest_author_obj::$cache_group );
|
65 |
-
|
66 |
-
$this->assertInstanceOf( stdClass::class, $guest_author );
|
67 |
-
$this->assertEquals( $guest_author, $guest_author_cached );
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Checks a simulated WP_User object based on the post ID using different key/value.
|
72 |
-
*
|
73 |
-
* @covers CoAuthors_Guest_Authors::get_guest_author_by()
|
74 |
-
*/
|
75 |
-
public function test_get_guest_author_by_with_different_keys() {
|
76 |
-
|
77 |
-
global $coauthors_plus;
|
78 |
-
|
79 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
80 |
-
|
81 |
-
// Checks when user is not a guest author.
|
82 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID ) );
|
83 |
-
$this->assertFalse( $guest_author_obj->get_guest_author_by( 'ID', $this->author1->ID, true ) );
|
84 |
-
|
85 |
-
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
86 |
-
|
87 |
-
// Checks guest author using ID.
|
88 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
89 |
-
|
90 |
-
$this->assertInstanceOf( stdClass::class, $guest_author );
|
91 |
-
$this->assertEquals( $guest_author_id, $guest_author->ID );
|
92 |
-
$this->assertEquals( $guest_author_obj->post_type, $guest_author->type );
|
93 |
-
|
94 |
-
// Checks guest author using user_nicename.
|
95 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'user_nicename', $this->editor1->user_nicename );
|
96 |
-
|
97 |
-
$this->assertInstanceOf( stdClass::class, $guest_author );
|
98 |
-
$this->assertEquals( $guest_author_obj->post_type, $guest_author->type );
|
99 |
-
|
100 |
-
// Checks guest author using linked_account.
|
101 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'linked_account', $this->editor1->user_login );
|
102 |
-
|
103 |
-
$this->assertInstanceOf( stdClass::class, $guest_author );
|
104 |
-
$this->assertEquals( $guest_author_obj->post_type, $guest_author->type );
|
105 |
-
}
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Checks thumbnail for a guest author object.
|
109 |
-
*
|
110 |
-
* @covers CoAuthors_Guest_Authors::get_guest_author_thumbnail()
|
111 |
-
*/
|
112 |
-
public function test_get_guest_author_thumbnail() {
|
113 |
-
|
114 |
-
global $coauthors_plus;
|
115 |
-
|
116 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
117 |
-
|
118 |
-
// Checks when guest author does not have any thumbnail.
|
119 |
-
$guest_author_id = $guest_author_obj->create( array(
|
120 |
-
'user_login' => 'author2',
|
121 |
-
'display_name' => 'author2',
|
122 |
-
) );
|
123 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
124 |
-
|
125 |
-
$this->assertNull( $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 ) );
|
126 |
-
|
127 |
-
// Checks when guest author has thumbnail.
|
128 |
-
$filename = rand_str() . '.jpg';
|
129 |
-
$contents = rand_str();
|
130 |
-
$upload = wp_upload_bits( $filename, null, $contents );
|
131 |
-
|
132 |
-
$this->assertTrue( empty( $upload['error'] ) );
|
133 |
-
|
134 |
-
$attachment_id = $this->_make_attachment( $upload );
|
135 |
-
|
136 |
-
set_post_thumbnail( $guest_author->ID, $attachment_id );
|
137 |
-
|
138 |
-
$thumbnail = $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 );
|
139 |
-
|
140 |
-
$this->assertContains( 'avatar-0', $thumbnail );
|
141 |
-
$this->assertContains( $filename, $thumbnail );
|
142 |
-
$this->assertContains( 'src="' . wp_get_attachment_url( $attachment_id ) . '"', $thumbnail );
|
143 |
-
}
|
144 |
-
|
145 |
-
/**
|
146 |
-
* Checks all of the meta fields that can be associated with a guest author.
|
147 |
-
*
|
148 |
-
* @covers CoAuthors_Guest_Authors::get_guest_author_fields()
|
149 |
-
*/
|
150 |
-
public function test_get_guest_author_fields() {
|
151 |
-
|
152 |
-
global $coauthors_plus;
|
153 |
-
|
154 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
155 |
-
|
156 |
-
// Checks all the meta fields.
|
157 |
-
$fields = $guest_author_obj->get_guest_author_fields();
|
158 |
-
|
159 |
-
$this->assertNotEmpty( $fields );
|
160 |
-
$this->assertInternalType( 'array', $fields );
|
161 |
-
|
162 |
-
$keys = wp_list_pluck( $fields, 'key' );
|
163 |
-
|
164 |
-
$global_fields = array(
|
165 |
-
'display_name',
|
166 |
-
'first_name',
|
167 |
-
'last_name',
|
168 |
-
'user_login',
|
169 |
-
'user_email',
|
170 |
-
'linked_account',
|
171 |
-
'website',
|
172 |
-
'aim',
|
173 |
-
'yahooim',
|
174 |
-
'jabber',
|
175 |
-
'description',
|
176 |
-
);
|
177 |
-
|
178 |
-
$this->assertEquals( $global_fields, $keys );
|
179 |
-
|
180 |
-
// Checks all the meta fields with group that does not exist.
|
181 |
-
$fields = $guest_author_obj->get_guest_author_fields( 'test' );
|
182 |
-
|
183 |
-
$this->assertEmpty( $fields );
|
184 |
-
|
185 |
-
// Checks all the meta fields with group "name".
|
186 |
-
$fields = $guest_author_obj->get_guest_author_fields( 'name' );
|
187 |
-
$keys = wp_list_pluck( $fields, 'key' );
|
188 |
-
|
189 |
-
$this->assertEquals( array( 'display_name', 'first_name', 'last_name' ), $keys );
|
190 |
-
|
191 |
-
// Checks all the meta fields with group "slug".
|
192 |
-
$fields = $guest_author_obj->get_guest_author_fields( 'slug' );
|
193 |
-
$keys = wp_list_pluck( $fields, 'key' );
|
194 |
-
|
195 |
-
$this->assertEquals( array( 'user_login', 'linked_account' ), $keys );
|
196 |
-
|
197 |
-
// Checks all the meta fields with group "contact-info".
|
198 |
-
$fields = $guest_author_obj->get_guest_author_fields( 'contact-info' );
|
199 |
-
$keys = wp_list_pluck( $fields, 'key' );
|
200 |
-
|
201 |
-
$this->assertEquals( array( 'user_email', 'website', 'aim', 'yahooim', 'jabber' ), $keys );
|
202 |
-
|
203 |
-
// Checks all the meta fields with group "about".
|
204 |
-
$fields = $guest_author_obj->get_guest_author_fields( 'about' );
|
205 |
-
$keys = wp_list_pluck( $fields, 'key' );
|
206 |
-
|
207 |
-
$this->assertEquals( array( 'description' ), $keys );
|
208 |
-
}
|
209 |
-
|
210 |
-
/**
|
211 |
-
* Checks all of the user accounts that have been linked.
|
212 |
-
*
|
213 |
-
* @covers CoAuthors_Guest_Authors::get_all_linked_accounts()
|
214 |
-
*/
|
215 |
-
public function test_get_all_linked_accounts() {
|
216 |
-
|
217 |
-
global $coauthors_plus;
|
218 |
-
|
219 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
220 |
-
|
221 |
-
$this->assertEmpty( $guest_author_obj->get_all_linked_accounts() );
|
222 |
-
|
223 |
-
// Checks when guest author ( not linked account ) exists.
|
224 |
-
$guest_author_obj->create( array(
|
225 |
-
'user_login' => 'author2',
|
226 |
-
'display_name' => 'author2',
|
227 |
-
) );
|
228 |
-
|
229 |
-
$this->assertEmpty( $guest_author_obj->get_all_linked_accounts() );
|
230 |
-
|
231 |
-
// Create guest author from existing user and check.
|
232 |
-
$guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
233 |
-
|
234 |
-
$linked_accounts = $guest_author_obj->get_all_linked_accounts();
|
235 |
-
$linked_account_ids = wp_list_pluck( $linked_accounts, 'ID' );
|
236 |
-
|
237 |
-
$this->assertNotEmpty( $linked_accounts );
|
238 |
-
$this->assertInternalType( 'array', $linked_accounts );
|
239 |
-
$this->assertTrue( in_array( $this->editor1->ID, $linked_account_ids, true ) );
|
240 |
-
}
|
241 |
-
|
242 |
-
/**
|
243 |
-
* Checks all of the user accounts that have been linked using cache.
|
244 |
-
*
|
245 |
-
* @covers CoAuthors_Guest_Authors::get_all_linked_accounts()
|
246 |
-
*/
|
247 |
-
public function test_get_all_linked_accounts_with_cache() {
|
248 |
-
|
249 |
-
global $coauthors_plus;
|
250 |
-
|
251 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
252 |
-
|
253 |
-
$cache_key = 'all-linked-accounts';
|
254 |
-
|
255 |
-
// Checks when guest author does not exist in cache.
|
256 |
-
$this->assertFalse( wp_cache_get( $cache_key, $guest_author_obj::$cache_group ) );
|
257 |
-
|
258 |
-
// Checks when guest author exists in cache.
|
259 |
-
$guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
260 |
-
|
261 |
-
$linked_accounts = $guest_author_obj->get_all_linked_accounts();
|
262 |
-
$linked_accounts_cache = wp_cache_get( $cache_key, $guest_author_obj::$cache_group );
|
263 |
-
|
264 |
-
$this->assertEquals( $linked_accounts, $linked_accounts_cache );
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Checks guest author from an existing WordPress user.
|
269 |
-
*
|
270 |
-
* @covers CoAuthors_Guest_Authors::create_guest_author_from_user_id()
|
271 |
-
*/
|
272 |
-
public function test_create_guest_author_from_user_id() {
|
273 |
-
|
274 |
-
global $coauthors_plus;
|
275 |
-
|
276 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
277 |
-
|
278 |
-
// Checks create guest author when user don't exist.
|
279 |
-
$response = $guest_author_obj->create_guest_author_from_user_id( 0 );
|
280 |
-
|
281 |
-
$this->assertInstanceOf( 'WP_Error', $response );
|
282 |
-
$this->assertEquals( 'invalid-user', $response->get_error_code() );
|
283 |
-
|
284 |
-
// Checks create guest author when user exist.
|
285 |
-
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
286 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
287 |
-
|
288 |
-
$this->assertInstanceOf( stdClass::class, $guest_author );
|
289 |
-
}
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Checks delete guest author action when $_POST args are not set.
|
293 |
-
*
|
294 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
295 |
-
*/
|
296 |
-
public function test_handle_delete_guest_author_action_when_post_args_not_as_expected() {
|
297 |
-
|
298 |
-
global $coauthors_plus;
|
299 |
-
|
300 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
301 |
-
|
302 |
-
// Checks when nothing is set.
|
303 |
-
$this->assertNull( $guest_author_obj->handle_delete_guest_author_action() );
|
304 |
-
|
305 |
-
// Back up $_POST.
|
306 |
-
$_post_backup = $_POST;
|
307 |
-
|
308 |
-
// Checks when action is set but not expected.
|
309 |
-
$_POST['action'] = 'test';
|
310 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
311 |
-
|
312 |
-
$this->assertNull( $guest_author_obj->handle_delete_guest_author_action() );
|
313 |
-
|
314 |
-
// Get guest author and check that is should not be removed.
|
315 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] );
|
316 |
-
|
317 |
-
$this->assertNotEmpty( $guest_author );
|
318 |
-
|
319 |
-
// Checks when _wpnonce and id not set.
|
320 |
-
$_POST['action'] = 'delete-guest-author';
|
321 |
-
$_POST['reassign'] = 'test';
|
322 |
-
|
323 |
-
$this->assertNull( $guest_author_obj->handle_delete_guest_author_action() );
|
324 |
-
|
325 |
-
// Get guest author and check that is should not be removed.
|
326 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] );
|
327 |
-
|
328 |
-
$this->assertNotEmpty( $guest_author );
|
329 |
-
|
330 |
-
// Checks when all args set for $_POST but action is not as expected.
|
331 |
-
$_POST['action'] = 'test';
|
332 |
-
$_POST['reassign'] = 'test';
|
333 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' );
|
334 |
-
|
335 |
-
$this->assertNull( $guest_author_obj->handle_delete_guest_author_action() );
|
336 |
-
|
337 |
-
// Get guest author and check that is should not be removed.
|
338 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $_POST['id'] );
|
339 |
-
|
340 |
-
$this->assertNotEmpty( $guest_author );
|
341 |
-
|
342 |
-
// Restore $_POST from back up.
|
343 |
-
$_POST = $_post_backup;
|
344 |
-
}
|
345 |
-
|
346 |
-
/**
|
347 |
-
* Checks delete guest author action with nonce.
|
348 |
-
*
|
349 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
350 |
-
*/
|
351 |
-
public function test_handle_delete_guest_author_action_with_nonce() {
|
352 |
-
|
353 |
-
global $coauthors_plus;
|
354 |
-
|
355 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
356 |
-
|
357 |
-
// Back up $_POST.
|
358 |
-
$_post_backup = $_POST;
|
359 |
-
|
360 |
-
$expected = __( "Doin' something fishy, huh?", 'co-authors-plus' );
|
361 |
-
|
362 |
-
$_POST['action'] = 'delete-guest-author';
|
363 |
-
$_POST['reassign'] = 'test';
|
364 |
-
$_POST['id'] = '0';
|
365 |
-
|
366 |
-
// Checks when nonce is not as expected.
|
367 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author-1' );
|
368 |
-
|
369 |
-
try {
|
370 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
371 |
-
} catch ( Exception $e ) {
|
372 |
-
$exception = $e;
|
373 |
-
}
|
374 |
-
|
375 |
-
$this->assertInstanceOf( 'WPDieException', $exception );
|
376 |
-
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
|
377 |
-
|
378 |
-
// Checks when nonce is as expected.
|
379 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
380 |
-
|
381 |
-
try {
|
382 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
383 |
-
} catch ( Exception $e ) {
|
384 |
-
$exception = $e;
|
385 |
-
}
|
386 |
-
|
387 |
-
$this->assertNotContains( esc_html( $expected ), $exception->getMessage() );
|
388 |
-
|
389 |
-
// Restore $_POST from back up.
|
390 |
-
$_POST = $_post_backup;
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
* Checks delete guest author action with list_author capability.
|
395 |
-
*
|
396 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
397 |
-
*/
|
398 |
-
public function test_handle_delete_guest_author_action_with_list_users_capability() {
|
399 |
-
|
400 |
-
global $coauthors_plus;
|
401 |
-
|
402 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
403 |
-
|
404 |
-
// Back up $_POST.
|
405 |
-
$_post_backup = $_POST;
|
406 |
-
|
407 |
-
$expected = __( "You don't have permission to perform this action.", 'co-authors-plus' );
|
408 |
-
|
409 |
-
// Back up current user.
|
410 |
-
$current_user = get_current_user_id();
|
411 |
-
|
412 |
-
wp_set_current_user( $this->editor1->ID );
|
413 |
-
|
414 |
-
$_POST['action'] = 'delete-guest-author';
|
415 |
-
$_POST['reassign'] = 'test';
|
416 |
-
|
417 |
-
// Checks when current user can not have list_users capability.
|
418 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
419 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->editor1->ID );
|
420 |
-
|
421 |
-
try {
|
422 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
423 |
-
} catch ( Exception $e ) {
|
424 |
-
$exception = $e;
|
425 |
-
}
|
426 |
-
|
427 |
-
$this->assertInstanceOf( 'WPDieException', $exception );
|
428 |
-
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
|
429 |
-
|
430 |
-
// Checks when current user has list_users capability.
|
431 |
-
wp_set_current_user( $this->admin1->ID );
|
432 |
-
|
433 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
434 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
435 |
-
|
436 |
-
try {
|
437 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
438 |
-
} catch ( Exception $e ) {
|
439 |
-
$exception = $e;
|
440 |
-
}
|
441 |
-
|
442 |
-
$this->assertNotContains( esc_html( $expected ), $exception->getMessage() );
|
443 |
-
|
444 |
-
// Restore current user from backup.
|
445 |
-
wp_set_current_user( $current_user );
|
446 |
-
|
447 |
-
// Restore $_POST from back up.
|
448 |
-
$_POST = $_post_backup;
|
449 |
-
}
|
450 |
-
|
451 |
-
/**
|
452 |
-
* Checks delete guest author action with guest author.
|
453 |
-
*
|
454 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
455 |
-
*/
|
456 |
-
public function test_handle_delete_guest_author_action_with_guest_author_existence() {
|
457 |
-
|
458 |
-
global $coauthors_plus;
|
459 |
-
|
460 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
461 |
-
|
462 |
-
// Back up $_POST.
|
463 |
-
$_post_backup = $_POST;
|
464 |
-
|
465 |
-
$expected = sprintf( __( "%s can't be deleted because it doesn't exist.", 'co-authors-plus' ), $guest_author_obj->labels['singular'] );
|
466 |
-
|
467 |
-
// Back up current user.
|
468 |
-
$current_user = get_current_user_id();
|
469 |
-
|
470 |
-
wp_set_current_user( $this->admin1->ID );
|
471 |
-
|
472 |
-
$_POST['action'] = 'delete-guest-author';
|
473 |
-
$_POST['reassign'] = 'test';
|
474 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
475 |
-
$_POST['id'] = $this->admin1->ID;
|
476 |
-
|
477 |
-
// Checks when guest author does not exist.
|
478 |
-
try {
|
479 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
480 |
-
} catch ( Exception $e ) {
|
481 |
-
$exception = $e;
|
482 |
-
}
|
483 |
-
|
484 |
-
$this->assertInstanceOf( 'WPDieException', $exception );
|
485 |
-
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
|
486 |
-
|
487 |
-
// Checks when guest author exists.
|
488 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
489 |
-
|
490 |
-
try {
|
491 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
492 |
-
} catch ( Exception $e ) {
|
493 |
-
$exception = $e;
|
494 |
-
}
|
495 |
-
|
496 |
-
$this->assertNotContains( esc_html( $expected ), $exception->getMessage() );
|
497 |
-
|
498 |
-
// Restore current user from backup.
|
499 |
-
wp_set_current_user( $current_user );
|
500 |
-
|
501 |
-
// Restore $_POST from back up.
|
502 |
-
$_POST = $_post_backup;
|
503 |
-
}
|
504 |
-
|
505 |
-
/**
|
506 |
-
* Checks delete guest author action with reassign not as expected.
|
507 |
-
*
|
508 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
509 |
-
*/
|
510 |
-
public function test_handle_delete_guest_author_action_with_reassign_not_as_expected() {
|
511 |
-
|
512 |
-
global $coauthors_plus;
|
513 |
-
|
514 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
515 |
-
|
516 |
-
// Back up $_POST.
|
517 |
-
$_post_backup = $_POST;
|
518 |
-
|
519 |
-
$expected = __( 'Please make sure to pick an option.', 'co-authors-plus' );
|
520 |
-
|
521 |
-
// Back up current user.
|
522 |
-
$current_user = get_current_user_id();
|
523 |
-
|
524 |
-
wp_set_current_user( $this->admin1->ID );
|
525 |
-
|
526 |
-
$_POST['action'] = 'delete-guest-author';
|
527 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
528 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
529 |
-
|
530 |
-
// Checks when reassign is not as expected.
|
531 |
-
$_POST['reassign'] = 'test';
|
532 |
-
|
533 |
-
try {
|
534 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
535 |
-
} catch ( Exception $e ) {
|
536 |
-
$exception = $e;
|
537 |
-
}
|
538 |
-
|
539 |
-
$this->assertInstanceOf( 'WPDieException', $exception );
|
540 |
-
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
|
541 |
-
|
542 |
-
// Restore current user from backup.
|
543 |
-
wp_set_current_user( $current_user );
|
544 |
-
|
545 |
-
// Restore $_POST from back up.
|
546 |
-
$_POST = $_post_backup;
|
547 |
-
}
|
548 |
-
|
549 |
-
/**
|
550 |
-
* Checks delete guest author action when reassign is leave-assigned.
|
551 |
-
*
|
552 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
553 |
-
*/
|
554 |
-
public function test_handle_delete_guest_author_action_with_reassign_is_leave_assigned() {
|
555 |
-
|
556 |
-
global $coauthors_plus;
|
557 |
-
|
558 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
559 |
-
|
560 |
-
// Back up $_POST.
|
561 |
-
$_post_backup = $_POST;
|
562 |
-
|
563 |
-
// Back up current user.
|
564 |
-
$current_user = get_current_user_id();
|
565 |
-
|
566 |
-
wp_set_current_user( $this->admin1->ID );
|
567 |
-
|
568 |
-
$_POST['action'] = 'delete-guest-author';
|
569 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
570 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
571 |
-
$_POST['reassign'] = 'leave-assigned';
|
572 |
-
|
573 |
-
add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 );
|
574 |
-
|
575 |
-
try {
|
576 |
-
|
577 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
578 |
-
|
579 |
-
} catch( Exception $e ) {
|
580 |
-
|
581 |
-
$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
|
582 |
-
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
|
583 |
-
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
|
584 |
-
}
|
585 |
-
|
586 |
-
remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
|
587 |
-
|
588 |
-
// Restore current user from backup.
|
589 |
-
wp_set_current_user( $current_user );
|
590 |
-
|
591 |
-
// Restore $_POST from back up.
|
592 |
-
$_POST = $_post_backup;
|
593 |
-
}
|
594 |
-
|
595 |
-
/**
|
596 |
-
* Checks delete guest author action when reassign is reassign-another.
|
597 |
-
*
|
598 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
599 |
-
*/
|
600 |
-
public function test_handle_delete_guest_author_action_with_reassign_is_reassign_another() {
|
601 |
-
|
602 |
-
global $coauthors_plus;
|
603 |
-
|
604 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
605 |
-
|
606 |
-
// Back up $_POST.
|
607 |
-
$_post_backup = $_POST;
|
608 |
-
|
609 |
-
// Back up current user.
|
610 |
-
$current_user = get_current_user_id();
|
611 |
-
|
612 |
-
$expected = __( 'Co-author does not exists. Try again?', 'co-authors-plus' );
|
613 |
-
|
614 |
-
wp_set_current_user( $this->admin1->ID );
|
615 |
-
|
616 |
-
$_POST['action'] = 'delete-guest-author';
|
617 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
618 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
619 |
-
$_POST['reassign'] = 'reassign-another';
|
620 |
-
|
621 |
-
// When coauthor does not exist.
|
622 |
-
$_POST['leave-assigned-to'] = 'test';
|
623 |
-
|
624 |
-
try {
|
625 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
626 |
-
} catch ( Exception $e ) {
|
627 |
-
$exception = $e;
|
628 |
-
}
|
629 |
-
|
630 |
-
$this->assertInstanceOf( 'WPDieException', $exception );
|
631 |
-
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
|
632 |
-
|
633 |
-
// When coauthor exists.
|
634 |
-
$_POST['leave-assigned-to'] = $this->author1->user_nicename;
|
635 |
-
|
636 |
-
add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 );
|
637 |
-
|
638 |
-
try {
|
639 |
-
|
640 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
641 |
-
|
642 |
-
} catch ( Exception $e ) {
|
643 |
-
|
644 |
-
//$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
|
645 |
-
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
|
646 |
-
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
|
647 |
-
}
|
648 |
-
|
649 |
-
remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
|
650 |
-
|
651 |
-
// Restore current user from backup.
|
652 |
-
wp_set_current_user( $current_user );
|
653 |
-
|
654 |
-
// Restore $_POST from back up.
|
655 |
-
$_POST = $_post_backup;
|
656 |
-
}
|
657 |
-
|
658 |
-
/**
|
659 |
-
* Checks delete guest author action when reassign is remove-byline.
|
660 |
-
*
|
661 |
-
* @covers CoAuthors_Guest_Authors::handle_delete_guest_author_action()
|
662 |
-
*/
|
663 |
-
public function test_handle_delete_guest_author_action_with_reassign_is_remove_byline() {
|
664 |
-
|
665 |
-
global $coauthors_plus;
|
666 |
-
|
667 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
668 |
-
|
669 |
-
// Back up $_POST.
|
670 |
-
$_post_backup = $_POST;
|
671 |
-
|
672 |
-
// Back up current user.
|
673 |
-
$current_user = get_current_user_id();
|
674 |
-
|
675 |
-
wp_set_current_user( $this->admin1->ID );
|
676 |
-
|
677 |
-
$_POST['action'] = 'delete-guest-author';
|
678 |
-
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
|
679 |
-
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
680 |
-
$_POST['reassign'] = 'remove-byline';
|
681 |
-
|
682 |
-
add_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99, 2 );
|
683 |
-
|
684 |
-
try {
|
685 |
-
|
686 |
-
$guest_author_obj->handle_delete_guest_author_action();
|
687 |
-
|
688 |
-
} catch ( Exception $e ) {
|
689 |
-
|
690 |
-
$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
|
691 |
-
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
|
692 |
-
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
|
693 |
-
}
|
694 |
-
|
695 |
-
remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
|
696 |
-
|
697 |
-
// Restore current user from backup.
|
698 |
-
wp_set_current_user( $current_user );
|
699 |
-
|
700 |
-
// Restore $_POST from back up.
|
701 |
-
$_POST = $_post_backup;
|
702 |
-
}
|
703 |
-
|
704 |
-
/**
|
705 |
-
* To catch any redirection and throw location and status in Exception.
|
706 |
-
*
|
707 |
-
* Note : Destination location can be get from Exception Message and
|
708 |
-
* status can be get from Exception code.
|
709 |
-
*
|
710 |
-
* @param string $location Redirected location.
|
711 |
-
* @param int $status Status.
|
712 |
-
*
|
713 |
-
* @throws \Exception Redirection data.
|
714 |
-
*
|
715 |
-
* @return void
|
716 |
-
**/
|
717 |
-
public function catch_redirect_destination( $location, $status ) {
|
718 |
-
|
719 |
-
throw new Exception( $location, $status );
|
720 |
-
}
|
721 |
-
|
722 |
-
/**
|
723 |
-
* Checks delete guest author when he/she does not exist.
|
724 |
-
*
|
725 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
726 |
-
*/
|
727 |
-
public function test_delete_when_guest_author_not_exist() {
|
728 |
-
|
729 |
-
global $coauthors_plus;
|
730 |
-
|
731 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
732 |
-
|
733 |
-
$response = $guest_author_obj->delete( $this->admin1->ID );
|
734 |
-
|
735 |
-
$this->assertInstanceOf( 'WP_Error', $response );
|
736 |
-
$this->assertEquals( 'guest-author-missing', $response->get_error_code() );
|
737 |
-
}
|
738 |
-
|
739 |
-
/**
|
740 |
-
* Checks delete guest author without reassign author.
|
741 |
-
*
|
742 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
743 |
-
*/
|
744 |
-
public function test_delete_without_reassign() {
|
745 |
-
|
746 |
-
global $coauthors_plus;
|
747 |
-
|
748 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
749 |
-
|
750 |
-
$author2 = $this->factory->user->create_and_get();
|
751 |
-
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID );
|
752 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
753 |
-
$guest_author_term = $coauthors_plus->get_author_term( $guest_author );
|
754 |
-
|
755 |
-
$response = $guest_author_obj->delete( $guest_author_id );
|
756 |
-
|
757 |
-
$this->assertTrue( $response );
|
758 |
-
$this->assertFalse( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) );
|
759 |
-
$this->assertNull( get_post( $guest_author_id ) );
|
760 |
-
}
|
761 |
-
|
762 |
-
/**
|
763 |
-
* Checks delete guest author with reassign author but he/she does not exist.
|
764 |
-
*
|
765 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
766 |
-
*/
|
767 |
-
public function test_delete_with_reassign_author_not_exist() {
|
768 |
-
|
769 |
-
global $coauthors_plus;
|
770 |
-
|
771 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
772 |
-
|
773 |
-
// Checks when reassign author is not exist.
|
774 |
-
$author2 = $this->factory->user->create_and_get();
|
775 |
-
$guest_author_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID );
|
776 |
-
|
777 |
-
$response = $guest_author_obj->delete( $guest_author_id, 'test' );
|
778 |
-
|
779 |
-
$this->assertInstanceOf( 'WP_Error', $response );
|
780 |
-
$this->assertEquals( 'reassign-to-missing', $response->get_error_code() );
|
781 |
-
}
|
782 |
-
|
783 |
-
/**
|
784 |
-
* Checks delete guest author with reassign author when linked account and author are same user.
|
785 |
-
*
|
786 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
787 |
-
*/
|
788 |
-
public function test_delete_with_reassign_when_linked_account_and_author_are_same_user() {
|
789 |
-
|
790 |
-
global $coauthors_plus;
|
791 |
-
|
792 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
793 |
-
|
794 |
-
$author2 = $this->factory->user->create_and_get();
|
795 |
-
$guest_author2_id = $guest_author_obj->create_guest_author_from_user_id( $author2->ID );
|
796 |
-
$guest_author2 = $guest_author_obj->get_guest_author_by( 'ID', $guest_author2_id );
|
797 |
-
$guest_author2_term = $coauthors_plus->get_author_term( $guest_author2 );
|
798 |
-
|
799 |
-
$response = $guest_author_obj->delete( $guest_author2_id, $guest_author2->linked_account );
|
800 |
-
|
801 |
-
$this->assertTrue( $response );
|
802 |
-
$this->assertNotEmpty( get_term_by( 'id', $guest_author2_term->term_id, $coauthors_plus->coauthor_taxonomy ) );
|
803 |
-
$this->assertNull( get_post( $guest_author2_id ) );
|
804 |
-
}
|
805 |
-
|
806 |
-
/**
|
807 |
-
* Checks delete guest author with reassign author when linked account and author are different user.
|
808 |
-
*
|
809 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
810 |
-
*/
|
811 |
-
public function test_delete_with_reassign_when_linked_account_and_author_are_different_user() {
|
812 |
-
|
813 |
-
global $coauthors_plus;
|
814 |
-
|
815 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
816 |
-
|
817 |
-
$guest_admin_id = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
818 |
-
$guest_admin = $guest_author_obj->get_guest_author_by( 'ID', $guest_admin_id );
|
819 |
-
|
820 |
-
$author2 = $this->factory->user->create_and_get();
|
821 |
-
$guest_author_id2 = $guest_author_obj->create_guest_author_from_user_id( $author2->ID );
|
822 |
-
$guest_author2 = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id2 );
|
823 |
-
$guest_author_term2 = $coauthors_plus->get_author_term( $guest_author2 );
|
824 |
-
|
825 |
-
$post = $this->factory->post->create_and_get( array(
|
826 |
-
'post_author' => $author2->ID,
|
827 |
-
) );
|
828 |
-
|
829 |
-
$response = $guest_author_obj->delete( $guest_author_id2, $guest_admin->linked_account );
|
830 |
-
|
831 |
-
// Checks post author, it should be reassigned to new author.
|
832 |
-
$this->assertEquals( array( $guest_admin->linked_account ), wp_list_pluck( get_coauthors( $post->ID ), 'linked_account' ) );
|
833 |
-
$this->assertTrue( $response );
|
834 |
-
$this->assertFalse( get_term_by( 'id', $guest_author_term2->term_id, $coauthors_plus->coauthor_taxonomy ) );
|
835 |
-
$this->assertNull( get_post( $guest_author_id2 ) );
|
836 |
-
}
|
837 |
-
|
838 |
-
/**
|
839 |
-
* Checks delete guest author with reassign author and without linked account and author is the same user.
|
840 |
-
*
|
841 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
842 |
-
*/
|
843 |
-
public function test_delete_with_reassign_without_linked_account_and_author_is_same_user() {
|
844 |
-
|
845 |
-
global $coauthors_plus;
|
846 |
-
|
847 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
848 |
-
|
849 |
-
$guest_author_id = $guest_author_obj->create( array(
|
850 |
-
'user_login' => 'guest_author',
|
851 |
-
'display_name' => 'guest_author',
|
852 |
-
) );
|
853 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
854 |
-
$guest_author_term = $coauthors_plus->get_author_term( $guest_author );
|
855 |
-
|
856 |
-
$response = $guest_author_obj->delete( $guest_author_id, $guest_author->user_login );
|
857 |
-
|
858 |
-
$this->assertTrue( $response );
|
859 |
-
$this->assertNotEmpty( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) );
|
860 |
-
$this->assertNull( get_post( $guest_author_id ) );
|
861 |
-
}
|
862 |
-
|
863 |
-
/**
|
864 |
-
* Checks delete guest author with reassign author and without linked account and author is other user.
|
865 |
-
*
|
866 |
-
* @covers CoAuthors_Guest_Authors::delete()
|
867 |
-
*/
|
868 |
-
public function test_delete_with_reassign_without_linked_account_and_author_is_other_user() {
|
869 |
-
|
870 |
-
global $coauthors_plus;
|
871 |
-
|
872 |
-
$guest_author_obj = $coauthors_plus->guest_authors;
|
873 |
-
|
874 |
-
$guest_admin_id = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
|
875 |
-
$guest_admin = $guest_author_obj->get_guest_author_by( 'ID', $guest_admin_id );
|
876 |
-
|
877 |
-
$guest_author_id = $guest_author_obj->create( array(
|
878 |
-
'user_login' => 'guest_author',
|
879 |
-
'display_name' => 'guest_author',
|
880 |
-
) );
|
881 |
-
$guest_author = $guest_author_obj->get_guest_author_by( 'ID', $guest_author_id );
|
882 |
-
$guest_author_term = $coauthors_plus->get_author_term( $guest_author );
|
883 |
-
|
884 |
-
$response = $guest_author_obj->delete( $guest_author_id, $guest_admin->user_login );
|
885 |
-
|
886 |
-
$this->assertTrue( $response );
|
887 |
-
$this->assertFalse( get_term_by( 'id', $guest_author_term->term_id, $coauthors_plus->coauthor_taxonomy ) );
|
888 |
-
$this->assertNull( get_post( $guest_author_id ) );
|
889 |
-
}
|
890 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test-coauthors-plus.php
DELETED
@@ -1,679 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase {
|
4 |
-
|
5 |
-
public function setUp() {
|
6 |
-
|
7 |
-
parent::setUp();
|
8 |
-
|
9 |
-
$this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) );
|
10 |
-
$this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) );
|
11 |
-
|
12 |
-
$this->post = $this->factory->post->create_and_get( array(
|
13 |
-
'post_author' => $this->author1->ID,
|
14 |
-
'post_status' => 'publish',
|
15 |
-
'post_content' => rand_str(),
|
16 |
-
'post_title' => rand_str(),
|
17 |
-
'post_type' => 'post',
|
18 |
-
) );
|
19 |
-
}
|
20 |
-
|
21 |
-
/**
|
22 |
-
* Checks whether the guest authors functionality is enabled or not.
|
23 |
-
*
|
24 |
-
* @covers CoAuthors_Plus::is_guest_authors_enabled()
|
25 |
-
*/
|
26 |
-
public function test_is_guest_authors_enabled() {
|
27 |
-
|
28 |
-
global $coauthors_plus;
|
29 |
-
|
30 |
-
$this->assertTrue( $coauthors_plus->is_guest_authors_enabled() );
|
31 |
-
|
32 |
-
add_filter( 'coauthors_guest_authors_enabled', '__return_false' );
|
33 |
-
|
34 |
-
$this->assertFalse( $coauthors_plus->is_guest_authors_enabled() );
|
35 |
-
|
36 |
-
remove_filter( 'coauthors_guest_authors_enabled', '__return_false' );
|
37 |
-
|
38 |
-
$this->assertTrue( $coauthors_plus->is_guest_authors_enabled() );
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Checks coauthor object when he/she is a guest author.
|
43 |
-
*
|
44 |
-
* @covers CoAuthors_Plus::get_coauthor_by()
|
45 |
-
*/
|
46 |
-
public function test_get_coauthor_by_when_guest_author() {
|
47 |
-
|
48 |
-
global $coauthors_plus;
|
49 |
-
|
50 |
-
$guest_author_id = $coauthors_plus->guest_authors->create( array(
|
51 |
-
'user_login' => 'author2',
|
52 |
-
'display_name' => 'author2',
|
53 |
-
) );
|
54 |
-
|
55 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'id', $guest_author_id );
|
56 |
-
|
57 |
-
$this->assertInstanceOf( stdClass::class, $coauthor );
|
58 |
-
$this->assertObjectHasAttribute( 'ID', $coauthor );
|
59 |
-
$this->assertEquals( $guest_author_id, $coauthor->ID );
|
60 |
-
$this->assertEquals( 'guest-author', $coauthor->type );
|
61 |
-
}
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Checks coauthor object when he/she is a wp author.
|
65 |
-
*
|
66 |
-
* @covers CoAuthors_Plus::get_coauthor_by()
|
67 |
-
*/
|
68 |
-
public function test_get_coauthor_by_when_guest_authors_not_enabled() {
|
69 |
-
|
70 |
-
global $coauthors_plus;
|
71 |
-
|
72 |
-
add_filter( 'coauthors_guest_authors_enabled', '__return_false' );
|
73 |
-
|
74 |
-
$this->assertFalse( $coauthors_plus->get_coauthor_by( '', '' ) );
|
75 |
-
|
76 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->author1->ID );
|
77 |
-
|
78 |
-
$this->assertInstanceOf( WP_User::class, $coauthor );
|
79 |
-
$this->assertObjectHasAttribute( 'ID', $coauthor );
|
80 |
-
$this->assertEquals( $this->author1->ID, $coauthor->ID );
|
81 |
-
$this->assertEquals( 'wpuser', $coauthor->type );
|
82 |
-
|
83 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'user_login', $this->author1->user_login );
|
84 |
-
|
85 |
-
$this->assertInstanceOf( WP_User::class, $coauthor );
|
86 |
-
$this->assertObjectHasAttribute( 'user_login', $coauthor->data );
|
87 |
-
$this->assertEquals( $this->author1->user_login, $coauthor->user_login );
|
88 |
-
|
89 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'user_nicename', $this->author1->user_nicename );
|
90 |
-
|
91 |
-
$this->assertInstanceOf( WP_User::class, $coauthor );
|
92 |
-
$this->assertObjectHasAttribute( 'user_nicename', $coauthor->data );
|
93 |
-
$this->assertEquals( $this->author1->user_nicename, $coauthor->user_nicename );
|
94 |
-
|
95 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'user_email', $this->author1->user_email );
|
96 |
-
|
97 |
-
$this->assertInstanceOf( WP_User::class, $coauthor );
|
98 |
-
$this->assertObjectHasAttribute( 'user_email', $coauthor->data );
|
99 |
-
$this->assertEquals( $this->author1->user_email, $coauthor->user_email );
|
100 |
-
|
101 |
-
remove_filter( 'coauthors_guest_authors_enabled', '__return_false' );
|
102 |
-
|
103 |
-
$coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1->ID );
|
104 |
-
|
105 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'id', $this->editor1->ID );
|
106 |
-
|
107 |
-
$this->assertInstanceOf( stdClass::class, $coauthor );
|
108 |
-
$this->assertObjectHasAttribute( 'linked_account', $coauthor );
|
109 |
-
$this->assertEquals( $this->editor1->user_login, $coauthor->linked_account );
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Checks coauthors plus is enabled for this post type.
|
114 |
-
*
|
115 |
-
* @covers CoAuthors_Plus::is_post_type_enabled()
|
116 |
-
*/
|
117 |
-
public function test_is_post_type_enabled() {
|
118 |
-
|
119 |
-
global $coauthors_plus, $post;
|
120 |
-
|
121 |
-
// Backing up global post.
|
122 |
-
$post_backup = $post;
|
123 |
-
|
124 |
-
// Checks when post type is null.
|
125 |
-
$this->assertFalse( $coauthors_plus->is_post_type_enabled() );
|
126 |
-
|
127 |
-
// Checks when post type is post.
|
128 |
-
$this->assertTrue( $coauthors_plus->is_post_type_enabled( 'post' ) );
|
129 |
-
|
130 |
-
// Checks when post type is page.
|
131 |
-
$this->assertTrue( $coauthors_plus->is_post_type_enabled( 'page' ) );
|
132 |
-
|
133 |
-
// Checks when post type is attachment.
|
134 |
-
$this->assertFalse( $coauthors_plus->is_post_type_enabled( 'attachment' ) );
|
135 |
-
|
136 |
-
// Checks when post type is revision.
|
137 |
-
$this->assertFalse( $coauthors_plus->is_post_type_enabled( 'revision' ) );
|
138 |
-
|
139 |
-
$post = $this->post;
|
140 |
-
|
141 |
-
// Checks when post type set using global post.
|
142 |
-
$this->assertTrue( $coauthors_plus->is_post_type_enabled() );
|
143 |
-
|
144 |
-
$post = '';
|
145 |
-
$screen = get_current_screen();
|
146 |
-
|
147 |
-
// Set the edit post current screen.
|
148 |
-
set_current_screen( 'edit-post' );
|
149 |
-
$this->assertTrue( $coauthors_plus->is_post_type_enabled() );
|
150 |
-
|
151 |
-
$GLOBALS['current_screen'] = $screen;
|
152 |
-
|
153 |
-
// Restore global post from backup.
|
154 |
-
$post = $post_backup;
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Checks if the current user can set co-authors or not using current screen.
|
159 |
-
*
|
160 |
-
* @covers CoAuthors_Plus::current_user_can_set_authors()
|
161 |
-
*/
|
162 |
-
public function test_current_user_can_set_authors_using_current_screen() {
|
163 |
-
|
164 |
-
global $coauthors_plus;
|
165 |
-
|
166 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
167 |
-
|
168 |
-
$screen = get_current_screen();
|
169 |
-
|
170 |
-
// Set the edit post current screen.
|
171 |
-
set_current_screen( 'edit-post' );
|
172 |
-
|
173 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
174 |
-
|
175 |
-
$GLOBALS['current_screen'] = $screen;
|
176 |
-
|
177 |
-
// Backing up current user.
|
178 |
-
$current_user = get_current_user_id();
|
179 |
-
|
180 |
-
// Checks when current user is author.
|
181 |
-
wp_set_current_user( $this->author1->ID );
|
182 |
-
|
183 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
184 |
-
|
185 |
-
set_current_screen( 'edit-post' );
|
186 |
-
|
187 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
188 |
-
|
189 |
-
$GLOBALS['current_screen'] = $screen;
|
190 |
-
|
191 |
-
// Checks when current user is editor.
|
192 |
-
wp_set_current_user( $this->editor1->ID );
|
193 |
-
|
194 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
195 |
-
|
196 |
-
set_current_screen( 'edit-post' );
|
197 |
-
|
198 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors() );
|
199 |
-
|
200 |
-
$GLOBALS['current_screen'] = $screen;
|
201 |
-
|
202 |
-
// Checks when current user is admin.
|
203 |
-
$admin1 = $this->factory->user->create_and_get( array(
|
204 |
-
'role' => 'administrator',
|
205 |
-
) );
|
206 |
-
|
207 |
-
wp_set_current_user( $admin1->ID );
|
208 |
-
|
209 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
210 |
-
|
211 |
-
set_current_screen( 'edit-post' );
|
212 |
-
|
213 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors() );
|
214 |
-
|
215 |
-
$GLOBALS['current_screen'] = $screen;
|
216 |
-
|
217 |
-
// Restore current user from backup.
|
218 |
-
wp_set_current_user( $current_user );
|
219 |
-
}
|
220 |
-
|
221 |
-
/**
|
222 |
-
* Checks if the current user can set co-authors or not using global post.
|
223 |
-
*
|
224 |
-
* @covers CoAuthors_Plus::current_user_can_set_authors()
|
225 |
-
*/
|
226 |
-
public function test_current_user_can_set_authors_using_global_post() {
|
227 |
-
|
228 |
-
global $coauthors_plus, $post;
|
229 |
-
|
230 |
-
// Backing up global post.
|
231 |
-
$post_backup = $post;
|
232 |
-
|
233 |
-
$post = $this->post;
|
234 |
-
|
235 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
236 |
-
|
237 |
-
// Backing up current user.
|
238 |
-
$current_user = get_current_user_id();
|
239 |
-
|
240 |
-
// Checks when current user is author.
|
241 |
-
wp_set_current_user( $this->author1->ID );
|
242 |
-
|
243 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors() );
|
244 |
-
|
245 |
-
// Checks when current user is editor.
|
246 |
-
wp_set_current_user( $this->editor1->ID );
|
247 |
-
|
248 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors() );
|
249 |
-
|
250 |
-
// Checks when current user is super admin.
|
251 |
-
$admin1 = $this->factory->user->create_and_get( array(
|
252 |
-
'role' => 'administrator',
|
253 |
-
) );
|
254 |
-
|
255 |
-
grant_super_admin( $admin1->ID );
|
256 |
-
wp_set_current_user( $admin1->ID );
|
257 |
-
|
258 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors() );
|
259 |
-
|
260 |
-
// Restore current user from backup.
|
261 |
-
wp_set_current_user( $current_user );
|
262 |
-
|
263 |
-
// Restore global post from backup.
|
264 |
-
$post = $post_backup;
|
265 |
-
}
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Checks if the current user can set co-authors or not using normal post.
|
269 |
-
*
|
270 |
-
* @covers CoAuthors_Plus::current_user_can_set_authors()
|
271 |
-
*/
|
272 |
-
public function test_current_user_can_set_authors_using_normal_post() {
|
273 |
-
|
274 |
-
global $coauthors_plus;
|
275 |
-
|
276 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
277 |
-
|
278 |
-
// Backing up current user.
|
279 |
-
$current_user = get_current_user_id();
|
280 |
-
|
281 |
-
// Checks when current user is author.
|
282 |
-
wp_set_current_user( $this->author1->ID );
|
283 |
-
|
284 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
285 |
-
|
286 |
-
// Checks when current user is editor.
|
287 |
-
wp_set_current_user( $this->editor1->ID );
|
288 |
-
|
289 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
290 |
-
|
291 |
-
// Checks when current user is super admin.
|
292 |
-
$admin1 = $this->factory->user->create_and_get( array(
|
293 |
-
'role' => 'administrator',
|
294 |
-
) );
|
295 |
-
|
296 |
-
grant_super_admin( $admin1->ID );
|
297 |
-
wp_set_current_user( $admin1->ID );
|
298 |
-
|
299 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
300 |
-
|
301 |
-
// Restore current user from backup.
|
302 |
-
wp_set_current_user( $current_user );
|
303 |
-
}
|
304 |
-
|
305 |
-
/**
|
306 |
-
* Checks if the current user can set co-authors or not using coauthors_plus_edit_authors filter.
|
307 |
-
*
|
308 |
-
* @covers CoAuthors_Plus::current_user_can_set_authors()
|
309 |
-
*/
|
310 |
-
public function test_current_user_can_set_authors_using_coauthors_plus_edit_authors_filter() {
|
311 |
-
|
312 |
-
global $coauthors_plus;
|
313 |
-
|
314 |
-
// Backing up current user.
|
315 |
-
$current_user = get_current_user_id();
|
316 |
-
|
317 |
-
// Checking when current user is subscriber and filter is true/false.
|
318 |
-
$subscriber1 = $this->factory->user->create_and_get( array(
|
319 |
-
'role' => 'subscriber',
|
320 |
-
) );
|
321 |
-
|
322 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
323 |
-
|
324 |
-
add_filter( 'coauthors_plus_edit_authors', '__return_true' );
|
325 |
-
|
326 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
327 |
-
|
328 |
-
remove_filter( 'coauthors_plus_edit_authors', '__return_true' );
|
329 |
-
|
330 |
-
// Checks when current user is editor.
|
331 |
-
wp_set_current_user( $this->editor1->ID );
|
332 |
-
|
333 |
-
$this->assertTrue( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
334 |
-
|
335 |
-
add_filter( 'coauthors_plus_edit_authors', '__return_false' );
|
336 |
-
|
337 |
-
$this->assertFalse( $coauthors_plus->current_user_can_set_authors( $this->post ) );
|
338 |
-
|
339 |
-
remove_filter( 'coauthors_plus_edit_authors', '__return_false' );
|
340 |
-
|
341 |
-
// Restore current user from backup.
|
342 |
-
wp_set_current_user( $current_user );
|
343 |
-
}
|
344 |
-
|
345 |
-
/**
|
346 |
-
* Checks matching co-authors based on a search value when no arguments provided.
|
347 |
-
*
|
348 |
-
* @covers CoAuthors_Plus::search_authors()
|
349 |
-
*/
|
350 |
-
public function test_search_authors_no_args() {
|
351 |
-
|
352 |
-
global $coauthors_plus;
|
353 |
-
|
354 |
-
// Checks when search term is empty.
|
355 |
-
$authors = $coauthors_plus->search_authors();
|
356 |
-
|
357 |
-
$this->assertNotEmpty( $authors );
|
358 |
-
$this->assertArrayHasKey( 'admin', $authors );
|
359 |
-
$this->assertArrayHasKey( $this->author1->user_login, $authors );
|
360 |
-
$this->assertArrayHasKey( $this->editor1->user_login, $authors );
|
361 |
-
|
362 |
-
// Checks when search term is empty and any subscriber exists.
|
363 |
-
$subscriber1 = $this->factory->user->create_and_get( array(
|
364 |
-
'role' => 'subscriber',
|
365 |
-
) );
|
366 |
-
|
367 |
-
$authors = $coauthors_plus->search_authors();
|
368 |
-
|
369 |
-
$this->assertNotEmpty( $authors );
|
370 |
-
$this->assertNotContains( $subscriber1->user_login, $authors );
|
371 |
-
|
372 |
-
// Checks when search term is empty and any contributor exists.
|
373 |
-
$contributor1 = $this->factory->user->create_and_get( array(
|
374 |
-
'role' => 'contributor',
|
375 |
-
) );
|
376 |
-
|
377 |
-
$authors = $coauthors_plus->search_authors();
|
378 |
-
|
379 |
-
$this->assertNotEmpty( $authors );
|
380 |
-
$this->assertArrayHasKey( $contributor1->user_login, $authors );
|
381 |
-
}
|
382 |
-
|
383 |
-
/**
|
384 |
-
* Checks matching co-authors based on a search value when only search keyword is provided.
|
385 |
-
*
|
386 |
-
* @covers CoAuthors_Plus::search_authors()
|
387 |
-
*/
|
388 |
-
public function test_search_authors_when_search_keyword_provided() {
|
389 |
-
|
390 |
-
global $coauthors_plus;
|
391 |
-
|
392 |
-
// Checks when author does not exist with searched term.
|
393 |
-
$this->assertEmpty( $coauthors_plus->search_authors( 'test' ) );
|
394 |
-
|
395 |
-
// Checks when author searched using ID.
|
396 |
-
$authors = $coauthors_plus->search_authors( $this->author1->ID );
|
397 |
-
|
398 |
-
$this->assertNotEmpty( $authors );
|
399 |
-
$this->assertArrayHasKey( $this->author1->user_login, $authors );
|
400 |
-
$this->assertNotContains( $this->editor1->user_login, $authors );
|
401 |
-
$this->assertNotContains( 'admin', $authors );
|
402 |
-
|
403 |
-
// Checks when author searched using display_name.
|
404 |
-
$authors = $coauthors_plus->search_authors( $this->author1->display_name );
|
405 |
-
|
406 |
-
$this->assertNotEmpty( $authors );
|
407 |
-
$this->assertArrayHasKey( $this->author1->user_login, $authors );
|
408 |
-
$this->assertNotContains( $this->editor1->user_login, $authors );
|
409 |
-
$this->assertNotContains( 'admin', $authors );
|
410 |
-
|
411 |
-
// Checks when author searched using user_email.
|
412 |
-
$authors = $coauthors_plus->search_authors( $this->author1->user_email );
|
413 |
-
|
414 |
-
$this->assertNotEmpty( $authors );
|
415 |
-
$this->assertArrayHasKey( $this->author1->user_login, $authors );
|
416 |
-
$this->assertNotContains( $this->editor1->user_login, $authors );
|
417 |
-
$this->assertNotContains( 'admin', $authors );
|
418 |
-
|
419 |
-
// Checks when author searched using user_login.
|
420 |
-
$authors = $coauthors_plus->search_authors( $this->author1->user_login );
|
421 |
-
|
422 |
-
$this->assertNotEmpty( $authors );
|
423 |
-
$this->assertArrayHasKey( $this->author1->user_login, $authors );
|
424 |
-
$this->assertNotContains( $this->editor1->user_login, $authors );
|
425 |
-
$this->assertNotContains( 'admin', $authors );
|
426 |
-
|
427 |
-
// Checks when any subscriber exists using ID but not author.
|
428 |
-
$subscriber1 = $this->factory->user->create_and_get( array(
|
429 |
-
'role' => 'subscriber',
|
430 |
-
) );
|
431 |
-
|
432 |
-
$this->assertEmpty( $coauthors_plus->search_authors( $subscriber1->ID ) );
|
433 |
-
}
|
434 |
-
|
435 |
-
/**
|
436 |
-
* Checks matching co-authors based on a search value when only ignore authors are provided.
|
437 |
-
*
|
438 |
-
* @covers CoAuthors_Plus::search_authors()
|
439 |
-
*/
|
440 |
-
public function test_search_authors_when_ignored_authors_provided() {
|
441 |
-
|
442 |
-
global $coauthors_plus;
|
443 |
-
|
444 |
-
// Ignoring single author.
|
445 |
-
$ignored_authors = array( $this->author1->user_login );
|
446 |
-
|
447 |
-
$authors = $coauthors_plus->search_authors( '', $ignored_authors );
|
448 |
-
|
449 |
-
$this->assertNotEmpty( $authors );
|
450 |
-
$this->assertNotContains( $this->author1->user_login, $authors );
|
451 |
-
|
452 |
-
// Checks when ignoring author1 but also exists one more author with similar kind of data.
|
453 |
-
$author2 = $this->factory->user->create_and_get( array(
|
454 |
-
'role' => 'author',
|
455 |
-
) );
|
456 |
-
|
457 |
-
$authors = $coauthors_plus->search_authors( '', $ignored_authors );
|
458 |
-
|
459 |
-
$this->assertNotEmpty( $authors );
|
460 |
-
$this->assertNotContains( $this->author1->user_login, $authors );
|
461 |
-
$this->assertArrayHasKey( $author2->user_login, $authors );
|
462 |
-
|
463 |
-
// Ignoring multiple authors.
|
464 |
-
$authors = $coauthors_plus->search_authors( '', array( $this->author1->user_login, $author2->user_login ) );
|
465 |
-
|
466 |
-
$this->assertNotEmpty( $authors );
|
467 |
-
$this->assertNotContains( $this->author1->user_login, $authors );
|
468 |
-
$this->assertNotContains( $author2->user_login, $authors );
|
469 |
-
}
|
470 |
-
|
471 |
-
/**
|
472 |
-
* Checks matching co-authors based on a search value when search keyword as well as ignore authors are provided.
|
473 |
-
*
|
474 |
-
* @covers CoAuthors_Plus::search_authors()
|
475 |
-
*/
|
476 |
-
public function test_search_authors_when_search_keyword_and_ignored_authors_provided() {
|
477 |
-
|
478 |
-
global $coauthors_plus;
|
479 |
-
|
480 |
-
// Checks when ignoring author1.
|
481 |
-
$ignored_authors = array( $this->author1->user_login );
|
482 |
-
|
483 |
-
$this->assertEmpty( $coauthors_plus->search_authors( $this->author1->ID, $ignored_authors ) );
|
484 |
-
|
485 |
-
// Checks when ignoring author1 but also exists one more author with similar kind of data.
|
486 |
-
$author2 = $this->factory->user->create_and_get( array(
|
487 |
-
'role' => 'author',
|
488 |
-
'user_login' => 'author2',
|
489 |
-
) );
|
490 |
-
|
491 |
-
$authors = $coauthors_plus->search_authors( 'author', $ignored_authors );
|
492 |
-
|
493 |
-
$this->assertNotEmpty( $authors );
|
494 |
-
$this->assertNotContains( $this->author1->user_login, $authors );
|
495 |
-
$this->assertArrayHasKey( $author2->user_login, $authors );
|
496 |
-
}
|
497 |
-
|
498 |
-
/**
|
499 |
-
* Checks the author term for a given co-author when passed coauthor is not an object.
|
500 |
-
*
|
501 |
-
* @covers CoAuthors_Plus::get_author_term()
|
502 |
-
*/
|
503 |
-
public function test_get_author_term_when_coauthor_is_not_object() {
|
504 |
-
|
505 |
-
global $coauthors_plus;
|
506 |
-
|
507 |
-
$this->assertEmpty( $coauthors_plus->get_author_term( '' ) );
|
508 |
-
$this->assertEmpty( $coauthors_plus->get_author_term( $this->author1->ID ) );
|
509 |
-
$this->assertEmpty( $coauthors_plus->get_author_term( (array) $this->author1 ) );
|
510 |
-
}
|
511 |
-
|
512 |
-
/**
|
513 |
-
* Checks the author term for a given co-author using cache.
|
514 |
-
*
|
515 |
-
* @covers CoAuthors_Plus::get_author_term()
|
516 |
-
*/
|
517 |
-
public function test_get_author_term_using_caching() {
|
518 |
-
|
519 |
-
global $coauthors_plus;
|
520 |
-
|
521 |
-
$cache_key = 'author-term-' . $this->author1->user_nicename;
|
522 |
-
|
523 |
-
// Checks when term does not exist in cache.
|
524 |
-
$this->assertFalse( wp_cache_get( $cache_key, 'co-authors-plus' ) );
|
525 |
-
|
526 |
-
// Checks when term exists in cache.
|
527 |
-
$author_term = $coauthors_plus->get_author_term( $this->author1 );
|
528 |
-
$author_term_cached = wp_cache_get( $cache_key, 'co-authors-plus' );
|
529 |
-
|
530 |
-
$this->assertInstanceOf( WP_Term::class, $author_term );
|
531 |
-
$this->assertEquals( $author_term, $author_term_cached );
|
532 |
-
}
|
533 |
-
|
534 |
-
/**
|
535 |
-
* Checks the author term for a given co-author with having linked account.
|
536 |
-
*
|
537 |
-
* @covers CoAuthors_Plus::get_author_term()
|
538 |
-
*/
|
539 |
-
public function test_get_author_term_when_author_has_linked_account() {
|
540 |
-
|
541 |
-
global $coauthors_plus;
|
542 |
-
|
543 |
-
// Checks when term exists using linked account.
|
544 |
-
$coauthor_id = $coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->editor1->ID );
|
545 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'id', $coauthor_id );
|
546 |
-
|
547 |
-
$author_term = $coauthors_plus->get_author_term( $coauthor );
|
548 |
-
|
549 |
-
$this->assertInstanceOf( WP_Term::class, $author_term );
|
550 |
-
|
551 |
-
// Checks when term does not exist or deleted somehow.
|
552 |
-
wp_delete_term( $author_term->term_id, $author_term->taxonomy );
|
553 |
-
|
554 |
-
$this->assertFalse( $coauthors_plus->get_author_term( $coauthor ) );
|
555 |
-
}
|
556 |
-
|
557 |
-
/**
|
558 |
-
* Checks the author term for a given co-author without having linked account.
|
559 |
-
*
|
560 |
-
* @covers CoAuthors_Plus::get_author_term()
|
561 |
-
*/
|
562 |
-
public function test_get_author_term_when_author_has_not_linked_account() {
|
563 |
-
|
564 |
-
global $coauthors_plus;
|
565 |
-
|
566 |
-
// Checks when term exists without linked account.
|
567 |
-
$coauthor_id = $coauthors_plus->guest_authors->create( array(
|
568 |
-
'display_name' => 'guest',
|
569 |
-
'user_login' => 'guest',
|
570 |
-
) );
|
571 |
-
$coauthor = $coauthors_plus->get_coauthor_by( 'id', $coauthor_id );
|
572 |
-
|
573 |
-
$author_term = $coauthors_plus->get_author_term( $coauthor );
|
574 |
-
|
575 |
-
$this->assertInstanceOf( WP_Term::class, $author_term );
|
576 |
-
|
577 |
-
// Checks when term does not exist or deleted somehow.
|
578 |
-
wp_delete_term( $author_term->term_id, $author_term->taxonomy );
|
579 |
-
|
580 |
-
$this->assertFalse( $coauthors_plus->get_author_term( $coauthor ) );
|
581 |
-
}
|
582 |
-
|
583 |
-
/**
|
584 |
-
* Checks update author term when passed coauthor is not an object.
|
585 |
-
*
|
586 |
-
* @covers CoAuthors_Plus::update_author_term()
|
587 |
-
*/
|
588 |
-
public function test_update_author_term_when_coauthor_is_not_object() {
|
589 |
-
|
590 |
-
global $coauthors_plus;
|
591 |
-
|
592 |
-
$this->assertEmpty( $coauthors_plus->update_author_term( '' ) );
|
593 |
-
$this->assertEmpty( $coauthors_plus->update_author_term( $this->author1->ID ) );
|
594 |
-
$this->assertEmpty( $coauthors_plus->update_author_term( (array) $this->author1 ) );
|
595 |
-
}
|
596 |
-
|
597 |
-
/**
|
598 |
-
* Checks update author term when author term exists for passed coauthor.
|
599 |
-
*
|
600 |
-
* @covers CoAuthors_Plus::update_author_term()
|
601 |
-
*/
|
602 |
-
public function test_update_author_term_when_author_term_exists() {
|
603 |
-
|
604 |
-
global $coauthors_plus;
|
605 |
-
|
606 |
-
// Checks term description.
|
607 |
-
$author_term = $coauthors_plus->update_author_term( $this->author1 );
|
608 |
-
|
609 |
-
// In "update_author_term()", only description is being updated, so asserting that only ( here and everywhere ).
|
610 |
-
$this->assertEquals( $this->author1->display_name . ' ' . $this->author1->first_name . ' ' . $this->author1->last_name . ' ' . $this->author1->user_login . ' ' . $this->author1->ID . ' ' . $this->author1->user_email, $author_term->description );
|
611 |
-
|
612 |
-
// Checks term description after updating user.
|
613 |
-
wp_update_user( array(
|
614 |
-
'ID' => $this->author1->ID,
|
615 |
-
'first_name' => 'author1',
|
616 |
-
) );
|
617 |
-
|
618 |
-
$author_term = $coauthors_plus->update_author_term( $this->author1 );
|
619 |
-
|
620 |
-
$this->assertEquals( $this->author1->display_name . ' ' . $this->author1->first_name . ' ' . $this->author1->last_name . ' ' . $this->author1->user_login . ' ' . $this->author1->ID . ' ' . $this->author1->user_email, $author_term->description );
|
621 |
-
|
622 |
-
// Backup coauthor taxonomy.
|
623 |
-
$taxonomy_backup = $coauthors_plus->coauthor_taxonomy;
|
624 |
-
|
625 |
-
wp_update_user( array(
|
626 |
-
'ID' => $this->author1->ID,
|
627 |
-
'last_name' => 'author1',
|
628 |
-
) );
|
629 |
-
|
630 |
-
// Checks with different taxonomy.
|
631 |
-
$coauthors_plus->coauthor_taxonomy = 'abcd';
|
632 |
-
|
633 |
-
$this->assertFalse( $coauthors_plus->update_author_term( $this->author1 ) );
|
634 |
-
|
635 |
-
// Restore coauthor taxonomy from backup.
|
636 |
-
$coauthors_plus->coauthor_taxonomy = $taxonomy_backup;
|
637 |
-
}
|
638 |
-
|
639 |
-
/**
|
640 |
-
* Checks update author term when author term does not exist for passed coauthor.
|
641 |
-
*
|
642 |
-
* @covers CoAuthors_Plus::update_author_term()
|
643 |
-
*/
|
644 |
-
public function test_update_author_term_when_author_term_not_exist() {
|
645 |
-
|
646 |
-
global $coauthors_plus;
|
647 |
-
|
648 |
-
// Checks term description.
|
649 |
-
$author_term = $coauthors_plus->update_author_term( $this->editor1 );
|
650 |
-
|
651 |
-
$this->assertEquals( $this->editor1->display_name . ' ' . $this->editor1->first_name . ' ' . $this->editor1->last_name . ' ' . $this->editor1->user_login . ' ' . $this->editor1->ID . ' ' . $this->editor1->user_email, $author_term->description );
|
652 |
-
|
653 |
-
// Checks term description after updating user.
|
654 |
-
wp_update_user( array(
|
655 |
-
'ID' => $this->editor1->ID,
|
656 |
-
'first_name' => 'editor1',
|
657 |
-
) );
|
658 |
-
|
659 |
-
$author_term = $coauthors_plus->update_author_term( $this->editor1 );
|
660 |
-
|
661 |
-
$this->assertEquals( $this->editor1->display_name . ' ' . $this->editor1->first_name . ' ' . $this->editor1->last_name . ' ' . $this->editor1->user_login . ' ' . $this->editor1->ID . ' ' . $this->editor1->user_email, $author_term->description );
|
662 |
-
|
663 |
-
// Backup coauthor taxonomy.
|
664 |
-
$taxonomy_backup = $coauthors_plus->coauthor_taxonomy;
|
665 |
-
|
666 |
-
wp_update_user( array(
|
667 |
-
'ID' => $this->editor1->ID,
|
668 |
-
'last_name' => 'editor1',
|
669 |
-
) );
|
670 |
-
|
671 |
-
// Checks with different taxonomy.
|
672 |
-
$coauthors_plus->coauthor_taxonomy = 'abcd';
|
673 |
-
|
674 |
-
$this->assertFalse( $coauthors_plus->update_author_term( $this->editor1 ) );
|
675 |
-
|
676 |
-
// Restore coauthor taxonomy from backup.
|
677 |
-
$coauthors_plus->coauthor_taxonomy = $taxonomy_backup;
|
678 |
-
}
|
679 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test-manage-coauthors.php
DELETED
@@ -1,428 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class Test_Manage_CoAuthors extends CoAuthorsPlus_TestCase {
|
4 |
-
|
5 |
-
public function setUp() {
|
6 |
-
parent::setUp();
|
7 |
-
|
8 |
-
$this->admin1 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'admin1' ) );
|
9 |
-
$this->author1 = $this->factory->user->create( array( 'role' => 'author', 'user_login' => 'author1' ) );
|
10 |
-
$this->editor1 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor2' ) );
|
11 |
-
|
12 |
-
$post = array(
|
13 |
-
'post_author' => $this->author1,
|
14 |
-
'post_status' => 'publish',
|
15 |
-
'post_content' => rand_str(),
|
16 |
-
'post_title' => rand_str(),
|
17 |
-
'post_type' => 'post',
|
18 |
-
);
|
19 |
-
|
20 |
-
$this->author1_post1 = wp_insert_post( $post );
|
21 |
-
|
22 |
-
$post = array(
|
23 |
-
'post_author' => $this->author1,
|
24 |
-
'post_status' => 'publish',
|
25 |
-
'post_content' => rand_str(),
|
26 |
-
'post_title' => rand_str(),
|
27 |
-
'post_type' => 'post',
|
28 |
-
);
|
29 |
-
|
30 |
-
$this->author1_post2 = wp_insert_post( $post );
|
31 |
-
|
32 |
-
$page = array(
|
33 |
-
'post_author' => $this->author1,
|
34 |
-
'post_status' => 'publish',
|
35 |
-
'post_content' => rand_str(),
|
36 |
-
'post_title' => rand_str(),
|
37 |
-
'post_type' => 'page',
|
38 |
-
);
|
39 |
-
|
40 |
-
$this->author1_page1 = wp_insert_post( $page );
|
41 |
-
|
42 |
-
$page = array(
|
43 |
-
'post_author' => $this->author1,
|
44 |
-
'post_status' => 'publish',
|
45 |
-
'post_content' => rand_str(),
|
46 |
-
'post_title' => rand_str(),
|
47 |
-
'post_type' => 'page',
|
48 |
-
);
|
49 |
-
|
50 |
-
$this->author1_page2 = wp_insert_post( $page );
|
51 |
-
}
|
52 |
-
|
53 |
-
public function tearDown() {
|
54 |
-
parent::tearDown();
|
55 |
-
}
|
56 |
-
|
57 |
-
/**
|
58 |
-
* Test assigning a Co-Author to a post
|
59 |
-
*/
|
60 |
-
public function test_add_coauthor_to_post() {
|
61 |
-
global $coauthors_plus;
|
62 |
-
|
63 |
-
$coauthors = get_coauthors( $this->author1_post1 );
|
64 |
-
$this->assertEquals( 1, count( $coauthors ) );
|
65 |
-
|
66 |
-
// append = true, should preserve order
|
67 |
-
$editor1 = get_user_by( 'id', $this->editor1 );
|
68 |
-
$coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), true );
|
69 |
-
$coauthors = get_coauthors( $this->author1_post1 );
|
70 |
-
$this->assertEquals( array( $this->author1, $this->editor1 ), wp_list_pluck( $coauthors, 'ID' ) );
|
71 |
-
|
72 |
-
// append = false, overrides existing authors
|
73 |
-
$coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), false );
|
74 |
-
$coauthors = get_coauthors( $this->author1_post1 );
|
75 |
-
$this->assertEquals( array( $this->editor1 ), wp_list_pluck( $coauthors, 'ID' ) );
|
76 |
-
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* When a co-author is assigned to a post, the post author value
|
81 |
-
* should be set appropriately
|
82 |
-
*
|
83 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/140
|
84 |
-
*/
|
85 |
-
public function test_add_coauthor_updates_post_author() {
|
86 |
-
global $coauthors_plus;
|
87 |
-
|
88 |
-
// append = true, preserves existing post_author
|
89 |
-
$editor1 = get_user_by( 'id', $this->editor1 );
|
90 |
-
$coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), true );
|
91 |
-
$this->assertEquals( $this->author1, get_post( $this->author1_post1 )->post_author );
|
92 |
-
|
93 |
-
// append = false, overrides existing post_author
|
94 |
-
$coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ), false );
|
95 |
-
$this->assertEquals( $this->editor1, get_post( $this->author1_post1 )->post_author );
|
96 |
-
|
97 |
-
}
|
98 |
-
|
99 |
-
/**
|
100 |
-
* Post published count should default to 'post', but be filterable
|
101 |
-
*
|
102 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/170
|
103 |
-
*/
|
104 |
-
public function test_post_publish_count_for_coauthor() {
|
105 |
-
global $coauthors_plus;
|
106 |
-
|
107 |
-
$editor1 = get_user_by( 'id', $this->editor1 );
|
108 |
-
|
109 |
-
/**
|
110 |
-
* Two published posts
|
111 |
-
*/
|
112 |
-
$coauthors_plus->add_coauthors( $this->author1_post1, array( $editor1->user_login ) );
|
113 |
-
$coauthors_plus->add_coauthors( $this->author1_post2, array( $editor1->user_login ) );
|
114 |
-
$this->assertEquals( 2, count_user_posts( $editor1->ID ) );
|
115 |
-
|
116 |
-
/**
|
117 |
-
* One published page too, but no filter
|
118 |
-
*/
|
119 |
-
$coauthors_plus->add_coauthors( $this->author1_page1, array( $editor1->user_login ) );
|
120 |
-
$this->assertEquals( 2, count_user_posts( $editor1->ID ) );
|
121 |
-
|
122 |
-
// Publish count to include posts and pages
|
123 |
-
$filter = function() {
|
124 |
-
return array( 'post', 'page' );
|
125 |
-
};
|
126 |
-
add_filter( 'coauthors_count_published_post_types', $filter );
|
127 |
-
|
128 |
-
/**
|
129 |
-
* Two published posts and pages
|
130 |
-
*/
|
131 |
-
$coauthors_plus->add_coauthors( $this->author1_page2, array( $editor1->user_login ) );
|
132 |
-
$this->assertEquals( 4, count_user_posts( $editor1->ID ) );
|
133 |
-
|
134 |
-
// Publish count is just pages
|
135 |
-
remove_filter( 'coauthors_count_published_post_types', $filter );
|
136 |
-
$filter = function() {
|
137 |
-
return array( 'page' );
|
138 |
-
};
|
139 |
-
add_filter( 'coauthors_count_published_post_types', $filter );
|
140 |
-
|
141 |
-
/**
|
142 |
-
* Just one published page now for the editor
|
143 |
-
*/
|
144 |
-
$author1 = get_user_by( 'id', $this->author1 );
|
145 |
-
$coauthors_plus->add_coauthors( $this->author1_page2, array( $author1->user_login ) );
|
146 |
-
$this->assertEquals( 1, count_user_posts( $editor1->ID ) );
|
147 |
-
|
148 |
-
}
|
149 |
-
|
150 |
-
/**
|
151 |
-
* Returns data as it is when post type is not allowed.
|
152 |
-
*
|
153 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
154 |
-
*
|
155 |
-
* @covers ::coauthors_set_post_author_field()
|
156 |
-
*/
|
157 |
-
public function test_coauthors_set_post_author_field_when_post_type_is_attachment() {
|
158 |
-
|
159 |
-
global $coauthors_plus;
|
160 |
-
|
161 |
-
$this->assertEquals( 10, has_filter( 'wp_insert_post_data', array(
|
162 |
-
$coauthors_plus,
|
163 |
-
'coauthors_set_post_author_field',
|
164 |
-
) ) );
|
165 |
-
|
166 |
-
$post_id = $this->factory->post->create( array(
|
167 |
-
'post_author' => $this->author1,
|
168 |
-
'post_type' => 'attachment',
|
169 |
-
) );
|
170 |
-
|
171 |
-
$post = get_post( $post_id );
|
172 |
-
|
173 |
-
$data = $post_array = array(
|
174 |
-
'ID' => $post->ID,
|
175 |
-
'post_type' => $post->post_type,
|
176 |
-
'post_author' => $post->post_author,
|
177 |
-
);
|
178 |
-
|
179 |
-
$new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array );
|
180 |
-
|
181 |
-
$this->assertEquals( $data, $new_data );
|
182 |
-
}
|
183 |
-
|
184 |
-
/**
|
185 |
-
* Compares data when coauthor is not set in the post array.
|
186 |
-
*
|
187 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
188 |
-
*
|
189 |
-
* @covers ::coauthors_set_post_author_field()
|
190 |
-
*/
|
191 |
-
public function test_coauthors_set_post_author_field_when_coauthor_is_not_set() {
|
192 |
-
|
193 |
-
global $coauthors_plus;
|
194 |
-
|
195 |
-
$author1_post1 = get_post( $this->author1_post1 );
|
196 |
-
|
197 |
-
$data = $post_array = array(
|
198 |
-
'ID' => $author1_post1->ID,
|
199 |
-
'post_type' => $author1_post1->post_type,
|
200 |
-
'post_author' => $author1_post1->post_author,
|
201 |
-
);
|
202 |
-
|
203 |
-
$new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array );
|
204 |
-
|
205 |
-
$this->assertEquals( $data, $new_data );
|
206 |
-
}
|
207 |
-
|
208 |
-
/**
|
209 |
-
* Compares data when coauthor is set in the post array.
|
210 |
-
*
|
211 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
212 |
-
*
|
213 |
-
* @covers ::coauthors_set_post_author_field()
|
214 |
-
*/
|
215 |
-
public function test_coauthors_set_post_author_field_when_coauthor_is_set() {
|
216 |
-
|
217 |
-
global $coauthors_plus;
|
218 |
-
|
219 |
-
$user_id = $this->factory->user->create( array(
|
220 |
-
'user_login' => 'test_admin',
|
221 |
-
'user_nicename' => 'test_admiи',
|
222 |
-
) );
|
223 |
-
|
224 |
-
$user = get_user_by( 'id', $user_id );
|
225 |
-
|
226 |
-
// Backing up global variables.
|
227 |
-
$post_backup = $_POST;
|
228 |
-
$request_backup = $_REQUEST;
|
229 |
-
|
230 |
-
$_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' );;
|
231 |
-
$_POST['coauthors'] = array(
|
232 |
-
$user->user_nicename,
|
233 |
-
);
|
234 |
-
|
235 |
-
$post_id = $this->factory->post->create( array(
|
236 |
-
'post_author' => $user_id,
|
237 |
-
) );
|
238 |
-
|
239 |
-
$post = get_post( $post_id );
|
240 |
-
|
241 |
-
$data = $post_array = array(
|
242 |
-
'ID' => $post->ID,
|
243 |
-
'post_type' => $post->post_type,
|
244 |
-
'post_author' => $post->post_author,
|
245 |
-
);
|
246 |
-
|
247 |
-
$new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array );
|
248 |
-
|
249 |
-
$this->assertEquals( $data, $new_data );
|
250 |
-
|
251 |
-
// Store global variables from backup.
|
252 |
-
$_POST = $post_backup;
|
253 |
-
$_REQUEST = $request_backup;
|
254 |
-
}
|
255 |
-
|
256 |
-
/**
|
257 |
-
* Compares data when coauthor is set and it is linked with main wp user.
|
258 |
-
*
|
259 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
260 |
-
*
|
261 |
-
* @covers ::coauthors_set_post_author_field()
|
262 |
-
*/
|
263 |
-
public function test_coauthors_set_post_author_field_when_guest_author_is_linked_with_wp_user() {
|
264 |
-
|
265 |
-
global $coauthors_plus;
|
266 |
-
|
267 |
-
$author1 = get_user_by( 'id', $this->author1 );
|
268 |
-
|
269 |
-
$author1_post1 = get_post( $this->author1_post1 );
|
270 |
-
|
271 |
-
$data = $post_array = array(
|
272 |
-
'ID' => $author1_post1->ID,
|
273 |
-
'post_type' => $author1_post1->post_type,
|
274 |
-
'post_author' => $author1_post1->post_author,
|
275 |
-
);
|
276 |
-
|
277 |
-
// Backing up global variables.
|
278 |
-
$post_backup = $_POST;
|
279 |
-
$request_backup = $_REQUEST;
|
280 |
-
|
281 |
-
$_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' );;
|
282 |
-
$_POST['coauthors'] = array(
|
283 |
-
$author1->user_nicename,
|
284 |
-
);
|
285 |
-
|
286 |
-
// Create guest author with linked account with user.
|
287 |
-
$coauthors_plus->guest_authors = new CoAuthors_Guest_Authors;
|
288 |
-
$coauthors_plus->guest_authors->create_guest_author_from_user_id( $this->author1 );
|
289 |
-
|
290 |
-
$new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array );
|
291 |
-
|
292 |
-
$this->assertEquals( $data, $new_data );
|
293 |
-
|
294 |
-
// Store global variables from backup.
|
295 |
-
$_POST = $post_backup;
|
296 |
-
$_REQUEST = $request_backup;
|
297 |
-
}
|
298 |
-
|
299 |
-
/**
|
300 |
-
* Compares post author when it is not set in the main data array somehow.
|
301 |
-
*
|
302 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
303 |
-
*
|
304 |
-
* @covers ::coauthors_set_post_author_field()
|
305 |
-
*/
|
306 |
-
public function test_coauthors_set_post_author_field_when_post_author_is_not_set() {
|
307 |
-
|
308 |
-
global $coauthors_plus;
|
309 |
-
|
310 |
-
wp_set_current_user( $this->author1 );
|
311 |
-
|
312 |
-
// Backing up global variables.
|
313 |
-
$post_backup = $_POST;
|
314 |
-
$request_backup = $_REQUEST;
|
315 |
-
|
316 |
-
$_REQUEST = $_POST = array();
|
317 |
-
|
318 |
-
$author1_post1 = get_post( $this->author1_post1 );
|
319 |
-
|
320 |
-
$data = $post_array = array(
|
321 |
-
'ID' => $author1_post1->ID,
|
322 |
-
'post_type' => $author1_post1->post_type,
|
323 |
-
'post_author' => $author1_post1->post_author,
|
324 |
-
);
|
325 |
-
|
326 |
-
unset( $data['post_author'] );
|
327 |
-
|
328 |
-
$new_data = $coauthors_plus->coauthors_set_post_author_field( $data, $post_array );
|
329 |
-
|
330 |
-
$this->assertEquals( $this->author1, $new_data['post_author'] );
|
331 |
-
|
332 |
-
// Store global variables from backup.
|
333 |
-
$_POST = $post_backup;
|
334 |
-
$_REQUEST = $request_backup;
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Bypass coauthors_update_post() when post type is not allowed.
|
339 |
-
*
|
340 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
341 |
-
*
|
342 |
-
* @covers ::coauthors_update_post()
|
343 |
-
*/
|
344 |
-
public function test_coauthors_update_post_when_post_type_is_attachment() {
|
345 |
-
|
346 |
-
global $coauthors_plus;
|
347 |
-
|
348 |
-
$this->assertEquals( 10, has_action( 'save_post', array(
|
349 |
-
$coauthors_plus,
|
350 |
-
'coauthors_update_post',
|
351 |
-
) ) );
|
352 |
-
|
353 |
-
$post_id = $this->factory->post->create( array(
|
354 |
-
'post_author' => $this->author1,
|
355 |
-
'post_type' => 'attachment',
|
356 |
-
) );
|
357 |
-
|
358 |
-
$post = get_post( $post_id );
|
359 |
-
$return = $coauthors_plus->coauthors_update_post( $post_id, $post );
|
360 |
-
|
361 |
-
$this->assertNull( $return );
|
362 |
-
}
|
363 |
-
|
364 |
-
/**
|
365 |
-
* Checks coauthors when current user can set authors.
|
366 |
-
*
|
367 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
368 |
-
*
|
369 |
-
* @covers ::coauthors_update_post()
|
370 |
-
*/
|
371 |
-
public function test_coauthors_update_post_when_current_user_can_set_authors() {
|
372 |
-
|
373 |
-
global $coauthors_plus;
|
374 |
-
|
375 |
-
wp_set_current_user( $this->admin1 );
|
376 |
-
|
377 |
-
$admin1 = get_user_by( 'id', $this->admin1 );
|
378 |
-
$author1 = get_user_by( 'id', $this->author1 );
|
379 |
-
|
380 |
-
$post_id = $this->factory->post->create( array(
|
381 |
-
'post_author' => $this->admin1,
|
382 |
-
) );
|
383 |
-
|
384 |
-
$post = get_post( $post_id );
|
385 |
-
|
386 |
-
// Backing up global variables.
|
387 |
-
$post_backup = $_POST;
|
388 |
-
$request_backup = $_REQUEST;
|
389 |
-
|
390 |
-
$_POST['coauthors-nonce'] = $_REQUEST['coauthors-nonce'] = wp_create_nonce( 'coauthors-edit' );
|
391 |
-
$_POST['coauthors'] = array(
|
392 |
-
$admin1->user_nicename,
|
393 |
-
$author1->user_nicename,
|
394 |
-
);
|
395 |
-
|
396 |
-
$coauthors_plus->coauthors_update_post( $post_id, $post );
|
397 |
-
|
398 |
-
$coauthors = get_coauthors( $post_id );
|
399 |
-
|
400 |
-
$this->assertEquals( array( $this->admin1, $this->author1 ), wp_list_pluck( $coauthors, 'ID' ) );
|
401 |
-
|
402 |
-
// Store global variables from backup.
|
403 |
-
$_POST = $post_backup;
|
404 |
-
$_REQUEST = $request_backup;
|
405 |
-
}
|
406 |
-
|
407 |
-
/**
|
408 |
-
* Coauthors should be empty if post does not have any author terms
|
409 |
-
* and current user can not set authors for the post.
|
410 |
-
*
|
411 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/198
|
412 |
-
*
|
413 |
-
* @covers ::coauthors_update_post()
|
414 |
-
*/
|
415 |
-
public function test_coauthors_update_post_when_post_has_not_author_terms() {
|
416 |
-
|
417 |
-
global $coauthors_plus;
|
418 |
-
|
419 |
-
$post_id = $this->factory->post->create();
|
420 |
-
$post = get_post( $post_id );
|
421 |
-
|
422 |
-
$coauthors_plus->coauthors_update_post( $post_id, $post );
|
423 |
-
|
424 |
-
$coauthors = get_coauthors( $post_id );
|
425 |
-
|
426 |
-
$this->assertEmpty( $coauthors );
|
427 |
-
}
|
428 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
3 |
-
class Test_Template_Tags extends CoAuthorsPlus_TestCase {
|
4 |
-
|
5 |
-
public function setUp() {
|
6 |
-
|
7 |
-
parent::setUp();
|
8 |
-
|
9 |
-
/**
|
10 |
-
* When 'coauthors_auto_apply_template_tags' is set to true,
|
11 |
-
* we need CoAuthors_Template_Filters object to check 'the_author' filter.
|
12 |
-
*/
|
13 |
-
global $coauthors_plus_template_filters;
|
14 |
-
$coauthors_plus_template_filters = new CoAuthors_Template_Filters;
|
15 |
-
|
16 |
-
$this->author1 = $this->factory->user->create_and_get( array( 'role' => 'author', 'user_login' => 'author1' ) );
|
17 |
-
$this->editor1 = $this->factory->user->create_and_get( array( 'role' => 'editor', 'user_login' => 'editor1' ) );
|
18 |
-
|
19 |
-
$this->post = $this->factory->post->create_and_get( array(
|
20 |
-
'post_author' => $this->author1->ID,
|
21 |
-
'post_status' => 'publish',
|
22 |
-
'post_content' => rand_str(),
|
23 |
-
'post_title' => rand_str(),
|
24 |
-
'post_type' => 'post',
|
25 |
-
) );
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Tests for co-authors display names, with links to their posts.
|
30 |
-
*
|
31 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/279
|
32 |
-
*
|
33 |
-
* @covers ::coauthors_posts_links()
|
34 |
-
*/
|
35 |
-
public function test_coauthors_posts_links() {
|
36 |
-
|
37 |
-
global $coauthors_plus, $coauthors_plus_template_filters;
|
38 |
-
|
39 |
-
// Backing up global post.
|
40 |
-
$post_backup = $GLOBALS['post'];
|
41 |
-
|
42 |
-
$GLOBALS['post'] = $this->post;
|
43 |
-
|
44 |
-
// Checks for single post author.
|
45 |
-
$single_cpl = coauthors_posts_links( null, null, null, null, false );
|
46 |
-
|
47 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $single_cpl, 'Author link not found.' );
|
48 |
-
$this->assertContains( $this->author1->display_name, $single_cpl, 'Author name not found.' );
|
49 |
-
|
50 |
-
// Checks for multiple post author.
|
51 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
52 |
-
|
53 |
-
$multiple_cpl = coauthors_posts_links( null, null, null, null, false );
|
54 |
-
|
55 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $multiple_cpl, 'Main author link not found.' );
|
56 |
-
$this->assertContains( $this->author1->display_name, $multiple_cpl, 'Main author name not found.' );
|
57 |
-
|
58 |
-
// Here we are checking author name should not be more then one time.
|
59 |
-
// Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc.
|
60 |
-
$this->assertEquals( 1, substr_count( $multiple_cpl, ">{$this->author1->display_name}<" ) );
|
61 |
-
$this->assertContains( ' and ', $multiple_cpl, 'Coauthors name separator is not matched.' );
|
62 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->editor1->ID, $this->editor1->user_nicename ) . '"', $multiple_cpl, 'Coauthor link not found.' );
|
63 |
-
$this->assertContains( $this->editor1->display_name, $multiple_cpl, 'Coauthor name not found.' );
|
64 |
-
|
65 |
-
// Here we are checking editor name should not be more then one time.
|
66 |
-
// Asserting ">{$this->editor1->display_name}<" because "$this->editor1->display_name" can be multiple times like in href, title, etc.
|
67 |
-
$this->assertEquals( 1, substr_count( $multiple_cpl, ">{$this->editor1->display_name}<" ) );
|
68 |
-
|
69 |
-
$multiple_cpl = coauthors_links( null, ' or ', null, null, false );
|
70 |
-
|
71 |
-
$this->assertContains( ' or ', $multiple_cpl, 'Coauthors name separator is not matched.' );
|
72 |
-
|
73 |
-
$this->assertEquals( 10, has_filter( 'the_author', array(
|
74 |
-
$coauthors_plus_template_filters,
|
75 |
-
'filter_the_author',
|
76 |
-
) ) );
|
77 |
-
|
78 |
-
// Restore backed up post to global.
|
79 |
-
$GLOBALS['post'] = $post_backup;
|
80 |
-
}
|
81 |
-
|
82 |
-
/**
|
83 |
-
* Tests for co-authors display names.
|
84 |
-
*
|
85 |
-
* @see https://github.com/Automattic/Co-Authors-Plus/issues/279
|
86 |
-
*
|
87 |
-
* @covers ::coauthors_links()
|
88 |
-
*/
|
89 |
-
public function test_coauthors_links() {
|
90 |
-
|
91 |
-
global $coauthors_plus, $coauthors_plus_template_filters;
|
92 |
-
|
93 |
-
// Backing up global post.
|
94 |
-
$post_backup = $GLOBALS['post'];
|
95 |
-
|
96 |
-
$GLOBALS['post'] = $this->post;
|
97 |
-
|
98 |
-
// Checks for single post author.
|
99 |
-
$single_cpl = coauthors_links( null, null, null, null, false );
|
100 |
-
|
101 |
-
$this->assertEquals( $this->author1->display_name, $single_cpl, 'Author name not found.' );
|
102 |
-
|
103 |
-
// Checks for multiple post author.
|
104 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
105 |
-
|
106 |
-
$multiple_cpl = coauthors_links( null, null, null, null, false );
|
107 |
-
|
108 |
-
$this->assertContains( $this->author1->display_name, $multiple_cpl, 'Main author name not found.' );
|
109 |
-
$this->assertEquals( 1, substr_count( $multiple_cpl, $this->author1->display_name ) );
|
110 |
-
$this->assertContains( ' and ', $multiple_cpl, 'Coauthors name separator is not matched.' );
|
111 |
-
$this->assertContains( $this->editor1->display_name, $multiple_cpl, 'Coauthor name not found.' );
|
112 |
-
$this->assertEquals( 1, substr_count( $multiple_cpl, $this->editor1->display_name ) );
|
113 |
-
|
114 |
-
$multiple_cpl = coauthors_links( null, ' or ', null, null, false );
|
115 |
-
|
116 |
-
$this->assertContains( ' or ', $multiple_cpl, 'Coauthors name separator is not matched.' );
|
117 |
-
|
118 |
-
$this->assertEquals( 10, has_filter( 'the_author', array(
|
119 |
-
$coauthors_plus_template_filters,
|
120 |
-
'filter_the_author',
|
121 |
-
) ) );
|
122 |
-
|
123 |
-
// Restore backed up post to global.
|
124 |
-
$GLOBALS['post'] = $post_backup;
|
125 |
-
}
|
126 |
-
|
127 |
-
/**
|
128 |
-
* Checks coauthors when post not exist.
|
129 |
-
*
|
130 |
-
* @covers ::get_coauthors()
|
131 |
-
*/
|
132 |
-
public function test_get_coauthors_when_post_not_exists() {
|
133 |
-
|
134 |
-
$this->assertEmpty( get_coauthors() );
|
135 |
-
}
|
136 |
-
|
137 |
-
/**
|
138 |
-
* Checks coauthors when post exist (not global).
|
139 |
-
*
|
140 |
-
* @covers ::get_coauthors()
|
141 |
-
*/
|
142 |
-
public function test_get_coauthors_when_post_exists() {
|
143 |
-
|
144 |
-
global $coauthors_plus;
|
145 |
-
|
146 |
-
// Compare single author.
|
147 |
-
$this->assertEquals( array( $this->author1->ID ), wp_list_pluck( get_coauthors( $this->post->ID ), 'ID' ) );
|
148 |
-
|
149 |
-
// Compare multiple authors.
|
150 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
151 |
-
$this->assertEquals( array(
|
152 |
-
$this->author1->ID,
|
153 |
-
$this->editor1->ID,
|
154 |
-
), wp_list_pluck( get_coauthors( $this->post->ID ), 'ID' ) );
|
155 |
-
}
|
156 |
-
|
157 |
-
/**
|
158 |
-
* Checks coauthors when terms for post not exist.
|
159 |
-
*
|
160 |
-
* @covers ::get_coauthors()
|
161 |
-
*/
|
162 |
-
public function test_get_coauthors_when_terms_for_post_not_exists() {
|
163 |
-
|
164 |
-
$post_id = $this->factory->post->create();
|
165 |
-
$this->assertEmpty( get_coauthors( $post_id ) );
|
166 |
-
}
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Checks coauthors when post not exist.
|
170 |
-
*
|
171 |
-
* @covers ::get_coauthors()
|
172 |
-
*/
|
173 |
-
public function test_get_coauthors_when_global_post_exists() {
|
174 |
-
|
175 |
-
global $post;
|
176 |
-
|
177 |
-
// Backing up global post.
|
178 |
-
$post_backup = $post;
|
179 |
-
|
180 |
-
$post = $this->factory->post->create_and_get();
|
181 |
-
|
182 |
-
$this->assertEmpty( get_coauthors() );
|
183 |
-
|
184 |
-
$user_id = $this->factory->user->create();
|
185 |
-
$post = $this->factory->post->create_and_get( array(
|
186 |
-
'post_author' => $user_id,
|
187 |
-
) );
|
188 |
-
|
189 |
-
$this->assertEquals( array( $user_id ), wp_list_pluck( get_coauthors(), 'ID' ) );
|
190 |
-
|
191 |
-
// Restore global post from backup.
|
192 |
-
$post = $post_backup;
|
193 |
-
}
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Checks coauthors order.
|
197 |
-
*
|
198 |
-
* @covers ::get_coauthors()
|
199 |
-
*/
|
200 |
-
public function test_coauthors_order() {
|
201 |
-
|
202 |
-
global $coauthors_plus;
|
203 |
-
|
204 |
-
$post_id = $this->factory->post->create();
|
205 |
-
|
206 |
-
// Checks when no author exist.
|
207 |
-
$this->assertEmpty( get_coauthors( $post_id ) );
|
208 |
-
|
209 |
-
// Checks coauthors order.
|
210 |
-
$coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true );
|
211 |
-
$coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true );
|
212 |
-
|
213 |
-
$expected = array( $this->author1->user_login, $this->editor1->user_login );
|
214 |
-
|
215 |
-
$this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) );
|
216 |
-
|
217 |
-
// Checks coauthors order after modifying.
|
218 |
-
$post_id = $this->factory->post->create();
|
219 |
-
|
220 |
-
$coauthors_plus->add_coauthors( $post_id, array( $this->editor1->user_login ), true );
|
221 |
-
$coauthors_plus->add_coauthors( $post_id, array( $this->author1->user_login ), true );
|
222 |
-
|
223 |
-
$expected = array( $this->editor1->user_login, $this->author1->user_login );
|
224 |
-
|
225 |
-
$this->assertEquals( $expected, wp_list_pluck( get_coauthors( $post_id ), 'user_login' ) );
|
226 |
-
}
|
227 |
-
|
228 |
-
/**
|
229 |
-
* Checks whether user is a coauthor of the post when user or post not exists.
|
230 |
-
*
|
231 |
-
* @covers ::is_coauthor_for_post()
|
232 |
-
*/
|
233 |
-
public function test_is_coauthor_for_post_when_user_or_post_not_exists() {
|
234 |
-
|
235 |
-
global $post;
|
236 |
-
|
237 |
-
// Backing up global post.
|
238 |
-
$post_backup = $post;
|
239 |
-
|
240 |
-
$this->assertFalse( is_coauthor_for_post( '' ) );
|
241 |
-
$this->assertFalse( is_coauthor_for_post( '', $this->post->ID ) );
|
242 |
-
$this->assertFalse( is_coauthor_for_post( $this->author1->ID ) );
|
243 |
-
|
244 |
-
$post = $this->post;
|
245 |
-
|
246 |
-
$this->assertFalse( is_coauthor_for_post( '' ) );
|
247 |
-
|
248 |
-
// Restore global post from backup.
|
249 |
-
$post = $post_backup;
|
250 |
-
}
|
251 |
-
|
252 |
-
/**
|
253 |
-
* Checks whether user is a coauthor of the post when user is not expected as ID,
|
254 |
-
* or user_login is not set in user object.
|
255 |
-
*
|
256 |
-
* @covers ::is_coauthor_for_post()
|
257 |
-
*/
|
258 |
-
public function test_is_coauthor_for_post_when_user_not_numeric_or_user_login_not_set() {
|
259 |
-
|
260 |
-
$this->assertFalse( is_coauthor_for_post( 'test' ) );
|
261 |
-
}
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Checks whether user is a coauthor of the post when user is set in either way,
|
265 |
-
* as user_id or user object but he/she is not coauthor of the post.
|
266 |
-
*
|
267 |
-
* @covers ::is_coauthor_for_post()
|
268 |
-
*/
|
269 |
-
public function test_is_coauthor_for_post_when_user_numeric_or_user_login_set_but_not_coauthor() {
|
270 |
-
|
271 |
-
$this->assertFalse( is_coauthor_for_post( $this->editor1->ID, $this->post->ID ) );
|
272 |
-
$this->assertFalse( is_coauthor_for_post( $this->editor1, $this->post->ID ) );
|
273 |
-
}
|
274 |
-
|
275 |
-
/**
|
276 |
-
* Checks whether user is a coauthor of the post.
|
277 |
-
*
|
278 |
-
* @covers ::is_coauthor_for_post()
|
279 |
-
*/
|
280 |
-
public function test_is_coauthor_for_post_when_user_is_coauthor() {
|
281 |
-
|
282 |
-
global $post, $coauthors_plus;
|
283 |
-
|
284 |
-
// Backing up global post.
|
285 |
-
$post_backup = $post;
|
286 |
-
|
287 |
-
// Checking with specific post and user_id as well ass user object.
|
288 |
-
$this->assertTrue( is_coauthor_for_post( $this->author1->ID, $this->post->ID ) );
|
289 |
-
$this->assertTrue( is_coauthor_for_post( $this->author1, $this->post->ID ) );
|
290 |
-
|
291 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
292 |
-
|
293 |
-
$this->assertTrue( is_coauthor_for_post( $this->editor1->ID, $this->post->ID ) );
|
294 |
-
$this->assertTrue( is_coauthor_for_post( $this->editor1, $this->post->ID ) );
|
295 |
-
|
296 |
-
// Now checking with global post and user_id as well ass user object.
|
297 |
-
$post = $this->post;
|
298 |
-
|
299 |
-
$this->assertTrue( is_coauthor_for_post( $this->author1->ID ) );
|
300 |
-
$this->assertTrue( is_coauthor_for_post( $this->author1 ) );
|
301 |
-
|
302 |
-
$this->assertTrue( is_coauthor_for_post( $this->editor1->ID ) );
|
303 |
-
$this->assertTrue( is_coauthor_for_post( $this->editor1 ) );
|
304 |
-
|
305 |
-
// Restore global post from backup.
|
306 |
-
$post = $post_backup;
|
307 |
-
}
|
308 |
-
|
309 |
-
/**
|
310 |
-
* Tests for co-authors display names, without links to their posts.
|
311 |
-
*
|
312 |
-
* @covers ::coauthors()
|
313 |
-
* @covers ::coauthors__echo()
|
314 |
-
**/
|
315 |
-
public function test_coauthors() {
|
316 |
-
|
317 |
-
global $post, $coauthors_plus;
|
318 |
-
|
319 |
-
// Backing up global post.
|
320 |
-
$post_backup = $post;
|
321 |
-
|
322 |
-
$post = $this->post;
|
323 |
-
|
324 |
-
// Checks for single post author.
|
325 |
-
$coauthors = coauthors( null, null, null, null, false );
|
326 |
-
|
327 |
-
$this->assertEquals( $this->author1->display_name, $coauthors );
|
328 |
-
|
329 |
-
$coauthors = coauthors( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
330 |
-
|
331 |
-
$this->assertEquals( '<span>' . $this->author1->display_name . '</span>', $coauthors );
|
332 |
-
|
333 |
-
// Checks for multiple post author.
|
334 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
335 |
-
|
336 |
-
$coauthors = coauthors( null, null, null, null, false );
|
337 |
-
|
338 |
-
$this->assertEquals( $this->author1->display_name . ' and ' . $this->editor1->display_name, $coauthors );
|
339 |
-
|
340 |
-
$coauthors = coauthors( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
341 |
-
|
342 |
-
$this->assertEquals( '<span>' . $this->author1->display_name . '</span><span>' . $this->editor1->display_name . '</span>', $coauthors );
|
343 |
-
|
344 |
-
// Restore global post from backup.
|
345 |
-
$post = $post_backup;
|
346 |
-
}
|
347 |
-
|
348 |
-
/**
|
349 |
-
* Checks single co-author linked to their post archive.
|
350 |
-
*
|
351 |
-
* @covers ::coauthors_posts_links_single()
|
352 |
-
*/
|
353 |
-
public function test_coauthors_posts_links_single() {
|
354 |
-
|
355 |
-
global $post;
|
356 |
-
|
357 |
-
// Backing up global post.
|
358 |
-
$post_backup = $post;
|
359 |
-
|
360 |
-
$post = $this->post;
|
361 |
-
|
362 |
-
$author_link = coauthors_posts_links_single( $this->author1 );
|
363 |
-
|
364 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $author_link, 'Author link not found.' );
|
365 |
-
$this->assertContains( $this->author1->display_name, $author_link, 'Author name not found.' );
|
366 |
-
|
367 |
-
// Here we are checking author name should not be more then one time.
|
368 |
-
// Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc.
|
369 |
-
$this->assertEquals( 1, substr_count( $author_link, ">{$this->author1->display_name}<" ) );
|
370 |
-
|
371 |
-
// Restore global post from backup.
|
372 |
-
$post = $post_backup;
|
373 |
-
}
|
374 |
-
|
375 |
-
/**
|
376 |
-
* Checks co-authors first names, without links to their posts.
|
377 |
-
*
|
378 |
-
* @covers ::coauthors_firstnames()
|
379 |
-
* @covers ::coauthors__echo()
|
380 |
-
*/
|
381 |
-
public function test_coauthors_firstnames() {
|
382 |
-
|
383 |
-
global $post, $coauthors_plus;
|
384 |
-
|
385 |
-
// Backing up global post.
|
386 |
-
$post_backup = $post;
|
387 |
-
|
388 |
-
$post = $this->post;
|
389 |
-
|
390 |
-
// Checking when first name is not set for user, so it should match with user_login.
|
391 |
-
$first_names = coauthors_firstnames( null, null, null, null, false );
|
392 |
-
|
393 |
-
$this->assertEquals( $this->author1->user_login, $first_names );
|
394 |
-
|
395 |
-
$first_names = coauthors_firstnames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
396 |
-
|
397 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span>', $first_names );
|
398 |
-
|
399 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
400 |
-
|
401 |
-
$first_names = coauthors_firstnames( null, null, null, null, false );
|
402 |
-
|
403 |
-
$this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $first_names );
|
404 |
-
|
405 |
-
$first_names = coauthors_firstnames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
406 |
-
|
407 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span><span>' . $this->editor1->user_login . '</span>', $first_names );
|
408 |
-
|
409 |
-
// Checking when first name is set for user.
|
410 |
-
$first_name = 'Test';
|
411 |
-
$user_id = $this->factory->user->create( array(
|
412 |
-
'first_name' => $first_name,
|
413 |
-
) );
|
414 |
-
$post = $this->factory->post->create_and_get( array(
|
415 |
-
'post_author' => $user_id,
|
416 |
-
) );
|
417 |
-
|
418 |
-
$first_names = coauthors_firstnames( null, null, null, null, false );
|
419 |
-
|
420 |
-
$this->assertEquals( $first_name, $first_names );
|
421 |
-
|
422 |
-
// Restore global post from backup.
|
423 |
-
$post = $post_backup;
|
424 |
-
}
|
425 |
-
|
426 |
-
/**
|
427 |
-
* Checks co-authors last names, without links to their posts.
|
428 |
-
*
|
429 |
-
* @covers ::coauthors_lastnames()
|
430 |
-
* @covers ::coauthors__echo()
|
431 |
-
*/
|
432 |
-
public function test_coauthors_lastnames() {
|
433 |
-
|
434 |
-
global $post, $coauthors_plus;
|
435 |
-
|
436 |
-
// Backing up global post.
|
437 |
-
$post_backup = $post;
|
438 |
-
|
439 |
-
$post = $this->post;
|
440 |
-
|
441 |
-
// Checking when last name is not set for user, so it should match with user_login.
|
442 |
-
$last_names = coauthors_lastnames( null, null, null, null, false );
|
443 |
-
|
444 |
-
$this->assertEquals( $this->author1->user_login, $last_names );
|
445 |
-
|
446 |
-
$last_names = coauthors_lastnames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
447 |
-
|
448 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span>', $last_names );
|
449 |
-
|
450 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
451 |
-
|
452 |
-
$last_names = coauthors_lastnames( null, null, null, null, false );
|
453 |
-
|
454 |
-
$this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $last_names );
|
455 |
-
|
456 |
-
$last_names = coauthors_lastnames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
457 |
-
|
458 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span><span>' . $this->editor1->user_login . '</span>', $last_names );
|
459 |
-
|
460 |
-
// Checking when last name is set for user.
|
461 |
-
$last_name = 'Test';
|
462 |
-
$user_id = $this->factory->user->create( array(
|
463 |
-
'last_name' => $last_name,
|
464 |
-
) );
|
465 |
-
$post = $this->factory->post->create_and_get( array(
|
466 |
-
'post_author' => $user_id,
|
467 |
-
) );
|
468 |
-
|
469 |
-
$last_names = coauthors_lastnames( null, null, null, null, false );
|
470 |
-
|
471 |
-
$this->assertEquals( $last_name, $last_names );
|
472 |
-
|
473 |
-
// Restore global post from backup.
|
474 |
-
$post = $post_backup;
|
475 |
-
}
|
476 |
-
|
477 |
-
/**
|
478 |
-
* Checks co-authors nicknames, without links to their posts.
|
479 |
-
*
|
480 |
-
* @covers ::coauthors_nicknames()
|
481 |
-
* @covers ::coauthors__echo()
|
482 |
-
*/
|
483 |
-
public function test_coauthors_nicknames() {
|
484 |
-
|
485 |
-
global $post, $coauthors_plus;
|
486 |
-
|
487 |
-
// Backing up global post.
|
488 |
-
$post_backup = $post;
|
489 |
-
|
490 |
-
$post = $this->post;
|
491 |
-
|
492 |
-
// Checking when nickname is not set for user, so it should match with user_login.
|
493 |
-
$nick_names = coauthors_nicknames( null, null, null, null, false );
|
494 |
-
|
495 |
-
$this->assertEquals( $this->author1->user_login, $nick_names );
|
496 |
-
|
497 |
-
$nick_names = coauthors_nicknames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
498 |
-
|
499 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span>', $nick_names );
|
500 |
-
|
501 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
502 |
-
|
503 |
-
$nick_names = coauthors_nicknames( null, null, null, null, false );
|
504 |
-
|
505 |
-
$this->assertEquals( $this->author1->user_login . ' and ' . $this->editor1->user_login, $nick_names );
|
506 |
-
|
507 |
-
$nick_names = coauthors_nicknames( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
508 |
-
|
509 |
-
$this->assertEquals( '<span>' . $this->author1->user_login . '</span><span>' . $this->editor1->user_login . '</span>', $nick_names );
|
510 |
-
|
511 |
-
// Checking when nickname is set for user.
|
512 |
-
$nick_name = 'Test';
|
513 |
-
$user_id = $this->factory->user->create( array(
|
514 |
-
'nickname' => $nick_name,
|
515 |
-
) );
|
516 |
-
$post = $this->factory->post->create_and_get( array(
|
517 |
-
'post_author' => $user_id,
|
518 |
-
) );
|
519 |
-
|
520 |
-
$nick_names = coauthors_nicknames( null, null, null, null, false );
|
521 |
-
|
522 |
-
$this->assertEquals( $nick_name, $nick_names );
|
523 |
-
|
524 |
-
// Restore global post from backup.
|
525 |
-
$post = $post_backup;
|
526 |
-
}
|
527 |
-
|
528 |
-
/**
|
529 |
-
* Checks co-authors email addresses.
|
530 |
-
*
|
531 |
-
* @covers ::coauthors_emails()
|
532 |
-
* @covers ::coauthors__echo()
|
533 |
-
*/
|
534 |
-
public function test_coauthors_emails() {
|
535 |
-
|
536 |
-
global $post, $coauthors_plus;
|
537 |
-
|
538 |
-
// Backing up global post.
|
539 |
-
$post_backup = $post;
|
540 |
-
|
541 |
-
$post = $this->post;
|
542 |
-
|
543 |
-
$emails = coauthors_emails( null, null, null, null, false );
|
544 |
-
|
545 |
-
$this->assertEquals( $this->author1->user_email, $emails );
|
546 |
-
|
547 |
-
$emails = coauthors_emails( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
548 |
-
|
549 |
-
$this->assertEquals( '<span>' . $this->author1->user_email . '</span>', $emails );
|
550 |
-
|
551 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
552 |
-
|
553 |
-
$emails = coauthors_emails( null, null, null, null, false );
|
554 |
-
|
555 |
-
$this->assertEquals( $this->author1->user_email . ' and ' . $this->editor1->user_email, $emails );
|
556 |
-
|
557 |
-
$emails = coauthors_emails( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
558 |
-
|
559 |
-
$this->assertEquals( '<span>' . $this->author1->user_email . '</span><span>' . $this->editor1->user_email . '</span>', $emails );
|
560 |
-
|
561 |
-
$email = 'test@example.org';
|
562 |
-
$user_id = $this->factory->user->create( array(
|
563 |
-
'user_email' => $email,
|
564 |
-
) );
|
565 |
-
$post = $this->factory->post->create_and_get( array(
|
566 |
-
'post_author' => $user_id,
|
567 |
-
) );
|
568 |
-
|
569 |
-
$emails = coauthors_emails( null, null, null, null, false );
|
570 |
-
|
571 |
-
$this->assertEquals( $email, $emails );
|
572 |
-
|
573 |
-
// Restore global post from backup.
|
574 |
-
$post = $post_backup;
|
575 |
-
}
|
576 |
-
|
577 |
-
/**
|
578 |
-
* Checks single co-author if he/she is a guest author.
|
579 |
-
*
|
580 |
-
* @covers ::coauthors_links_single()
|
581 |
-
*/
|
582 |
-
public function test_coauthors_links_single_when_guest_author() {
|
583 |
-
|
584 |
-
global $post, $authordata;
|
585 |
-
|
586 |
-
// Backing up global post.
|
587 |
-
$post_backup = $post;
|
588 |
-
|
589 |
-
$post = $this->post;
|
590 |
-
|
591 |
-
// Backing up global author data.
|
592 |
-
$authordata_backup = $authordata;
|
593 |
-
|
594 |
-
$this->author1->type = 'guest-author';
|
595 |
-
|
596 |
-
$this->assertNull( coauthors_links_single( $this->author1 ) );
|
597 |
-
|
598 |
-
update_user_meta( $this->author1->ID, 'website', 'example.org' );
|
599 |
-
|
600 |
-
$this->assertNull( coauthors_links_single( $this->author1 ) );
|
601 |
-
|
602 |
-
$authordata = $this->author1;
|
603 |
-
$author_link = coauthors_links_single( $this->author1 );
|
604 |
-
|
605 |
-
$this->assertContains( get_the_author_meta( 'website' ), $author_link, 'Author link not found.' );
|
606 |
-
$this->assertContains( get_the_author(), $author_link, 'Author name not found.' );
|
607 |
-
|
608 |
-
// Here we are checking author name should not be more then one time.
|
609 |
-
// Asserting ">get_the_author()<" because "get_the_author()" can be multiple times like in href, title, etc.
|
610 |
-
$this->assertEquals( 1, substr_count( $author_link, '>' . get_the_author() . '<' ) );
|
611 |
-
|
612 |
-
// Restore global author data from backup.
|
613 |
-
$authordata = $authordata_backup;
|
614 |
-
|
615 |
-
// Restore global post from backup.
|
616 |
-
$post = $post_backup;
|
617 |
-
}
|
618 |
-
|
619 |
-
/**
|
620 |
-
* Checks single co-author when user's url is set and not a guest author.
|
621 |
-
*
|
622 |
-
* @covers ::coauthors_links_single()
|
623 |
-
*/
|
624 |
-
public function test_coauthors_links_single_author_url_is_set() {
|
625 |
-
|
626 |
-
global $post, $authordata;
|
627 |
-
|
628 |
-
// Backing up global post.
|
629 |
-
$post_backup = $post;
|
630 |
-
|
631 |
-
$post = $this->post;
|
632 |
-
|
633 |
-
// Backing up global author data.
|
634 |
-
$authordata_backup = $authordata;
|
635 |
-
|
636 |
-
$user_id = $this->factory->user->create( array(
|
637 |
-
'user_url' => 'example.org',
|
638 |
-
) );
|
639 |
-
$user = get_user_by( 'id', $user_id );
|
640 |
-
|
641 |
-
$authordata = $user;
|
642 |
-
$author_link = coauthors_links_single( $user );
|
643 |
-
|
644 |
-
$this->assertContains( get_the_author_meta( 'url' ), $author_link, 'Author link not found.' );
|
645 |
-
$this->assertContains( get_the_author(), $author_link, 'Author name not found.' );
|
646 |
-
|
647 |
-
// Here we are checking author name should not be more then one time.
|
648 |
-
// Asserting ">get_the_author()<" because "get_the_author()" can be multiple times like in href, title, etc.
|
649 |
-
$this->assertEquals( 1, substr_count( $author_link, '>' . get_the_author() . '<' ) );
|
650 |
-
|
651 |
-
// Restore global author data from backup.
|
652 |
-
$authordata = $authordata_backup;
|
653 |
-
|
654 |
-
// Restore global post from backup.
|
655 |
-
$post = $post_backup;
|
656 |
-
}
|
657 |
-
|
658 |
-
/**
|
659 |
-
* Checks single co-author when user's website/url not exist.
|
660 |
-
*
|
661 |
-
* @covers ::coauthors_links_single()
|
662 |
-
*/
|
663 |
-
public function test_coauthors_links_single_when_url_not_exist() {
|
664 |
-
|
665 |
-
global $post, $authordata;
|
666 |
-
|
667 |
-
// Backing up global post.
|
668 |
-
$post_backup = $post;
|
669 |
-
|
670 |
-
$post = $this->post;
|
671 |
-
|
672 |
-
// Backing up global author data.
|
673 |
-
$authordata_backup = $authordata;
|
674 |
-
|
675 |
-
$this->editor1->type = 'guest-author';
|
676 |
-
|
677 |
-
$author_link = coauthors_links_single( $this->editor1 );
|
678 |
-
|
679 |
-
$this->assertEmpty( $author_link );
|
680 |
-
|
681 |
-
$authordata = $this->author1;
|
682 |
-
$author_link = coauthors_links_single( $this->author1 );
|
683 |
-
|
684 |
-
$this->assertEquals( get_the_author(), $author_link );
|
685 |
-
|
686 |
-
// Restore global author data from backup.
|
687 |
-
$authordata = $authordata_backup;
|
688 |
-
|
689 |
-
// Restore global post from backup.
|
690 |
-
$post = $post_backup;
|
691 |
-
}
|
692 |
-
|
693 |
-
/**
|
694 |
-
* Checks co-authors IDs.
|
695 |
-
*
|
696 |
-
* @covers ::coauthors_ids()
|
697 |
-
* @covers ::coauthors__echo()
|
698 |
-
*/
|
699 |
-
public function test_coauthors_ids() {
|
700 |
-
|
701 |
-
global $post, $coauthors_plus;
|
702 |
-
|
703 |
-
// Backing up global post.
|
704 |
-
$post_backup = $post;
|
705 |
-
|
706 |
-
$post = $this->post;
|
707 |
-
|
708 |
-
$ids = coauthors_ids( null, null, null, null, false );
|
709 |
-
|
710 |
-
$this->assertEquals( $this->author1->ID, $ids );
|
711 |
-
|
712 |
-
$ids = coauthors_ids( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
713 |
-
|
714 |
-
$this->assertEquals( '<span>' . $this->author1->ID . '</span>', $ids );
|
715 |
-
|
716 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
717 |
-
|
718 |
-
$ids = coauthors_ids( null, null, null, null, false );
|
719 |
-
|
720 |
-
$this->assertEquals( $this->author1->ID . ' and ' . $this->editor1->ID, $ids );
|
721 |
-
|
722 |
-
$ids = coauthors_ids( '</span><span>', '</span><span>', '<span>', '</span>', false );
|
723 |
-
|
724 |
-
$this->assertEquals( '<span>' . $this->author1->ID . '</span><span>' . $this->editor1->ID . '</span>', $ids );
|
725 |
-
|
726 |
-
// Restore global post from backup.
|
727 |
-
$post = $post_backup;
|
728 |
-
}
|
729 |
-
|
730 |
-
/**
|
731 |
-
* Checks co-authors meta.
|
732 |
-
*
|
733 |
-
* @covers ::get_the_coauthor_meta()
|
734 |
-
*/
|
735 |
-
public function test_get_the_coauthor_meta() {
|
736 |
-
|
737 |
-
global $post;
|
738 |
-
|
739 |
-
// Backing up global post.
|
740 |
-
$post_backup = $post;
|
741 |
-
|
742 |
-
$this->assertEmpty( get_the_coauthor_meta( '' ) );
|
743 |
-
|
744 |
-
update_user_meta( $this->author1->ID, 'meta_key', 'meta_value' );
|
745 |
-
|
746 |
-
$this->assertEmpty( get_the_coauthor_meta( 'meta_key' ) );
|
747 |
-
|
748 |
-
$post = $this->post;
|
749 |
-
$meta = get_the_coauthor_meta( 'meta_key' );
|
750 |
-
|
751 |
-
$this->assertEquals( 'meta_value', $meta[ $this->author1->ID ] );
|
752 |
-
|
753 |
-
// Restore global post from backup.
|
754 |
-
$post = $post_backup;
|
755 |
-
}
|
756 |
-
|
757 |
-
/**
|
758 |
-
* Checks all the co-authors of the blog with default args.
|
759 |
-
*
|
760 |
-
* @covers ::coauthors_wp_list_authors()
|
761 |
-
*/
|
762 |
-
public function test_coauthors_wp_list_authors_for_default_args() {
|
763 |
-
|
764 |
-
global $coauthors_plus;
|
765 |
-
|
766 |
-
$args = array(
|
767 |
-
'echo' => false,
|
768 |
-
);
|
769 |
-
|
770 |
-
$coauthors = coauthors_wp_list_authors( $args );
|
771 |
-
|
772 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $coauthors, 'Author link not found.' );
|
773 |
-
$this->assertContains( $this->author1->display_name, $coauthors, 'Author name not found.' );
|
774 |
-
|
775 |
-
$coauthors = coauthors_wp_list_authors( $args );
|
776 |
-
|
777 |
-
$this->assertNotContains( 'href="' . get_author_posts_url( $this->editor1->ID, $this->editor1->user_nicename ) . '"', $coauthors );
|
778 |
-
$this->assertNotContains( $this->editor1->display_name, $coauthors );
|
779 |
-
|
780 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
781 |
-
|
782 |
-
$coauthors = coauthors_wp_list_authors( $args );
|
783 |
-
|
784 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->author1->ID, $this->author1->user_nicename ) . '"', $coauthors, 'Main author link not found.' );
|
785 |
-
$this->assertContains( $this->author1->display_name, $coauthors, 'Main author name not found.' );
|
786 |
-
|
787 |
-
// Here we are checking author name should not be more then one time.
|
788 |
-
// Asserting ">{$this->author1->display_name}<" because "$this->author1->display_name" can be multiple times like in href, title, etc.
|
789 |
-
$this->assertEquals( 1, substr_count( $coauthors, ">{$this->author1->display_name}<" ) );
|
790 |
-
|
791 |
-
$this->assertContains( '</li><li>', $coauthors, 'Coauthors name separator is not matched.' );
|
792 |
-
$this->assertContains( 'href="' . get_author_posts_url( $this->editor1->ID, $this->editor1->user_nicename ) . '"', $coauthors, 'Coauthor link not found.' );
|
793 |
-
$this->assertContains( $this->editor1->display_name, $coauthors, 'Coauthor name not found.' );
|
794 |
-
|
795 |
-
// Here we are checking editor name should not be more then one time.
|
796 |
-
// Asserting ">{$this->editor1->display_name}<" because "$this->editor1->display_name" can be multiple times like in href, title, etc.
|
797 |
-
$this->assertEquals( 1, substr_count( $coauthors, ">{$this->editor1->display_name}<" ) );
|
798 |
-
}
|
799 |
-
|
800 |
-
/**
|
801 |
-
* Checks all the co-authors of the blog with optioncount option.
|
802 |
-
*
|
803 |
-
* @covers ::coauthors_wp_list_authors()
|
804 |
-
*/
|
805 |
-
public function test_coauthors_wp_list_authors_for_optioncount() {
|
806 |
-
|
807 |
-
$this->assertContains( '(' . count_user_posts( $this->author1->ID ) . ')', coauthors_wp_list_authors( array(
|
808 |
-
'echo' => false,
|
809 |
-
'optioncount' => true,
|
810 |
-
) ) );
|
811 |
-
}
|
812 |
-
|
813 |
-
/**
|
814 |
-
* Checks all the co-authors of the blog with show_fullname option.
|
815 |
-
*
|
816 |
-
* @covers ::coauthors_wp_list_authors()
|
817 |
-
*/
|
818 |
-
public function test_coauthors_wp_list_authors_for_show_fullname() {
|
819 |
-
|
820 |
-
$args = array(
|
821 |
-
'echo' => false,
|
822 |
-
'show_fullname' => true,
|
823 |
-
);
|
824 |
-
|
825 |
-
$this->assertContains( $this->author1->display_name, coauthors_wp_list_authors( $args ) );
|
826 |
-
|
827 |
-
$user = $this->factory->user->create_and_get( array(
|
828 |
-
'first_name' => 'First',
|
829 |
-
'last_name' => 'Last',
|
830 |
-
) );
|
831 |
-
|
832 |
-
$this->factory->post->create( array(
|
833 |
-
'post_author' => $user->ID,
|
834 |
-
) );
|
835 |
-
|
836 |
-
$this->assertContains( "{$user->user_firstname} {$user->user_lastname}", coauthors_wp_list_authors( $args ) );
|
837 |
-
}
|
838 |
-
|
839 |
-
/**
|
840 |
-
* Checks all the co-authors of the blog with hide_empty option.
|
841 |
-
*
|
842 |
-
* @covers ::coauthors_wp_list_authors()
|
843 |
-
*/
|
844 |
-
public function test_coauthors_wp_list_authors_for_hide_empty() {
|
845 |
-
|
846 |
-
global $coauthors_plus;
|
847 |
-
|
848 |
-
$coauthors_plus->guest_authors->create( array(
|
849 |
-
'user_login' => 'author2',
|
850 |
-
'display_name' => 'author2',
|
851 |
-
) );
|
852 |
-
|
853 |
-
$this->assertContains( 'author2', coauthors_wp_list_authors( array(
|
854 |
-
'echo' => false,
|
855 |
-
'hide_empty' => false,
|
856 |
-
) ) );
|
857 |
-
}
|
858 |
-
|
859 |
-
/**
|
860 |
-
* Checks all the co-authors of the blog with feed option.
|
861 |
-
*
|
862 |
-
* @covers ::coauthors_wp_list_authors()
|
863 |
-
*/
|
864 |
-
public function test_coauthors_wp_list_authors_for_feed() {
|
865 |
-
|
866 |
-
$feed_text = 'link to feed';
|
867 |
-
$coauthors = coauthors_wp_list_authors( array(
|
868 |
-
'echo' => false,
|
869 |
-
'feed' => $feed_text,
|
870 |
-
) );
|
871 |
-
|
872 |
-
$this->assertContains( esc_url( get_author_feed_link( $this->author1->ID ) ), $coauthors );
|
873 |
-
$this->assertContains( $feed_text, $coauthors );
|
874 |
-
}
|
875 |
-
|
876 |
-
/**
|
877 |
-
* Checks all the co-authors of the blog with feed_image option.
|
878 |
-
*
|
879 |
-
* @covers ::coauthors_wp_list_authors()
|
880 |
-
*/
|
881 |
-
public function test_coauthors_wp_list_authors_for_feed_image() {
|
882 |
-
|
883 |
-
$feed_image = WP_TESTS_DOMAIN . '/path/to/a/graphic.png';
|
884 |
-
$coauthors = coauthors_wp_list_authors( array(
|
885 |
-
'echo' => false,
|
886 |
-
'feed_image' => $feed_image,
|
887 |
-
) );
|
888 |
-
|
889 |
-
$this->assertContains( esc_url( get_author_feed_link( $this->author1->ID ) ), $coauthors );
|
890 |
-
$this->assertContains( $feed_image, $coauthors );
|
891 |
-
}
|
892 |
-
|
893 |
-
/**
|
894 |
-
* Checks all the co-authors of the blog with feed_type option.
|
895 |
-
*
|
896 |
-
* @covers ::coauthors_wp_list_authors()
|
897 |
-
*/
|
898 |
-
public function test_coauthors_wp_list_authors_for_feed_type() {
|
899 |
-
|
900 |
-
$feed_type = 'atom';
|
901 |
-
$feed_text = 'link to feed';
|
902 |
-
$coauthors = coauthors_wp_list_authors( array(
|
903 |
-
'echo' => false,
|
904 |
-
'feed_type' => $feed_type,
|
905 |
-
'feed' => $feed_text,
|
906 |
-
) );
|
907 |
-
|
908 |
-
$this->assertContains( esc_url( get_author_feed_link( $this->author1->ID, $feed_type ) ), $coauthors );
|
909 |
-
$this->assertContains( $feed_type, $coauthors );
|
910 |
-
$this->assertContains( $feed_text, $coauthors );
|
911 |
-
}
|
912 |
-
|
913 |
-
/**
|
914 |
-
* Checks all the co-authors of the blog with style option.
|
915 |
-
*
|
916 |
-
* @covers ::coauthors_wp_list_authors()
|
917 |
-
*/
|
918 |
-
public function test_coauthors_wp_list_authors_for_style() {
|
919 |
-
|
920 |
-
$coauthors = coauthors_wp_list_authors( array(
|
921 |
-
'echo' => false,
|
922 |
-
'style' => 'none',
|
923 |
-
) );
|
924 |
-
|
925 |
-
$this->assertNotContains( '<li>', $coauthors );
|
926 |
-
$this->assertNotContains( '</li>', $coauthors );
|
927 |
-
}
|
928 |
-
|
929 |
-
/**
|
930 |
-
* Checks all the co-authors of the blog with html option.
|
931 |
-
*
|
932 |
-
* @covers ::coauthors_wp_list_authors()
|
933 |
-
*/
|
934 |
-
public function test_coauthors_wp_list_authors_for_html() {
|
935 |
-
|
936 |
-
global $coauthors_plus;
|
937 |
-
|
938 |
-
$args = array(
|
939 |
-
'echo' => false,
|
940 |
-
'html' => false,
|
941 |
-
);
|
942 |
-
|
943 |
-
$this->assertEquals( $this->author1->display_name, coauthors_wp_list_authors( $args ) );
|
944 |
-
|
945 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $this->editor1->user_login ), true );
|
946 |
-
|
947 |
-
$this->assertEquals( "{$this->author1->display_name}, {$this->editor1->display_name}", coauthors_wp_list_authors( $args ) );
|
948 |
-
}
|
949 |
-
|
950 |
-
/**
|
951 |
-
* Checks all the co-authors of the blog with guest_authors_only option.
|
952 |
-
*
|
953 |
-
* @covers ::coauthors_wp_list_authors()
|
954 |
-
*/
|
955 |
-
public function test_coauthors_wp_list_authors_for_guest_authors_only() {
|
956 |
-
|
957 |
-
global $coauthors_plus;
|
958 |
-
|
959 |
-
$args = array(
|
960 |
-
'echo' => false,
|
961 |
-
'guest_authors_only' => true,
|
962 |
-
);
|
963 |
-
|
964 |
-
$this->assertEmpty( coauthors_wp_list_authors( $args ) );
|
965 |
-
|
966 |
-
$guest_author_id = $coauthors_plus->guest_authors->create( array(
|
967 |
-
'user_login' => 'author2',
|
968 |
-
'display_name' => 'author2',
|
969 |
-
) );
|
970 |
-
|
971 |
-
$this->assertEmpty( coauthors_wp_list_authors( $args ) );
|
972 |
-
|
973 |
-
$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id );
|
974 |
-
|
975 |
-
$coauthors_plus->add_coauthors( $this->post->ID, array( $guest_author->user_login ), true );
|
976 |
-
|
977 |
-
$this->assertContains( $guest_author->display_name, coauthors_wp_list_authors( $args ) );
|
978 |
-
}
|
979 |
-
|
980 |
-
/**
|
981 |
-
* Checks co-author's avatar.
|
982 |
-
*
|
983 |
-
* @covers ::coauthors_get_avatar()
|
984 |
-
*/
|
985 |
-
public function test_coauthors_get_avatar_default() {
|
986 |
-
|
987 |
-
$this->assertEmpty( coauthors_get_avatar( $this->author1->ID ) );
|
988 |
-
$this->assertEquals( preg_match( "|^<img alt='[^']*' src='[^']*' srcset='[^']*' class='[^']*' height='[^']*' width='[^']*' />$|", coauthors_get_avatar( $this->author1 ) ), 1 );
|
989 |
-
}
|
990 |
-
|
991 |
-
/**
|
992 |
-
* Checks co-author's avatar when author is a guest author.
|
993 |
-
*
|
994 |
-
* @covers ::coauthors_get_avatar()
|
995 |
-
*/
|
996 |
-
public function test_coauthors_get_avatar_when_guest_author() {
|
997 |
-
|
998 |
-
global $coauthors_plus;
|
999 |
-
|
1000 |
-
$guest_author_id = $coauthors_plus->guest_authors->create( array(
|
1001 |
-
'user_login' => 'author2',
|
1002 |
-
'display_name' => 'author2',
|
1003 |
-
) );
|
1004 |
-
|
1005 |
-
$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id );
|
1006 |
-
|
1007 |
-
$this->assertEquals( preg_match( "|^<img alt='[^']*' src='[^']*' srcset='[^']*' class='[^']*' height='[^']*' width='[^']*' />$|", coauthors_get_avatar( $guest_author ) ), 1 );
|
1008 |
-
|
1009 |
-
$filename = rand_str() . '.jpg';
|
1010 |
-
$contents = rand_str();
|
1011 |
-
$upload = wp_upload_bits( $filename, null, $contents );
|
1012 |
-
|
1013 |
-
$this->assertTrue( empty( $upload['error'] ) );
|
1014 |
-
|
1015 |
-
$attachment_id = $this->_make_attachment( $upload );
|
1016 |
-
|
1017 |
-
set_post_thumbnail( $guest_author->ID, $attachment_id );
|
1018 |
-
|
1019 |
-
$avatar = coauthors_get_avatar( $guest_author );
|
1020 |
-
$attachment_url = wp_get_attachment_url( $attachment_id );
|
1021 |
-
|
1022 |
-
$this->assertContains( $filename, $avatar );
|
1023 |
-
$this->assertContains( 'src="' . $attachment_url . '"', $avatar );
|
1024 |
-
}
|
1025 |
-
|
1026 |
-
/**
|
1027 |
-
* Checks co-author's avatar when user's email is not set somehow.
|
1028 |
-
*
|
1029 |
-
* @covers ::coauthors_get_avatar()
|
1030 |
-
*/
|
1031 |
-
public function test_coauthors_get_avatar_when_user_email_not_set() {
|
1032 |
-
|
1033 |
-
global $coauthors_plus;
|
1034 |
-
|
1035 |
-
$guest_author_id = $coauthors_plus->guest_authors->create( array(
|
1036 |
-
'user_login' => 'author2',
|
1037 |
-
'display_name' => 'author2',
|
1038 |
-
) );
|
1039 |
-
|
1040 |
-
$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'id', $guest_author_id );
|
1041 |
-
|
1042 |
-
unset( $guest_author->user_email );
|
1043 |
-
|
1044 |
-
$this->assertEmpty( coauthors_get_avatar( $guest_author ) );
|
1045 |
-
}
|
1046 |
-
|
1047 |
-
/**
|
1048 |
-
* Checks co-author's avatar with size.
|
1049 |
-
*
|
1050 |
-
* @covers ::coauthors_get_avatar()
|
1051 |
-
*/
|
1052 |
-
public function test_coauthors_get_avatar_size() {
|
1053 |
-
|
1054 |
-
$size = '100';
|
1055 |
-
$this->assertEquals( preg_match( "|^<img .*height='$size'.*width='$size'|", coauthors_get_avatar( $this->author1, $size ) ), 1 );
|
1056 |
-
}
|
1057 |
-
|
1058 |
-
/**
|
1059 |
-
* Checks co-author's avatar with alt.
|
1060 |
-
*
|
1061 |
-
* @covers ::coauthors_get_avatar()
|
1062 |
-
*/
|
1063 |
-
public function test_coauthors_get_avatar_alt() {
|
1064 |
-
|
1065 |
-
$alt = 'Test';
|
1066 |
-
$this->assertEquals( preg_match( "|^<img alt='$alt'|", coauthors_get_avatar( $this->author1, 96, '', $alt ) ), 1 );
|
1067 |
-
}
|
1068 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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