-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ reset-install: | |
--admin_password=admin \ | ||
[email protected] \ | ||
--skip-email | ||
@$(CLI) plugin install woocommerce --activate --version=7.9.0 | ||
@$(CLI) plugin install woocommerce --activate --version=8.9.3 | ||
@$(CLI) plugin install wordpress-importer --activate | ||
|
||
reset-posts: | ||
|
@@ -57,6 +57,10 @@ reset-woocommerce: | |
@$(CLI) post meta set 22 related_product 18 | ||
@$(CLI) post meta set 24 related_product 26 | ||
@$(CLI) post meta set 26 related_product 37 | ||
@$(CLI) comment create --comment_post_ID=15 --comment_content="I love this hoodie" --comment_author="John" --comment_type="review" | ||
@$(CLI) comment create --comment_post_ID=19 --comment_content="Awesome belt!" --comment_author="Jane" --comment_type="review" | ||
@$(CLI) comment meta set 2 rating "5" | ||
@$(CLI) comment meta set 3 rating "4" | ||
|
||
.PHONY: test | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Williarin\WordpressInterop\Bridge\Entity; | ||
|
||
use AllowDynamicProperties; | ||
use DateTimeInterface; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
use Williarin\WordpressInterop\Attributes\Id; | ||
use Williarin\WordpressInterop\Attributes\RepositoryClass; | ||
use Williarin\WordpressInterop\Bridge\Repository\CommentRepository; | ||
|
||
#[AllowDynamicProperties] | ||
#[RepositoryClass(CommentRepository::class)] | ||
class Comment | ||
{ | ||
use DynamicPropertiesTrait; | ||
|
||
#[Id] | ||
#[Groups('base')] | ||
public ?int $commentId = null; | ||
|
||
#[Groups('base')] | ||
public ?int $commentPostId = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentAuthor = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentAuthorEmail = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentAuthorUrl = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentAuthorIp = null; | ||
|
||
#[Groups('base')] | ||
public ?DateTimeInterface $commentDate = null; | ||
|
||
#[Groups('base')] | ||
public ?DateTimeInterface $commentDateGmt = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentContent = null; | ||
|
||
#[Groups('base')] | ||
public ?int $commentKarma = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentApproved = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentAgent = null; | ||
|
||
#[Groups('base')] | ||
public ?string $commentType = null; | ||
|
||
#[Groups('base')] | ||
public ?int $commentParent = null; | ||
|
||
#[Groups('base')] | ||
public ?int $userId = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Williarin\WordpressInterop\Bridge\Repository; | ||
|
||
use Williarin\WordpressInterop\Bridge\Entity\Comment; | ||
|
||
class CommentRepository extends AbstractEntityRepository | ||
{ | ||
protected const TABLE_NAME = 'comments'; | ||
protected const TABLE_META_NAME = 'commentmeta'; | ||
protected const TABLE_IDENTIFIER = 'comment_id'; | ||
protected const TABLE_META_IDENTIFIER = 'comment_id'; | ||
protected const FALLBACK_ENTITY = Comment::class; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(Comment::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Bridge\Repository; | ||
|
||
use Williarin\WordpressInterop\Bridge\Entity\Comment; | ||
use Williarin\WordpressInterop\Bridge\Repository\RepositoryInterface; | ||
use Williarin\WordpressInterop\Bridge\Repository\CommentRepository; | ||
use Williarin\WordpressInterop\Criteria\SelectColumns; | ||
use Williarin\WordpressInterop\Test\TestCase; | ||
|
||
use function Williarin\WordpressInterop\Util\String\select_from_eav; | ||
|
||
class CommentRepositoryTest extends TestCase | ||
{ | ||
/** @var CommentRepository */ | ||
private RepositoryInterface $repository; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->repository = $this->manager->getRepository(Comment::class); | ||
} | ||
|
||
public function testFind(): void | ||
{ | ||
$term = $this->repository->find(1); | ||
|
||
self::assertInstanceOf(Comment::class, $term); | ||
} | ||
|
||
public function testFindByAttribute(): void | ||
{ | ||
$comments = $this->repository | ||
->setOptions([ | ||
'allow_extra_properties' => true, | ||
]) | ||
->findBy([ | ||
new SelectColumns(['comment_id', 'comment_post_id', select_from_eav('rating', 'rating')]), | ||
'rating' => '5', | ||
]); | ||
|
||
self::assertContainsOnlyInstancesOf(Comment::class, $comments); | ||
self::assertCount(1, $comments); | ||
self::assertSame(2, $comments[0]->commentId); | ||
self::assertSame('5', $comments[0]->rating); | ||
self::assertSame(15, $comments[0]->commentPostId); | ||
} | ||
|
||
public function testFindOneByWithSelectedAttribute(): void | ||
{ | ||
$comments = $this->repository | ||
->setOptions([ | ||
'allow_extra_properties' => true, | ||
]) | ||
->findBy([ | ||
new SelectColumns(['comment_id', 'comment_post_id', select_from_eav('rating', 'rating')]), | ||
]); | ||
|
||
self::assertContainsOnlyInstancesOf(Comment::class, $comments); | ||
self::assertCount(3, $comments); | ||
self::assertNull($comments[0]->rating); | ||
self::assertSame('5', $comments[1]->rating); | ||
self::assertSame('4', $comments[2]->rating); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters