protected function buildContributable() { $urlFactory = new tubepress_url_impl_puzzle_UrlFactory(); $authors = array(array('name' => 'author name', 'url' => $urlFactory->fromString('http://author.com/foo')), array('name' => 'other author name', 'email' => '*****@*****.**')); $licenses = array('urls' => array($urlFactory->fromString('http://license.com/text.html')), 'type' => 'some license type'); return $this->buildSut('some-name', tubepress_api_version_Version::parse('1.2.3'), 'some title', $authors, $licenses); }
public function onSetup() { $this->_mockLogger = $this->mock(tubepress_api_log_LoggerInterface::_); $this->_mockLangUtils = $this->mock(tubepress_api_util_LangUtilsInterface::_); $this->_mockUrlFactory = $this->mock(tubepress_api_url_UrlFactoryInterface::_); $this->_mockStringUtils = $this->mock(tubepress_api_util_StringUtilsInterface::_); $this->_mockLangUtils->shouldReceive('isAssociativeArray')->andReturnUsing(function ($candidate) { $util = new tubepress_util_impl_LangUtils(); return $util->isAssociativeArray($candidate); }); $this->_mockLangUtils->shouldReceive('isSimpleArrayOfStrings')->andReturnUsing(function ($candidate) { $util = new tubepress_util_impl_LangUtils(); return $util->isSimpleArrayOfStrings($candidate); }); $this->_mockUrlFactory->shouldReceive('fromString')->andReturnUsing(function ($candidate) { $factory = new tubepress_url_impl_puzzle_UrlFactory(); return $factory->fromString($candidate); }); $this->_mockStringUtils->shouldReceive('endsWith')->andReturnUsing(function ($haystack, $needle) { $utils = new tubepress_util_impl_StringUtils(); return $utils->endsWith($haystack, $needle); }); $this->_mockLogger->shouldReceive('isEnabled')->atLeast(1)->andReturn(true); $this->_mockLogger->shouldReceive('debug'); $this->_sut = $this->buildSut($this->_mockLogger, $this->_mockUrlFactory, $this->_mockLangUtils, $this->_mockStringUtils); }
/** * @dataProvider getDataWantsToAuthorizeRequest */ public function testWantsToAuthorizeRequest($stringUrl, $expected) { $urlFactory = new tubepress_url_impl_puzzle_UrlFactory(); $mockUrl = $urlFactory->fromString($stringUrl); $mockRequest = $this->mock('tubepress_api_http_message_RequestInterface'); if ($mockUrl->getHost() === 'api.vimeo.com') { $this->_mockStringUtils->shouldReceive('startsWith')->once()->with($mockUrl->getPath(), '/oauth')->andReturnUsing(array(new tubepress_util_impl_StringUtils(), 'startsWith')); } $mockRequest->shouldReceive('getUrl')->once()->andReturn($mockUrl); $actual = $this->_sut->wantsToAuthorizeRequest($mockRequest); $this->assertEquals($expected, $actual); }
public function onSetup() { $this->_mockLogger = $this->mock(tubepress_api_log_LoggerInterface::_); $this->_mockUrlFactory = $this->mock(tubepress_api_url_UrlFactoryInterface::_); $this->_mockLogger->shouldReceive('isEnabled')->once()->andReturn(true); $this->_mockLogger->shouldReceive('debug')->atLeast(1); $this->_mockUrlFactory->shouldReceive('fromString')->andReturnUsing(function ($string) { $realFactory = new tubepress_url_impl_puzzle_UrlFactory(); return $realFactory->fromString($string); }); $this->_userContentDirectory = sys_get_temp_dir() . '/tubepress-boot-settings-test/'; $this->_sut = new tubepress_internal_boot_BootSettings($this->_mockLogger, $this->_mockUrlFactory); if (is_dir($this->_userContentDirectory)) { $this->recursivelyDeleteDirectory($this->_userContentDirectory); } $directoryCreated = mkdir($this->_userContentDirectory . '/config', 0777, true); $this->assertTrue($directoryCreated); }
protected function request($method, $path = 'index.php', array $params = array(), $debug = false) { $client = \JonnyW\PhantomJs\Client::getInstance(); $request = $client->getMessageFactory()->createRequest(); $response = $client->getMessageFactory()->createResponse(); $debugParams = array('tubepress_debug' => $debug ? 'true' : 'false', 'XDEBUG_SESSION_START' => 'true'); $encodedOpts = base64_encode(serialize($this->_options)); $finalParams = array_merge($debugParams, array('options' => $encodedOpts), $params); $urlFactory = new tubepress_url_impl_puzzle_UrlFactory(); $url = $urlFactory->fromString('http://' . self::$_WEB_SERVER_ADDRESS)->setPath($path)->setQuery($finalParams); $request->setMethod($method); $request->setUrl($url->toString()); $client->getEngine()->setPath(self::_getProjectRoot() . '/bin/phantomjs'); $client->send($request, $response); if ($response->getStatus() !== 200) { throw new RuntimeException(sprintf('%s returned HTTP %s: %s', $url, $response->getStatus(), $response->getContent())); } return $response; }
/** * @param $pathToManifest * * @return tubepress_api_contrib_AddonInterface */ protected function getAddonFromManifest($pathToManifest) { $mockUrlFactory = $this->mock(tubepress_api_url_UrlFactoryInterface::_); $mockUrlFactory->shouldReceive('fromString')->andReturnUsing(function ($incoming) { $factory = new tubepress_url_impl_puzzle_UrlFactory($_SERVER); return $factory->fromString($incoming); }); $logger = new tubepress_internal_logger_BootLogger(false); $urlFactory = new tubepress_url_impl_puzzle_UrlFactory(); $bootSettings = new tubepress_internal_boot_BootSettings($logger, $urlFactory); $langUtils = new tubepress_util_impl_LangUtils(); $stringUtils = new tubepress_util_impl_StringUtils(); $finderFactory = new tubepress_internal_finder_FinderFactory(); $manifestFinder = new tubepress_internal_boot_helper_uncached_contrib_ManifestFinder(dirname($pathToManifest), 'whatevs', 'manifest.json', $logger, $bootSettings, $finderFactory); $addonFactory = new tubepress_internal_boot_helper_uncached_contrib_AddonFactory($logger, $urlFactory, $langUtils, $stringUtils, $bootSettings); $addonManifests = $manifestFinder->find(); $this->assertTrue(count($addonManifests) === 1, 'Expected 1 add-on but got ' . count($addonManifests)); $addons = array(); foreach ($addonManifests as $manifestPath => $contents) { $addons[] = $addonFactory->fromManifestData($manifestPath, $contents); } $this->assertTrue($addons[0] instanceof tubepress_api_contrib_AddonInterface); return $addons[0]; }
public function dataProviderGetToString() { $toReturn = array(array('/', '/'), array('', ''), array('//foo', '//foo'), array('http://foo.bar/some/thing', 'http://foo.bar/some/thing'), array('http://foo.bar/some/thing/', 'http://foo.bar/some/thing/'), array('http://foo.bar', 'http://foo.bar'), array('http://foo.bar/', 'http://foo.bar/')); $urlFactory = new tubepress_url_impl_puzzle_UrlFactory(); $url = $urlFactory->fromString('http://foo.bar/some/thing'); $url->removeSchemeAndAuthority(); $toReturn[] = array($url, '/some/thing'); $url = $urlFactory->fromString('http://foo.bar/'); $url->removeSchemeAndAuthority(); $toReturn[] = array($url, '/'); $url = $urlFactory->fromString('http://foo.bar'); $url->removeSchemeAndAuthority(); $url->addPath('/foo/bar'); $toReturn[] = array($url, '/foo/bar'); $url = $urlFactory->fromString('http://foo.bar'); $url->removeSchemeAndAuthority(); $url->addPath('foo/bar'); $toReturn[] = array($url, '/foo/bar'); $url = $urlFactory->fromString('http://foo.bar/'); $url->removeSchemeAndAuthority(); $url->addPath('/foo/bar'); $toReturn[] = array($url, '/foo/bar'); return $toReturn; }
/** * @runInSeparateProcess * @dataProvider dataProviderTestGetFullUrl */ public function testGetFullUrl($serverArray, $expectedUrl) { $sut = new tubepress_url_impl_puzzle_UrlFactory($serverArray); $result = $sut->fromCurrent(); $this->assertSame($expectedUrl, $result->toString()); }