forked from corcel/acf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelationalFieldsTest.php
More file actions
66 lines (56 loc) · 1.77 KB
/
Copy pathRelationalFieldsTest.php
File metadata and controls
66 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
use Corcel\Acf\Field\PageLink;
use Corcel\Acf\Field\PostObject;
use Corcel\Acf\Field\Term;
use Corcel\Acf\Field\User;
use Corcel\Model\Post;
/**
* Class RelationalFieldsTests.
*
* @author Junior Grossi <juniorgro@gmail.com>
*/
class RelationalFieldsTests extends PHPUnit\Framework\TestCase
{
/**
* @var Post
*/
protected $post;
protected function setUp(): void
{
$this->post = Post::find(56);
}
public function testPostObjectField()
{
$object = new PostObject($this->post);
$object->process('fake_post_object');
$this->assertEquals('ACF Basic Fields', $object->get()->post_title);
}
public function testPageLinkField()
{
$page = new PageLink($this->post);
$page->process('fake_page_link');
$this->assertEquals('http://wordpress.corcel.dev/acf-content-fields/', $page->get());
}
public function testRelationshipField()
{
$relation = new PostObject($this->post);
$relation->process('fake_relationship');
$posts = $relation->get();
$this->assertEquals([44, 56], $posts->pluck('ID')->toArray());
}
public function testTaxonomyField()
{
$relation = new Term($this->post);
$relation->process('fake_taxonomy'); // multiple (Collection)
$this->assertEquals('uncategorized', $relation->get()->first()->slug);
$relation->process('fake_taxonomy_single'); // single (Corcel\Term)
$this->assertEquals('uncategorized', $relation->get()->slug);
}
public function testUserField()
{
$user = new User($this->post);
$user->process('fake_user');
$this->assertEquals('admin', $user->get()->user_login);
$this->assertEquals('admin', $user->get()->nickname);
}
}