Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitriBouteille committed May 20, 2024
1 parent 09c1666 commit 6bd7bb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
35 changes: 15 additions & 20 deletions tests/WordPress/Orm/AbstractModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AbstractModelTest extends TestCase
* @covers ::saveOrFail
* @dataProvider providerTestSaveNewObject
*/
public function testSuccessNSaveNewObject(string $saveMethod): void
public function testSuccessSaveNewObject(string $saveMethod): void
{
$model = new Article();
$model->setPostName('hello-world');
Expand Down Expand Up @@ -205,38 +205,31 @@ public function testUpsertWithExistingObjects(): void
*/
public function testUpsertWithUpdateKey(): void
{
$objetId = self::factory()->post->create([
'post_type' => 'product',
'post_name' => 'salomon-lab',
'post_status' => 'private',
'post_title' => 'Salomon Lab X.',
]);
add_option('store_latitude', 75.652, autoload: 'yes');

Post::upsert(
Option::upsert(
[
[
'post_name' => 'salomon-lab',
'post_status' => 'publish',
'post_title' => 'Hello world',
'option_name' => 'store_latitude',
'option_value' => 40.111,
'autoload' => 'no',
],
],
'post_name',
['post_status']
['option_name'],
['autoload']
);

$post = Post::findOneByName('salomon-lab');
$this->assertInstanceOf(Post::class, $post);
$this->assertEquals($objetId, $post->getId());
$this->assertEquals('publish', $post->getPostStatus(), 'The post status will be updated.');
$this->assertEquals('Salomon Lab X.', $post->getPostTitle(), 'The post title must be not updated.');
// Check if value is not update updated
$option = $this->checkUpsertOption('store_latitude', 75.652);
$this->assertEquals('no', $option?->getAutoload());
}

/**
* @param string $optionName
* @param string $expectedValue
* @return void
* @return Option|null
*/
private function checkUpsertOption(string $optionName, string $expectedValue): void
private function checkUpsertOption(string $optionName, string $expectedValue): ?Option
{
$option = Option::findOneByName($optionName);
$this->assertInstanceOf(Option::class, $option);
Expand All @@ -245,5 +238,7 @@ private function checkUpsertOption(string $optionName, string $expectedValue): v
\wp_cache_delete('alloptions', 'options');
$wpOpt = \get_option($optionName);
$this->assertEquals($expectedValue, $wpOpt);

return $option;
}
}
1 change: 0 additions & 1 deletion tests/WordPress/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function assertLastQueryEqual(string $query): void
public function assertPostEqualToWpObject(?Post $model, ?\WP_Post $wpPost): void
{
self::assertInstanceOf(\WP_Post::class, $wpPost);
self::assertInstanceOf(Post::class, $wpPost);

self::assertEquals($wpPost->ID, $model->getId());
self::assertEquals($wpPost->post_type, $model->getPostType());
Expand Down

0 comments on commit 6bd7bb7

Please sign in to comment.