Autoload.php
8 years ago
TestEmbera.php
8 years ago
TestFakeResponse.php
8 years ago
TestFormatter.php
8 years ago
TestHtmlProcessor.php
8 years ago
TestHttpRequest.php
8 years ago
TestOembed.php
8 years ago
TestProviders.php
8 years ago
TestServiceAmCharts.php
8 years ago
TestServiceAnimatron.php
8 years ago
TestServiceAnimoto.php
8 years ago
TestServiceAolOn.php
8 years ago
TestServiceAppNet.php
8 years ago
TestServiceAudioSnaps.php
8 years ago
TestServiceBambuser.php
8 years ago
TestServiceBlipTv.php
8 years ago
TestServiceCacoo.php
8 years ago
TestServiceChartblocks.php
8 years ago
TestServiceChirbit.php
8 years ago
TestServiceCircuitLab.php
8 years ago
TestServiceClipland.php
8 years ago
TestServiceClyp.php
8 years ago
TestServiceCodepoints.php
8 years ago
TestServiceCollegeHumor.php
8 years ago
TestServiceCoub.php
8 years ago
TestServiceCrowdRanking.php
8 years ago
TestServiceDailyMile.php
8 years ago
TestServiceDailyMotion.php
8 years ago
TestServiceDeviantart.php
8 years ago
TestServiceDidacte.php
8 years ago
TestServiceDipity.php
8 years ago
TestServiceDotSub.php
8 years ago
TestServiceEdocr.php
8 years ago
TestServiceEgliseInfo.php
8 years ago
TestServiceFacebook.php
8 years ago
TestServiceFlickr.php
8 years ago
TestServiceFunnyOrDie.php
8 years ago
TestServiceGeographCI.php
8 years ago
TestServiceGeographDe.php
8 years ago
TestServiceGeographUk.php
8 years ago
TestServiceGettyImages.php
8 years ago
TestServiceGfycat.php
8 years ago
TestServiceGithubGist.php
8 years ago
TestServiceGmep.php
8 years ago
TestServiceHq23.php
8 years ago
TestServiceHuffduffer.php
8 years ago
TestServiceHulu.php
8 years ago
TestServiceIFTTT.php
8 years ago
TestServiceIFixIt.php
8 years ago
TestServiceInfogram.php
8 years ago
TestServiceInstagram.php
8 years ago
TestServiceIssuu.php
8 years ago
TestServiceIssuuFakeResponse.php
8 years ago
TestServiceKickstarter.php
8 years ago
TestServiceLearningApps.php
8 years ago
TestServiceMeetup.php
8 years ago
TestServiceMixCloud.php
8 years ago
TestServiceMobyPicture.php
8 years ago
TestServiceNFB.php
8 years ago
TestServiceOfficeMix.php
8 years ago
TestServiceOfficialFM.php
8 years ago
TestServiceOumy.php
8 years ago
TestServicePastery.php
8 years ago
TestServicePollDaddy.php
8 years ago
TestServicePollEverywhere.php
8 years ago
TestServicePortfolium.php
8 years ago
TestServiceRapidengage.php
8 years ago
TestServiceRdio.php
8 years ago
TestServiceReleaseWire.php
8 years ago
TestServiceRepubHub.php
8 years ago
TestServiceReverbnation.php
8 years ago
TestServiceRevision3.php
8 years ago
TestServiceRoomshare.php
8 years ago
TestServiceRutube.php
8 years ago
TestServiceSapo.php
8 years ago
TestServiceScreenr.php
8 years ago
TestServiceScribd.php
8 years ago
TestServiceShortNote.php
8 years ago
TestServiceShoudio.php
8 years ago
TestServiceShowTheWay.php
8 years ago
TestServiceSilk.php
8 years ago
TestServiceSketchfab.php
8 years ago
TestServiceSlideshare.php
8 years ago
TestServiceSoundCloud.php
8 years ago
TestServiceSpeakerDeck.php
8 years ago
TestServiceSpotify.php
8 years ago
TestServiceStreamOneCloud.php
8 years ago
TestServiceStreamable.php
8 years ago
TestServiceSway.php
8 years ago
TestServiceTed.php
8 years ago
TestServiceTheySaidSo.php
8 years ago
TestServiceTwitter.php
8 years ago
TestServiceUstream.php
8 years ago
TestServiceVerse.php
8 years ago
TestServiceVevo.php
8 years ago
TestServiceViddler.php
8 years ago
TestServiceVideoFork.php
8 years ago
TestServiceVideoJug.php
8 years ago
TestServiceVimeo.php
8 years ago
TestServiceVine.php
8 years ago
TestServiceWordpressTV.php
8 years ago
TestServiceYFrog.php
8 years ago
TestServiceYandex.php
8 years ago
TestServiceYoutube.php
8 years ago
TestUrl.php
8 years ago
TestFormatter.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * TestFormatter.php |
| 4 | * |
| 5 | * @package Tests |
| 6 | * @author Michael Pratt <pratt@hablarmierda.net> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | class TestFormatter extends PHPUnit_Framework_TestCase |
| 14 | { |
| 15 | public function testTemplateArray() |
| 16 | { |
| 17 | $urls = array( |
| 18 | 'http://youtu.be/fSUK4WgQ3vk', |
| 19 | 'http://www.youtube.com/watch?v=T3O1nffTG-k' |
| 20 | ); |
| 21 | |
| 22 | $embera = new \Embera\Embera(); |
| 23 | $embera = new \Embera\Formatter($embera); |
| 24 | $embera->setTemplate('{html}|'); |
| 25 | |
| 26 | $result = $embera->transform($urls); |
| 27 | $this->assertCount(count($urls), explode('|', trim($result, '|'))); |
| 28 | } |
| 29 | |
| 30 | public function testTemplateString() |
| 31 | { |
| 32 | $embera = new \Embera\Embera(); |
| 33 | $embera = new \Embera\Formatter($embera); |
| 34 | $embera->setTemplate('<div class="hey">{html}</div>'); |
| 35 | $result = $embera->transform('Hey did you see http://www.youtube.com/watch?v=MpVHQnIvTXo'); |
| 36 | |
| 37 | $this->assertContains('<div class="hey"><iframe', $result); |
| 38 | } |
| 39 | |
| 40 | public function testTemplateRecursionKeys() |
| 41 | { |
| 42 | $embera = new \Embera\Embera(); |
| 43 | $embera = new \Embera\Formatter($embera); |
| 44 | $embera->setTemplate('{raw.html}'); |
| 45 | $result = $embera->transform('https://www.facebook.com/adam.j.mccann/posts/10156943904420037?pnref=story'); |
| 46 | |
| 47 | $this->assertContains('fb-root', $result); |
| 48 | } |
| 49 | |
| 50 | public function testOfflineSupport() |
| 51 | { |
| 52 | $urls = array( |
| 53 | 'http://www.youtube.com/watch?v=MpVHQnIvTXo', |
| 54 | 'http://youtu.be/fSUK4WgQ3vk', |
| 55 | ); |
| 56 | |
| 57 | $embera = new \Embera\Embera(array('oembed' => false)); |
| 58 | $embera = new \Embera\Formatter($embera); |
| 59 | $embera->setTemplate('<div class="hi">{html}</div>'); |
| 60 | |
| 61 | $result = $embera->transform($urls); |
| 62 | $this->assertEmpty($result); |
| 63 | $this->assertTrue($embera->hasErrors()); |
| 64 | $this->assertCount(count($urls), $embera->getErrors()); |
| 65 | |
| 66 | $last = $embera->getLastError(); |
| 67 | $this->assertTrue(!empty($last)); |
| 68 | } |
| 69 | |
| 70 | public function testOfflineSupport2() |
| 71 | { |
| 72 | $urls = array('http://youtu.be/fSUK4WgQ3vk'); |
| 73 | |
| 74 | $embera = new \Embera\Embera(array('oembed' => false)); |
| 75 | $embera = new \Embera\Formatter($embera, true); |
| 76 | $embera->setTemplate('<div class="hi">{html}</div>'); |
| 77 | |
| 78 | $result = $embera->transform($urls); |
| 79 | $this->assertContains('<iframe', $result); |
| 80 | } |
| 81 | |
| 82 | public function testSupportForDecoratedObjectAPI() |
| 83 | { |
| 84 | $urls = array( |
| 85 | 'http://www.youtube.com/watch?v=MpVHQnIvTXo', |
| 86 | 'http://youtu.be/fSUK4WgQ3vk', |
| 87 | ); |
| 88 | |
| 89 | $embera = new \Embera\Embera(array('oembed' => false)); |
| 90 | $embera = new \Embera\Formatter($embera); |
| 91 | |
| 92 | $result = $embera->autoEmbed(implode(' ', $urls)); |
| 93 | $this->assertTrue(!empty($result)); |
| 94 | $this->assertContains('<iframe', $result); |
| 95 | } |
| 96 | |
| 97 | public function testSupportForDecoratedObjectAPI2() |
| 98 | { |
| 99 | $this->setExpectedException('InvalidArgumentException'); |
| 100 | |
| 101 | $embera = new \Embera\Embera(array('oembed' => false)); |
| 102 | $embera = new \Embera\Formatter($embera); |
| 103 | |
| 104 | $last = $embera->getLastError(); |
| 105 | $this->assertTrue(empty($last)); |
| 106 | |
| 107 | $embera->unknownMethodName(); |
| 108 | } |
| 109 | |
| 110 | public function testUnknownWebsites() |
| 111 | { |
| 112 | $embera = new \Embera\Embera(); |
| 113 | $embera = new \Embera\Formatter($embera); |
| 114 | |
| 115 | $this->assertEmpty($embera->setTemplate('{html}', array('url1.com', 'url2.com', 'url3.com'))); |
| 116 | $this->assertEquals($embera->setTemplate('{html}', 'unknown url http://hey.com'), 'unknown url http://hey.com'); |
| 117 | } |
| 118 | |
| 119 | public function testRemoveEmptyPlaceholders() |
| 120 | { |
| 121 | $urls = array('http://youtu.be/fSUK4WgQ3vk'); |
| 122 | |
| 123 | $embera = new \Embera\Embera(); |
| 124 | $embera = new \Embera\Formatter($embera); |
| 125 | $embera->setTemplate('{unknown_key}'); |
| 126 | |
| 127 | $result = $embera->transform($urls); |
| 128 | $this->assertEquals($result, ''); |
| 129 | } |
| 130 | } |
| 131 |