markTestSkipped('GraphQL 4 test ' . __CLASS__ . ' skipped'); } } /** * @param bool $list * @dataProvider provideApply */ public function testApply(bool $list) { $query = new ModelQuery( new DataObjectModel(SiteTree::class, new SchemaConfig()), 'testQuery' ); $query->setType($list ? '[SiteTree]' : 'SiteTree'); $plugin = new LinkablePlugin(); $plugin->apply($query, new Schema('test')); $args = $query->getArgs(); $field = $list ? 'links' : 'link'; $this->assertArrayHasKey($field, $args); $this->assertEquals($list ? '[String]' : 'String', $args[$field]->getType()); } public function testResolver() { $page = SiteTree::create([ 'Title' => 'Test page', 'URLSegment' => 'test-page', 'ParentID' => 0, ]); $page->write(); $page->publishRecursive(); $page = SiteTree::create([ 'Title' => 'Other test page', 'URLSegment' => 'other-test-page', 'ParentID' => 0, ]); $page->write(); $page->publishRecursive(); $result = LinkablePlugin::applyLinkFilter('test', ['link' => 'test-page'], [], new FakeResolveInfo()); $this->assertTrue($result->exists()); $this->assertEquals('Test page', $result->first()->Title); $result = LinkablePlugin::applyLinkFilter('test', ['links' => ['test-page']], [], new FakeResolveInfo()); $this->assertTrue($result->exists()); $this->assertEquals('Test page', $result->first()->Title); $result = LinkablePlugin::applyLinkFilter( 'test', ['links' => ['test-page', 'other-test-page']], [], new FakeResolveInfo() ); $this->assertTrue($result->exists()); $this->assertCount(2, $result); $titles = $result->column('Title'); $this->assertTrue(in_array('Test page', $titles)); $this->assertTrue(in_array('Other test page', $titles)); $result = LinkablePlugin::applyLinkFilter( 'test', ['links' => ['test-page', 'fail-page']], [], new FakeResolveInfo() ); $this->assertTrue($result->exists()); $this->assertCount(1, $result); $this->assertEquals('Test page', $result->first()->Title); $result = LinkablePlugin::applyLinkFilter('test', ['link' => 'fail-page'], [], new FakeResolveInfo()); $this->assertFalse($result->exists()); $result = LinkablePlugin::applyLinkFilter('test', ['links' => ['fail-page']], [], new FakeResolveInfo()); $this->assertFalse($result->exists()); $result = LinkablePlugin::applyLinkFilter('test', ['notAnArg' => 'fail'], [], new FakeResolveInfo()); $this->assertEquals('test', $result); } public function provideApply() { return [ [true], [false], ]; } }