@@ -571,4 +571,163 @@ static function () use ( $expected ) {
571571 $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
572572 $ this ->assertSame ( $ expected , $ actual ['data ' ]['generalSettings ' ]['myCustomField ' ] );
573573 }
574+
575+ /**
576+ * Test that the siteIconUrl field returns null when no site icon is set.
577+ *
578+ * @return void
579+ */
580+ public function testSiteIconUrlReturnsNullWhenNotSet () {
581+ // Ensure no site icon is set.
582+ delete_option ( 'site_icon ' );
583+
584+ $ query = '
585+ {
586+ generalSettings {
587+ siteIconUrl
588+ }
589+ }
590+ ' ;
591+
592+ $ actual = $ this ->graphql ( compact ( 'query ' ) );
593+
594+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
595+ $ this ->assertNull ( $ actual ['data ' ]['generalSettings ' ]['siteIconUrl ' ] );
596+ }
597+
598+ /**
599+ * Test that the siteIconUrl field returns the URL when a site icon is set.
600+ *
601+ * @return void
602+ */
603+ public function testSiteIconUrlReturnsUrlWhenSet () {
604+ // Create a test attachment to use as site icon.
605+ $ filename = WPGRAPHQL_PLUGIN_DIR . 'tests/_data/images/test.png ' ;
606+ $ attachment_id = $ this ->factory ()->attachment ->create_upload_object ( $ filename );
607+
608+ // Set the site icon.
609+ update_option ( 'site_icon ' , $ attachment_id );
610+
611+ $ query = '
612+ {
613+ generalSettings {
614+ siteIconUrl
615+ }
616+ }
617+ ' ;
618+
619+ $ actual = $ this ->graphql ( compact ( 'query ' ) );
620+
621+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
622+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['siteIconUrl ' ] );
623+ $ this ->assertStringContainsString ( 'test ' , $ actual ['data ' ]['generalSettings ' ]['siteIconUrl ' ] );
624+
625+ // Cleanup.
626+ delete_option ( 'site_icon ' );
627+ wp_delete_attachment ( $ attachment_id , true );
628+ }
629+
630+ /**
631+ * Test that the siteIconUrl field respects the size argument.
632+ *
633+ * @return void
634+ */
635+ public function testSiteIconUrlWithSizeArgument () {
636+ // Create a test attachment to use as site icon.
637+ $ filename = WPGRAPHQL_PLUGIN_DIR . 'tests/_data/images/test.png ' ;
638+ $ attachment_id = $ this ->factory ()->attachment ->create_upload_object ( $ filename );
639+
640+ // Set the site icon.
641+ update_option ( 'site_icon ' , $ attachment_id );
642+
643+ $ query = '
644+ {
645+ generalSettings {
646+ defaultSize: siteIconUrl
647+ smallSize: siteIconUrl(size: 32)
648+ largeSize: siteIconUrl(size: 512)
649+ }
650+ }
651+ ' ;
652+
653+ $ actual = $ this ->graphql ( compact ( 'query ' ) );
654+
655+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
656+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['defaultSize ' ] );
657+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['smallSize ' ] );
658+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['largeSize ' ] );
659+
660+ // Cleanup.
661+ delete_option ( 'site_icon ' );
662+ wp_delete_attachment ( $ attachment_id , true );
663+ }
664+
665+ /**
666+ * Test that the siteIcon connection returns null when no site icon is set.
667+ *
668+ * @return void
669+ */
670+ public function testSiteIconConnectionReturnsNullWhenNotSet () {
671+ // Ensure no site icon is set.
672+ delete_option ( 'site_icon ' );
673+
674+ $ query = '
675+ {
676+ generalSettings {
677+ siteIcon {
678+ node {
679+ id
680+ databaseId
681+ sourceUrl
682+ }
683+ }
684+ }
685+ }
686+ ' ;
687+
688+ $ actual = $ this ->graphql ( compact ( 'query ' ) );
689+
690+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
691+ $ this ->assertNull ( $ actual ['data ' ]['generalSettings ' ]['siteIcon ' ] );
692+ }
693+
694+ /**
695+ * Test that the siteIcon connection returns the MediaItem when a site icon is set.
696+ *
697+ * @return void
698+ */
699+ public function testSiteIconConnectionReturnsMediaItemWhenSet () {
700+ // Create a test attachment to use as site icon.
701+ $ filename = WPGRAPHQL_PLUGIN_DIR . 'tests/_data/images/test.png ' ;
702+ $ attachment_id = $ this ->factory ()->attachment ->create_upload_object ( $ filename );
703+
704+ // Set the site icon.
705+ update_option ( 'site_icon ' , $ attachment_id );
706+
707+ $ query = '
708+ {
709+ generalSettings {
710+ siteIcon {
711+ node {
712+ id
713+ databaseId
714+ sourceUrl
715+ }
716+ }
717+ }
718+ }
719+ ' ;
720+
721+ $ actual = $ this ->graphql ( compact ( 'query ' ) );
722+
723+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
724+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['siteIcon ' ] );
725+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['siteIcon ' ]['node ' ] );
726+ $ this ->assertEquals ( $ attachment_id , $ actual ['data ' ]['generalSettings ' ]['siteIcon ' ]['node ' ]['databaseId ' ] );
727+ $ this ->assertNotNull ( $ actual ['data ' ]['generalSettings ' ]['siteIcon ' ]['node ' ]['sourceUrl ' ] );
728+
729+ // Cleanup.
730+ delete_option ( 'site_icon ' );
731+ wp_delete_attachment ( $ attachment_id , true );
732+ }
574733}
0 commit comments