Skip to content

Commit

Permalink
fix missing argument to load
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellopez authored and esamattis committed Jun 12, 2020
1 parent ccf0874 commit 3f0a3ee
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function save( $query_id, $query, $name = 'UnnamedQuery' ) {
}

// Check to see if the query has already been persisted. If so, we're done.
if ( ! empty( $this->load( $query_id ) ) ) {
if ( ! empty( $this->load( $query_id, $name ) ) ) {
return;
}

Expand Down
43 changes: 43 additions & 0 deletions tests/wpunit/LockTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
<?php

use WPGraphQL\Extensions\Lock\Settings;

class LockTest extends \Codeception\TestCase\WPTestCase
{
/**
* @var \WpunitTester
*/
protected $tester;

private $recording;

private function enableRecording(): void
{
$recording_option_name = Settings::get_option_name('recording');
$this->recording = get_option($recording_option_name);
update_option($recording_option_name, true);
}

private function resetRecording(): void
{
$recording_option_name = Settings::get_option_name('recording');
update_option($recording_option_name, $this->recording);
$this->recording = null;
}

public function setUp(): void
{
// Before...
Expand All @@ -29,6 +47,31 @@ public function testQueryPostTypeIsRegistered()
$this->assertArrayHasKey('graphql_query', $post_types);
}

public function testCanSavePost()
{
$this->enableRecording();

$lockLoader = new \WPGraphQL\Extensions\Lock\Loader();
$query_id = 'testCanSavePost';
$query = 'query testCanSavePost {
posts {
nodes {
title
}
}
}';
$operation_name = 'testCanSavePost';
$lockLoader->save($query_id, $query, $operation_name);

$this->resetRecording();

$result = $lockLoader->load($query_id, $operation_name);

$expected = $query;

$this->assertEquals($expected, $result);
}


public function testCanCallFromPHP()
{
Expand Down

0 comments on commit 3f0a3ee

Please sign in to comment.