From 3abf3045541dfc12e3d95f014799fd81a24dff60 Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Tue, 11 Feb 2020 12:29:29 +0200 Subject: [PATCH] Ensure terms translations can be fetched with IDs --- src/TermObject.php | 2 +- tests/wpunit/TermObjectQueryTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/TermObject.php b/src/TermObject.php index bd35283..ef25c84 100644 --- a/src/TermObject.php +++ b/src/TermObject.php @@ -172,7 +172,7 @@ function ($term_id, $args) { continue; } - $terms[] = $translation; + $terms[] = new \WPGraphQL\Model\Term($translation); } return $terms; diff --git a/tests/wpunit/TermObjectQueryTest.php b/tests/wpunit/TermObjectQueryTest.php index da5e502..e605bf4 100644 --- a/tests/wpunit/TermObjectQueryTest.php +++ b/tests/wpunit/TermObjectQueryTest.php @@ -160,6 +160,31 @@ public function testCanFetchTranslatedTermVersions() $this->assertEquals($expected, $data['data']['tags']['nodes']); } + public function testCanFetchTranslatedTermVersionsWithIds() + { + pll_save_term_translations([ + 'en' => $this->en_term_id, + 'fi' => $this->fi_term_id, + ]); + + $query = " + query Tags { + tags { + nodes { + name + translations { + id + } + } + } + } + "; + + $data = do_graphql_request($query); + $this->assertArrayNotHasKey('errors', $data, print_r($data, true)); + + } + public function testCanFetchSpecificTranslatedVersion() { pll_save_term_translations([