Skip to content

Update tests and documentation for Term::posts()#1931

Merged
gchtr merged 14 commits intomasterfrom
docs/term
Apr 24, 2019
Merged

Update tests and documentation for Term::posts()#1931
gchtr merged 14 commits intomasterfrom
docs/term

Conversation

@gchtr
Copy link
Copy Markdown
Member

@gchtr gchtr commented Feb 22, 2019

Ticket: #1917

Issue

The documentation for Term::posts() could need some love. Currently, it’s quite hard what the function accepts without having a very close look at the code.

Solution

Add more documentation.

Impact

Everybody happy.

Usage Changes

None.

Considerations

For 2.x, we could still consider to change the 1st and 2nd parameters so that they don’t accept different values (like "either post type or class"). Again, I suggest an arguments array that we also applied in #1845.

Testing

None.

@gchtr gchtr requested a review from palmiak February 22, 2019 23:37
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 23, 2019

Codecov Report

Merging #1931 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1931   +/-   ##
=========================================
  Coverage     95.04%   95.04%           
  Complexity     1555     1555           
=========================================
  Files            48       48           
  Lines          3670     3670           
=========================================
  Hits           3488     3488           
  Misses          182      182
Impacted Files Coverage Δ Complexity Δ
lib/Term.php 97.18% <ø> (ø) 57 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 255e912...08b195c. Read the comment docs.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 23, 2019

Codecov Report

Merging #1931 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1931   +/-   ##
=========================================
  Coverage     94.98%   94.98%           
  Complexity     1565     1565           
=========================================
  Files            49       49           
  Lines          3689     3689           
=========================================
  Hits           3504     3504           
  Misses          185      185
Impacted Files Coverage Δ Complexity Δ
lib/Term.php 97.18% <100%> (ø) 57 <10> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b78e929...22af873. Read the comment docs.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 94.322% when pulling 08b195c on docs/term into 255e912 on master.

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 23, 2019

Coverage Status

Coverage remained the same at 94.324% when pulling 1a8aa94 on docs/term into e663dee on master.

@palmiak
Copy link
Copy Markdown
Collaborator

palmiak commented Feb 24, 2019

It's much clearer now 👍

As I written in the comments I'm not sure about one thing in get_posts - if I would like to use:

term.posts( { posts_per_page: 5, orderby: 'menu_order' }, 'page', `myClass` )

and I have class page user might think it should works like this:

  • post_type will be set to page
  • postClass will be set to myClass
    but it won't. It will use:
  • post_type post
  • postClass page

I think there should be some extra logic:

if ( $PostClass == '' && class_exists($post_type) ) {
	$PostClass = $post_type;
}

and

if ( $post_type != '' ){
    $args['post_type'] = $post_type;
} elseif ( $post_type == '' && !isset($args['post_type']) ) {
    $args['post_type'] = 'any';
} 

or am I overthinking this?

@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Mar 3, 2019

@palmiak You are right! The logic that you described doesn’t work. I added some more tests to cover the different use cases. I think the reason that your use case fails is that in Timber, there’s a somewhat hidden logic that automatically uses a class for a post when it has the same name as the requested post type (as described in #799 (comment)).

So when there’s a class page and we select the post type page, Timber::get_posts() will always use the page class, no matter what we pass in the third parameter of Term::posts(). Even if we would change the logic with your suggestions. But this is probably a use case most uses will very rarely run into. To me, that behavior seems intended, though I think it’s too much magic.

It’s also something that might change with object factories, according to @pascalknecht.

@palmiak
Copy link
Copy Markdown
Collaborator

palmiak commented Mar 3, 2019

@gchtr I fully understand. I think that for now we won't make it any better. Let's wait for @pascalknecht change and then we'll think should what to do next.

Great work as always Lukas 👍

@gchtr gchtr self-assigned this Mar 4, 2019
@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Mar 5, 2019

Some tests failed because of some autoloading issue. I submitted #1940 to fix that.

@gchtr gchtr changed the title Update documentation for Term::posts() Update tests and documentation for Term::posts() Mar 5, 2019
@gchtr gchtr self-assigned this Mar 8, 2019
@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Mar 8, 2019

@palmiak Now the tests work! I’d still need an approving review from you to be able to merge this 😉.

@palmiak
Copy link
Copy Markdown
Collaborator

palmiak commented Mar 8, 2019 via email

@gchtr gchtr requested a review from jarednova as a code owner March 20, 2019 21:21
@gchtr gchtr requested a review from palmiak April 4, 2019 17:51
@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Apr 24, 2019

Could @jarednova or @palmiak approve this pull request so I can finally merge it? 😉

Copy link
Copy Markdown
Collaborator

@palmiak palmiak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything was ok before. Just forgot the formal approval.

@gchtr gchtr merged commit 4a7ff12 into master Apr 24, 2019
@gchtr gchtr deleted the docs/term branch April 24, 2019 19:20
@jarednova
Copy link
Copy Markdown
Member

Thanks @gchtr and @palmiak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants