/** * Construct object * * @since 1.1.0 * * @param |WP_Post|integer $post */ public function __construct($post) { $this->meta_key = \ingot\testing\utility\posts::meta_key(); $this->set_post($post); if ($this->post) { $this->set_groups(); } }
/** * Update the post/group association when saving posts * * @since 1.1.0 * * @param int $id * @param \WP_Post $post */ public function track_groups($id, $post) { posts::update_groups_in_post($post); }
/** * Test that we can find query by associated post/group * * @since 1.1.0 * * @group group * @group objects * @group posts_object * * @covers ingot\testing\utility\posts::posts_by_group() */ public function testQueryByGroup() { $this->factory->post->create(['post_title' => rand(), 'post_content' => 'x']); for ($i = 5; $i <= 10; $i++) { for ($x = 0; $x <= 2; $x++) { $title = 'gr_' . $i; $id = get_post($this->factory->post->create(['post_title' => $title, 'post_content' => '!'])); $obj = new \ingot\testing\object\posts(get_post($id)); $obj->add($i); } $query = \ingot\testing\utility\posts::posts_by_group([$i]); $this->assertTrue(is_a($query, 'WP_Query')); $this->assertTrue($query->have_posts(), var_export($i)); $this->assertSame(3, $query->post_count); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame($title, $query->post->post_title); } } if (7 == $i) { $obj->add(88); $query = \ingot\testing\utility\posts::posts_by_group([7, 88]); $this->assertTrue(is_a($query, 'WP_Query')); $this->assertTrue($query->have_posts(), var_export($i)); $this->assertSame(3, $query->post_count); } } $query = \ingot\testing\utility\posts::posts_by_group([5, 6, 7, 8, 9]); $this->assertTrue($query->have_posts()); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame('!', $query->post->post_content); } } $query = \ingot\testing\utility\posts::posts_by_group([5, 6, 9]); $this->assertTrue($query->have_posts()); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $this->assertSame('!', $query->post->post_content); } } }