<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[44497] trunk/tests/phpunit/includes/factory: Docs: Add docblocks for the PHPUnit factory objects.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/44497">44497</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/44497","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-01-09 05:43:14 +0000 (Wed, 09 Jan 2019)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Add docblocks for the PHPUnit factory objects.
Props andizer.
Fixes <a href="https://core.trac.wordpress.org/ticket/44521">#44521</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactorycallbackaftercreatephp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforattachmentphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforblogphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforcommentphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforpostphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryfortermphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforthingphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php</a></li>
<li><a href="#trunktestsphpunitincludesfactoryclasswpunittestfactoryforuserphp">trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactorycallbackaftercreatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,12 +1,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_UnitTest_Factory_Callback_After_Create {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @var callable
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> var $callback;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * WP_UnitTest_Factory_Callback_After_Create constructor.
+ *
+ * @param callable $callback A callback function.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function __construct( $callback ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->callback = $callback;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Calls the set callback on given object.
+ *
+ * @param mixed $object The object to apply the callback on.
+ *
+ * @return mixed The possibly altered object.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function call( $object ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return call_user_func( $this->callback, $object );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforattachmentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -12,7 +12,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $file Path of the attached file.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $legacy_parent Deprecated.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $legacy_args Deprecated
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $legacy_args Deprecated.
+ *
+ * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Backward compatibility for legacy argument format.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -34,6 +36,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Saves an attachment.
+ *
+ * @param string $file The file name to create attachment object for.
+ * @param int $parent The post id to attach the file to.
+ *
+ * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_upload_object( $file, $parent = 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $contents = file_get_contents( $file );
</span><span class="cx" style="display: block; padding: 0 10px"> $upload = wp_upload_bits( basename( $file ), null, $contents );
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforblogphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,6 +23,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates a blog object.
+ *
+ * @param array $args Arguments for the site object.
+ *
+ * @return int|WP_Error Returns WP_Error object on failure, the site ID on success.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> $meta = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,8 +45,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $blog;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Updates a blog object. Not implemented.
+ *
+ * @param int $blog_id The blog id to update.
+ * @param array $fields The fields to update.
+ *
+ * @return void
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function update_object( $blog_id, $fields ) {}
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves a site by given blog id.
+ *
+ * @param int $blog_id The blog id to retrieve.
+ *
+ * @return null|WP_Site The site object or null if not found.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function get_object_by_id( $blog_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_site( $blog_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforcommentphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,20 +22,52 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Inserts a comment.
+ *
+ * @param array $args The comment details.
+ *
+ * @return false|int The comment's ID on success, false on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_insert_comment( $this->addslashes_deep( $args ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Updates a comment.
+ *
+ * @param int $comment_id The comment id.
+ * @param array $fields The comment details.
+ *
+ * @return int When updated 1, not update 0.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function update_object( $comment_id, $fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $fields['comment_ID'] = $comment_id;
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_update_comment( $this->addslashes_deep( $fields ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates multiple comments on given post.
+ *
+ * @param int $post_id The post id to create comments for.
+ * @param int $count Total amount of comments to create.
+ * @param array $args The comment details.
+ * @param null $generation_definitions Default values.
+ *
+ * @return int[] Array with the comment ids.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $args['comment_post_ID'] = $post_id;
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->create_many( $count, $args, $generation_definitions );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Returns a comment.
+ *
+ * @param int $comment_id The comment id.
+ *
+ * @return null|WP_Comment WP_Comment when found, null when not found.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function get_object_by_id( $comment_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_comment( $comment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforpostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,15 +23,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates a post object.
+ *
+ * @param array $args Array with elements for the post.
+ *
+ * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_insert_post( $args );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Updates an existing post object.
+ *
+ * @param int $post_id The post id to update.
+ * @param array $fields Post data.
+ *
+ * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function update_object( $post_id, $fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $fields['ID'] = $post_id;
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_update_post( $fields );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves a object by an id.
+ *
+ * @param int $post_id The post id to update.
+ *
+ * @return null|WP_Post WP_Post on success or null on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function get_object_by_id( $post_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_post( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryfortermphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -24,6 +24,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates a term object.
+ *
+ * @param array $args Array or string of arguments for inserting a term.
+ *
+ * @return array|WP_Error
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args );
</span><span class="cx" style="display: block; padding: 0 10px"> $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,6 +40,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $term_id_pair['term_id'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Updates the term.
+ *
+ * @param int|object $term The term to update.
+ * @param array|string $fields The context in which to relate the term to the object.
+ *
+ * @return int The term id.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function update_object( $term, $fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_object( $term ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,12 +57,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $term_id_pair['term_id'];
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Attach terms on the given post.
+ *
+ * @param int $post_id The Post ID.
+ * @param string|array $terms An array of terms to set for the post, or a string of terms
+ * separated by commas. Hierarchical taxonomies must always pass IDs rather
+ * than names so that children with the same names but different parents
+ * aren't confused.
+ * @param string $taxonomy Taxonomy name.
+ * @param bool $append Optional. If true, don't delete existing terms, just add on. If false,
+ * replace the terms with the new terms. Default true.
+ *
+ * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_set_post_terms( $post_id, $terms, $taxonomy, $append );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return array|null|WP_Error|WP_Term
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Create a term and returns it as a object.
+ *
+ * @param array $args Array or string of arguments for inserting a term.
+ * @param null $generation_definitions The default values.
+ *
+ * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function create_and_get( $args = array(), $generation_definitions = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $term_id = $this->create( $args, $generation_definitions );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -55,6 +89,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return get_term( $term_id, $taxonomy );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves the term by given term id.
+ *
+ * @param int $term_id The term id to retrieve.
+ *
+ * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function get_object_by_id( $term_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return get_term( $term_id, $this->taxonomy );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforthingphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,9 +21,33 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->default_generation_definitions = $default_generation_definitions;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates an object.
+ *
+ * @param array $args The arguments.
+ *
+ * @return mixed The result. Can be anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> abstract function create_object( $args );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Updates an existing object.
+ *
+ * @param int $object The object id.
+ * @param array $fields The values to update.
+ *
+ * @return mixed The result. Can be anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> abstract function update_object( $object, $fields );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates an object.
+ *
+ * @param array $args Optional. The arguments for the object to create. Default is empty array.
+ * @param null $generation_definitions Optional. The default values for the object. Default is null.
+ *
+ * @return mixed The result. Can be anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create( $args = array(), $generation_definitions = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_null( $generation_definitions ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $generation_definitions = $this->default_generation_definitions;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -45,13 +69,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $created;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates an object and returns its object.
+ *
+ * @param array $args Optional. The arguments for the object to create. Default is empty array.
+ * @param null $generation_definitions Optional. The default values for the object. Default is null.
+ *
+ * @return mixed The created object. Can be anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_and_get( $args = array(), $generation_definitions = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $object_id = $this->create( $args, $generation_definitions );
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->get_object_by_id( $object_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves an object by ID.
+ *
+ * @param int $object_id The object id.
+ *
+ * @return mixed The object. Can be anything.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> abstract function get_object_by_id( $object_id );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Creates multiple objects.
+ *
+ * @param int $count Amount of objects to create.
+ * @param array $args Optional. The arguments for the object to create. Default is empty array.
+ * @param null $generation_definitions Optional. The default values for the object. Default is null.
+ *
+ * @return array
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_many( $count, $args = array(), $generation_definitions = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $results = array();
</span><span class="cx" style="display: block; padding: 0 10px"> for ( $i = 0; $i < $count; $i++ ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -60,6 +108,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $results;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Combines the given argument with the generation_definitions (defaults) and applies
+ * possibly set callbacks on it.
+ *
+ * @param array $args Optional. The arguments to combine with defaults. Default is empty array.
+ * @param array|null $generation_definitions Optional. The defaults. Default is null.
+ * @param array|null $callbacks Optional. Array with callbacks to apply on the fields. Default is null.
+ *
+ * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $callbacks = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_null( $generation_definitions ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,8 +146,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $args;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Applies the callbacks on the created object.
+ *
+ * @param WP_UnitTest_Factory_Callback_After_Create[] $callbacks Array with callback functions.
+ * @param mixed $created The object to apply callbacks for.
+ *
+ * @return array The altered fields.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function apply_callbacks( $callbacks, $created ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $updated_fields = array();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $callbacks as $field_name => $generator ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $updated_fields[ $field_name ] = $generator->call( $created );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -96,10 +164,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $updated_fields;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Instantiates a callback objects for the given function name.
+ *
+ * @param string $function The callback function.
+ *
+ * @return WP_UnitTest_Factory_Callback_After_Create
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function callback( $function ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_UnitTest_Factory_Callback_After_Create( $function );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Adds slashes to the given value.
+ *
+ * @param array|object|string|mixed $value The value to add slashes to.
+ *
+ * @return array|string The value with the possibly applied slashes.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function addslashes_deep( $value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_array( $value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $value = array_map( array( $this, 'addslashes_deep' ), $value );
</span></span></pre></div>
<a id="trunktestsphpunitincludesfactoryclasswpunittestfactoryforuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php 2019-01-09 05:08:25 UTC (rev 44496)
+++ trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php 2019-01-09 05:43:14 UTC (rev 44497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -21,15 +21,37 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Inserts an user.
+ *
+ * @param array $args The user data to insert.
+ *
+ * @return int|WP_Error
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function create_object( $args ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_insert_user( $args );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Updates the user data.
+ *
+ * @param int $user_id The user id to update.
+ * @param array $fields The user data to update.
+ *
+ * @return int|WP_Error User id on success. WP_Error on failure.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function update_object( $user_id, $fields ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $fields['ID'] = $user_id;
</span><span class="cx" style="display: block; padding: 0 10px"> return wp_update_user( $fields );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Retrieves the user for given user id.
+ *
+ * @param int $user_id The user id to get.
+ *
+ * @return WP_User The user.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> function get_object_by_id( $user_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_User( $user_id );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>