How to use getInstance method of with class

Best Prophecy code snippet using with.getInstance

ApiTest.php

Source:ApiTest.php Github

copy

Full Screen

...30{31 public function setUp()32 {33 parent::setUp();34 Plugin\Manager::getInstance()->activatePlugin('MobileAppMeasurable');35 // setup the access layer36 FakeAccess::$superUser = true;37 }38 /**39 * empty name -> exception40 * @expectedException \Exception41 */42 public function test_addSite_WithEmptyName_ThrowsException()43 {44 API::getInstance()->addSite("", array("http://piwik.net"));45 }46 /**47 * DataProvider for testAddSiteWrongUrls48 */49 public function getInvalidUrlData()50 {51 return array(52 array(array()), // no urls53 array(array("")),54 array(""),55 array("5http://piwik.net"),56 array("???://piwik.net"),57 );58 }59 /**60 * wrong urls -> exception61 *62 * @dataProvider getInvalidUrlData63 * @expectedException \Exception64 */65 public function test_addSite_WithWrongUrls_ThrowsException($url)66 {67 API::getInstance()->addSite("name", $url);68 }69 /**70 * Test with valid IPs71 */72 public function test_addSite_WithExcludedIps_AndTimezone_AndCurrency_AndExcludedQueryParameters_SucceedsWhenParamsAreValid()73 {74 $ips = '1.2.3.4,1.1.1.*,1.2.*.*,1.*.*.*';75 $timezone = 'Europe/Paris';76 $currency = 'EUR';77 $excludedQueryParameters = 'p1,P2, P33333';78 $expectedExcludedQueryParameters = 'p1,P2,P33333';79 $excludedUserAgents = " p1,P2, \nP3333 ";80 $expectedExcludedUserAgents = "p1,P2,P3333";81 $expectedWebsiteType = 'mobile-\'app';82 $keepUrlFragment = 1;83 $idsite = API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 1,84 $siteSearch = 1, $searchKeywordParameters = 'search,param', $searchCategoryParameters = 'cat,category',85 $ips, $excludedQueryParameters, $timezone, $currency, $group = null, $startDate = null, $excludedUserAgents,86 $keepUrlFragment, $expectedWebsiteType);87 $siteInfo = API::getInstance()->getSiteFromId($idsite);88 $this->assertEquals($ips, $siteInfo['excluded_ips']);89 $this->assertEquals($timezone, $siteInfo['timezone']);90 $this->assertEquals($currency, $siteInfo['currency']);91 $this->assertEquals($ecommerce, $siteInfo['ecommerce']);92 $this->assertTrue(Site::isEcommerceEnabledFor($idsite));93 $this->assertEquals($siteSearch, $siteInfo['sitesearch']);94 $this->assertTrue(Site::isSiteSearchEnabledFor($idsite));95 $this->assertEquals($expectedWebsiteType, $siteInfo['type']);96 $this->assertEquals($expectedWebsiteType, Site::getTypeFor($idsite));97 $this->assertEquals($searchKeywordParameters, $siteInfo['sitesearch_keyword_parameters']);98 $this->assertEquals($searchCategoryParameters, $siteInfo['sitesearch_category_parameters']);99 $this->assertEquals($expectedExcludedQueryParameters, $siteInfo['excluded_parameters']);100 $this->assertEquals($expectedExcludedUserAgents, $siteInfo['excluded_user_agents']);101 }102 /**103 * dataProvider for testAddSiteExcludedIpsNotValid104 */105 public function getInvalidIPsData()106 {107 return array(108 array('35817587341'),109 array('ieagieha'),110 array('1.2.3'),111 array('*.1.1.1'),112 array('*.*.1.1'),113 array('*.*.*.1'),114 array('1.1.1.1.1'),115 );116 }117 /**118 * Test with invalid IPs119 *120 * @dataProvider getInvalidIPsData121 * @expectedException \Exception122 */123 public function test_addSite_WithInvalidExcludedIps_ThrowsException($ip)124 {125 API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,126 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $ip);127 }128 /**129 * one url -> one main_url and nothing inserted as alias urls130 */131 public function test_addSite_WithOneUrl_Succeeds_AndCreatesNoAliasUrls()132 {133 $url = "http://piwik.net/";134 $urlOK = "http://piwik.net";135 $idsite = API::getInstance()->addSite("name", $url);136 $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);137 $siteInfo = API::getInstance()->getSiteFromId($idsite);138 $this->assertEquals($urlOK, $siteInfo['main_url']);139 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($siteInfo['ts_created'])));140 $siteUrls = API::getInstance()->getSiteUrlsFromId($idsite);141 $this->assertEquals(1, count($siteUrls));142 }143 /**144 * several urls -> one main_url and others as alias urls145 */146 public function test_addSite_WithSeveralUrls_Succeeds_AndCreatesAliasUrls()147 {148 $urls = array("http://piwik.net/", "http://piwik.com", "https://piwik.net/test/", "piwik.net/another/test");149 $urlsOK = array("http://piwik.net", "http://piwik.com", "http://piwik.net/another/test", "https://piwik.net/test");150 $idsite = API::getInstance()->addSite("super website", $urls);151 $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);152 $siteInfo = API::getInstance()->getSiteFromId($idsite);153 $this->assertEquals($urlsOK[0], $siteInfo['main_url']);154 $siteUrls = API::getInstance()->getSiteUrlsFromId($idsite);155 $this->assertEquals($urlsOK, $siteUrls);156 }157 /**158 * strange name159 */160 public function test_addSite_WithStrangeName_Succeeds()161 {162 $name = "supertest(); ~@@()''!£\$'%%^'!£ போ";163 $idsite = API::getInstance()->addSite($name, "http://piwik.net");164 $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);165 $siteInfo = API::getInstance()->getSiteFromId($idsite);166 $this->assertEquals($name, $siteInfo['name']);167 }168 /**169 * @expectedException \Exception170 * @expectedExceptionMessage Only 100 characters are allowed171 */172 public function test_addSite_ShouldFailAndNotCreatedASite_IfASettingIsInvalid()173 {174 try {175 $type = MobileAppMeasurable\Type::ID;176 $settings = array('app_id' => str_pad('test', 789, 't'));177 $this->addSiteWithType($type, $settings);178 } catch (Exception $e) {179 // make sure no site created180 $ids = API::getInstance()->getAllSitesId();181 $this->assertEquals(array(), $ids);182 throw $e;183 }184 }185 public function test_addSite_ShouldSavePassedMeasurableSettings_IfSettingsAreValid()186 {187 $type = MobileAppMeasurable\Type::ID;188 $settings = array('app_id' => 'org.piwik.mobile2');189 $idSite = $this->addSiteWithType($type, $settings);190 $this->assertSame(1, $idSite);191 $measurable = new Measurable($idSite);192 $appId = $measurable->getSettingValue('app_id');193 $this->assertSame('org.piwik.mobile2', $appId);194 }195 /**196 * adds a site197 * use by several other unit tests198 */199 protected function _addSite()200 {201 $name = "website ";202 $idsite = API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/"));203 $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);204 $siteInfo = API::getInstance()->getSiteFromId($idsite);205 $this->assertEquals($name, $siteInfo['name']);206 $this->assertEquals("http://piwik.net", $siteInfo['main_url']);207 $siteUrls = API::getInstance()->getSiteUrlsFromId($idsite);208 $this->assertEquals(array("http://piwik.net", "http://piwik.com/test"), $siteUrls);209 return $idsite;210 }211 private function addSiteWithType($type, $settings)212 {213 return API::getInstance()->addSite("name", "http://piwik.net/", $ecommerce = 0,214 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,215 $ip = null,216 $excludedQueryParameters = null,217 $timezone = null,218 $currency = null,219 $group = null,220 $startDate = null,221 $excludedUserAgents = null,222 $keepURLFragments = null,223 $type, $settings);224 }225 private function updateSiteSettings($idSite, $newSiteName, $settings)226 {227 return API::getInstance()->updateSite($idSite,228 $newSiteName,229 $urls = null,230 $ecommerce = null,231 $siteSearch = null,232 $searchKeywordParameters = null,233 $searchCategoryParameters = null,234 $excludedIps = null,235 $excludedQueryParameters = null,236 $timezone = null,237 $currency = null,238 $group = null,239 $startDate = null,240 $excludedUserAgents = null,241 $keepURLFragments = null,242 $type = null,243 $settings);244 }245 /**246 * no duplicate -> all the urls are saved247 */248 public function test_addSiteAliasUrls_WithUniqueUrls_SavesAllUrls()249 {250 $idsite = $this->_addSite();251 $siteUrlsBefore = API::getInstance()->getSiteUrlsFromId($idsite);252 $toAdd = array("http://piwik1.net",253 "http://piwik2.net",254 "http://piwik3.net/test/",255 "http://localhost/test",256 "http://localho5.st/test",257 "http://l42578gqege.f4",258 "http://super.com/test/test/atqata675675/te"259 );260 $toAddValid = array("http://piwik1.net",261 "http://piwik2.net",262 "http://piwik3.net/test",263 "http://localhost/test",264 "http://localho5.st/test",265 "http://l42578gqege.f4",266 "http://super.com/test/test/atqata675675/te");267 $insertedUrls = API::getInstance()->addSiteAliasUrls($idsite, $toAdd);268 $this->assertEquals(count($toAdd), $insertedUrls);269 $siteUrlsAfter = API::getInstance()->getSiteUrlsFromId($idsite);270 $shouldHave = array_merge($siteUrlsBefore, $toAddValid);271 sort($shouldHave);272 sort($siteUrlsAfter);273 $this->assertEquals($shouldHave, $siteUrlsAfter);274 }275 /**276 * duplicate -> don't save the already existing URLs277 */278 public function test_addSiteAliasUrls_WithDuplicateUrls_RemovesDuplicatesBeforeSaving()279 {280 $idsite = $this->_addSite();281 $siteUrlsBefore = API::getInstance()->getSiteUrlsFromId($idsite);282 $toAdd = array_merge($siteUrlsBefore, array("http://piwik1.net", "http://piwik2.net"));283 $insertedUrls = API::getInstance()->addSiteAliasUrls($idsite, $toAdd);284 $this->assertEquals(count($toAdd) - count($siteUrlsBefore), $insertedUrls);285 $siteUrlsAfter = API::getInstance()->getSiteUrlsFromId($idsite);286 $shouldHave = $toAdd;287 sort($shouldHave);288 sort($siteUrlsAfter);289 $this->assertEquals($shouldHave, $siteUrlsAfter);290 }291 /**292 * case empty array => nothing happens293 */294 public function test_addSiteAliasUrls_WithNoUrls_DoesNothing()295 {296 $idsite = $this->_addSite();297 $siteUrlsBefore = API::getInstance()->getSiteUrlsFromId($idsite);298 $toAdd = array();299 $insertedUrls = API::getInstance()->addSiteAliasUrls($idsite, $toAdd);300 $this->assertEquals(count($toAdd), $insertedUrls);301 $siteUrlsAfter = API::getInstance()->getSiteUrlsFromId($idsite);302 $shouldHave = $siteUrlsBefore;303 sort($shouldHave);304 sort($siteUrlsAfter);305 $this->assertEquals($shouldHave, $siteUrlsAfter);306 }307 /**308 * case array only duplicate => nothing happens309 */310 public function test_addSiteAliasUrls_WithAlreadyPersistedUrls_DoesNothing()311 {312 $idsite = $this->_addSite();313 $siteUrlsBefore = API::getInstance()->getSiteUrlsFromId($idsite);314 $toAdd = $siteUrlsBefore;315 $insertedUrls = API::getInstance()->addSiteAliasUrls($idsite, $toAdd);316 $this->assertEquals(0, $insertedUrls);317 $siteUrlsAfter = API::getInstance()->getSiteUrlsFromId($idsite);318 $shouldHave = $siteUrlsBefore;319 sort($shouldHave);320 sort($siteUrlsAfter);321 $this->assertEquals($shouldHave, $siteUrlsAfter);322 }323 /**324 * wrong format urls => exception325 * @expectedException \Exception326 */327 public function test_addSiteAliasUrls_WithIncorrectFormat_ThrowsException_3()328 {329 $idsite = $this->_addSite();330 $toAdd = array("http:mpigeq");331 API::getInstance()->addSiteAliasUrls($idsite, $toAdd);332 }333 /**334 * wrong idsite => no exception because simply no access to this resource335 * @expectedException \Exception336 */337 public function test_addSiteAliasUrls_WithWrongIdSite_ThrowsException()338 {339 $toAdd = array("http://pigeq.com/test");340 API::getInstance()->addSiteAliasUrls(-1, $toAdd);341 }342 /**343 * wrong idsite => exception344 * @expectedException \Exception345 */346 public function test_addSiteAliasUrls_WithWrongIdSite_ThrowsException2()347 {348 $toAdd = array("http://pigeq.com/test");349 API::getInstance()->addSiteAliasUrls(155, $toAdd);350 }351 public function test_addSite_CorrectlySavesExcludeUnknownUrlsSetting()352 {353 $idSite = API::getInstance()->addSite("site", array("http://piwik.net"), $ecommerce = null, $siteSearch = null,354 $searchKeywordParams = null, $searchCategoryParams = null, $excludedIps = null, $excludedQueryParams = null,355 $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null,356 $keepUrlFragments = null, $type = null, $settings = null, $excludeUnknownUrls = true);357 $site = API::getInstance()->getSiteFromId($idSite);358 $this->assertEquals(1, $site['exclude_unknown_urls']);359 }360 /**361 * no Id -> empty array362 */363 public function test_getAllSitesId_ReturnsNothing_WhenNoSitesSaved()364 {365 $ids = API::getInstance()->getAllSitesId();366 $this->assertEquals(array(), $ids);367 }368 /**369 * several Id -> normal array370 */371 public function test_getAllSitesId_ReturnsAllIds_WhenMultipleSitesPersisted()372 {373 $name = "tetq";374 $idsites = array(375 API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),376 API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),377 API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),378 API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),379 API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/")),380 );381 $ids = API::getInstance()->getAllSitesId();382 $this->assertEquals($idsites, $ids);383 }384 /**385 * wrong id => exception386 * @expectedException \Exception387 */388 public function test_getSiteFromId_WithWrongId_ThrowsException1()389 {390 API::getInstance()->getSiteFromId(0);391 }392 /**393 * wrong id => exception394 * @expectedException \Exception395 */396 public function test_getSiteFromId_WithWrongId_ThrowsException2()397 {398 API::getInstance()->getSiteFromId("x1");399 }400 /**401 * wrong id : no access => exception402 * @expectedException \Exception403 */404 public function test_getSiteFromId_ThrowsException_WhenTheUserDoesNotHavaAcessToTheSite()405 {406 $idsite = API::getInstance()->addSite("site", array("http://piwik.net", "http://piwik.com/test/"));407 $this->assertEquals(1, $idsite);408 // set noaccess to site 1409 FakeAccess::setIdSitesView(array(2));410 FakeAccess::setIdSitesAdmin(array());411 API::getInstance()->getSiteFromId(1);412 }413 /**414 * normal case415 */416 public function test_getSiteFromId_WithNormalId_ReturnsTheCorrectSite()417 {418 $name = "website ''";419 $idsite = API::getInstance()->addSite($name, array("http://piwik.net", "http://piwik.com/test/"));420 $this->assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $idsite);421 $siteInfo = API::getInstance()->getSiteFromId($idsite);422 $this->assertEquals($name, $siteInfo['name']);423 $this->assertEquals("http://piwik.net", $siteInfo['main_url']);424 }425 /**426 * there is no admin site available -> array()427 */428 public function test_getSitesWithAdminAccess_ReturnsNothing_WhenUserHasNoAdminAccess()429 {430 FakeAccess::setIdSitesAdmin(array());431 $sites = API::getInstance()->getSitesWithAdminAccess();432 $this->assertEquals(array(), $sites);433 }434 /**435 * normal case, admin and view and noaccess website => return only admin436 */437 public function test_getSitesWithAdminAccess_shouldOnlyReturnSitesHavingActuallyAdminAccess()438 {439 API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"));440 API::getInstance()->addSite("site2", array("http://piwik.com/test/"));441 API::getInstance()->addSite("site3", array("http://piwik.org"));442 $resultWanted = array(443 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),444 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),445 );446 FakeAccess::setIdSitesAdmin(array(1, 3));447 $sites = API::getInstance()->getSitesWithAdminAccess();448 // we don't test the ts_created449 unset($sites[0]['ts_created']);450 unset($sites[1]['ts_created']);451 $this->assertEquals($resultWanted, $sites);452 }453 public function test_getSitesWithAdminAccess_shouldApplyLimit_IfSet()454 {455 $this->createManySitesWithAdminAccess(40);456 // should return all sites by default457 $sites = API::getInstance()->getSitesWithAdminAccess();458 $this->assertReturnedSitesContainsSiteIds(range(1, 40), $sites);459 // return only 5 sites460 $sites = API::getInstance()->getSitesWithAdminAccess(false, false, 5);461 $this->assertReturnedSitesContainsSiteIds(array(1, 2, 3, 4, 5), $sites);462 // return only 10 sites463 $sites = API::getInstance()->getSitesWithAdminAccess(false, false, 10);464 $this->assertReturnedSitesContainsSiteIds(range(1, 10), $sites);465 }466 public function test_getSitesWithAdminAccess_shouldApplyPattern_IfSetAndFindBySiteName()467 {468 $this->createManySitesWithAdminAccess(40);469 // by site name470 $sites = API::getInstance()->getSitesWithAdminAccess(false, 'site38');471 $this->assertReturnedSitesContainsSiteIds(array(38), $sites);472 }473 public function test_getSitesWithAdminAccess_shouldApplyPattern_IfSetAndFindByUrl()474 {475 $this->createManySitesWithAdminAccess(40);476 $sites = API::getInstance()->getSitesWithAdminAccess(false, 'piwik38.o');477 $this->assertReturnedSitesContainsSiteIds(array(38), $sites);478 }479 public function test_getSitesWithAdminAccess_shouldApplyPattern_AndFindMany()480 {481 $this->createManySitesWithAdminAccess(40);482 $sites = API::getInstance()->getSitesWithAdminAccess(false, '5');483 $this->assertReturnedSitesContainsSiteIds(array(5, 15, 25, 35), $sites);484 }485 public function test_getSitesWithAdminAccess_shouldApplyPatternAndLimit()486 {487 $this->createManySitesWithAdminAccess(40);488 $sites = API::getInstance()->getSitesWithAdminAccess(false, '5', 2);489 $this->assertReturnedSitesContainsSiteIds(array(5, 15), $sites);490 }491 private function createManySitesWithAdminAccess($numSites)492 {493 for ($i = 1; $i <= $numSites; $i++) {494 API::getInstance()->addSite("site" . $i, array("http://piwik$i.org"));495 }496 FakeAccess::setIdSitesAdmin(range(1, $numSites));497 }498 private function assertReturnedSitesContainsSiteIds($expectedSiteIds, $sites)499 {500 $this->assertCount(count($expectedSiteIds), $sites);501 foreach ($sites as $site) {502 $key = array_search($site['idsite'], $expectedSiteIds);503 $this->assertNotFalse($key, 'Did not find expected siteId "' . $site['idsite'] . '" in the expected siteIds');504 unset($expectedSiteIds[$key]);505 }506 $siteIds = var_export($expectedSiteIds, 1);507 $this->assertEmpty($expectedSiteIds, 'Not all expected sites were found, remaining site ids: ' . $siteIds);508 }509 /**510 * there is no admin site available -> array()511 */512 public function test_getSitesWithViewAccess_ReturnsNothing_IfUserHasNoViewOrAdminAccess()513 {514 FakeAccess::setIdSitesView(array());515 FakeAccess::setIdSitesAdmin(array());516 $sites = API::getInstance()->getSitesWithViewAccess();517 $this->assertEquals(array(), $sites);518 }519 /**520 * normal case, admin and view and noaccess website => return only admin521 */522 public function test_getSitesWithViewAccess_ReturnsSitesWithViewAccess()523 {524 API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"));525 API::getInstance()->addSite("site2", array("http://piwik.com/test/"));526 API::getInstance()->addSite("site3", array("http://piwik.org"));527 $resultWanted = array(528 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', "excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),529 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', "excluded_ips" => "", 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),530 );531 FakeAccess::setIdSitesView(array(1, 3));532 FakeAccess::setIdSitesAdmin(array());533 $sites = API::getInstance()->getSitesWithViewAccess();534 // we don't test the ts_created535 unset($sites[0]['ts_created']);536 unset($sites[1]['ts_created']);537 $this->assertEquals($resultWanted, $sites);538 }539 /**540 * there is no admin site available -> array()541 */542 public function test_getSitesWithAtLeastViewAccess_ReturnsNothing_WhenUserHasNoAccess()543 {544 FakeAccess::setIdSitesView(array());545 FakeAccess::setIdSitesAdmin(array());546 $sites = API::getInstance()->getSitesWithAtLeastViewAccess();547 $this->assertEquals(array(), $sites);548 }549 /**550 * normal case, admin and view and noaccess website => return only admin551 */552 public function test_getSitesWithAtLeastViewAccess_ReturnsSitesWithViewAccess()553 {554 API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com/test/"), $ecommerce = 1);555 API::getInstance()->addSite("site2", array("http://piwik.com/test/"));556 API::getInstance()->addSite("site3", array("http://piwik.org"));557 $resultWanted = array(558 0 => array("idsite" => 1, "name" => "site1", "main_url" => "http://piwik.net", "ecommerce" => 1, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),559 1 => array("idsite" => 3, "name" => "site3", "main_url" => "http://piwik.org", "ecommerce" => 0, "excluded_ips" => "", 'sitesearch' => 1, 'sitesearch_keyword_parameters' => '', 'sitesearch_category_parameters' => '', 'excluded_parameters' => '', 'excluded_user_agents' => '', 'timezone' => 'UTC', 'currency' => 'USD', 'group' => '', 'keep_url_fragment' => 0, 'type' => 'website', 'exclude_unknown_urls' => 0),560 );561 FakeAccess::setIdSitesView(array(1, 3));562 FakeAccess::setIdSitesAdmin(array());563 $sites = API::getInstance()->getSitesWithAtLeastViewAccess();564 // we don't test the ts_created565 unset($sites[0]['ts_created']);566 unset($sites[1]['ts_created']);567 $this->assertEquals($resultWanted, $sites);568 }569 /**570 * no urls for this site => array()571 */572 public function test_getSiteUrlsFromId_ReturnsMainUrlOnly_WhenNoAliasUrls()573 {574 $idsite = API::getInstance()->addSite("site1", array("http://piwik.net"));575 $urls = API::getInstance()->getSiteUrlsFromId($idsite);576 $this->assertEquals(array("http://piwik.net"), $urls);577 }578 /**579 * normal case580 */581 public function test_getSiteUrlsFromId_ReturnsMainAndAliasUrls()582 {583 $site = array("http://piwik.net",584 "http://piwik.org",585 "http://piwik.org",586 "http://piwik.com");587 sort($site);588 $idsite = API::getInstance()->addSite("site1", $site);589 $siteWanted = array("http://piwik.net",590 "http://piwik.org",591 "http://piwik.com");592 sort($siteWanted);593 $urls = API::getInstance()->getSiteUrlsFromId($idsite);594 $this->assertEquals($siteWanted, $urls);595 }596 /**597 * wrongId => exception598 * @expectedException \Exception599 */600 public function test_getSiteUrlsFromId_ThrowsException_WhenSiteIdIsIncorrect()601 {602 FakeAccess::setIdSitesView(array(3));603 FakeAccess::setIdSitesAdmin(array());604 API::getInstance()->getSiteUrlsFromId(1);605 }606 /**607 * one url => no change to alias urls608 */609 public function test_updateSite_WithOneUrl_RemovesAliasUrls_AndUpdatesTheSiteCorrectly()610 {611 $urls = array("http://piwiknew.com",612 "http://piwiknew.net",613 "http://piwiknew.org",614 "http://piwiknew.fr");615 $idsite = API::getInstance()->addSite("site1", $urls);616 $newMainUrl = "http://main.url";617 // Also test that the group was set to empty, and is searchable618 $websites = API::getInstance()->getSitesFromGroup('');619 $this->assertEquals(1, count($websites));620 // the Update doesn't change the group field621 API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl);622 $websites = API::getInstance()->getSitesFromGroup('');623 $this->assertEquals(1, count($websites));624 // Updating the group to something625 $group = 'something';626 API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = true, $ss_kwd = null, $ss_cat = '', $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group);627 $websites = API::getInstance()->getSitesFromGroup($group);628 $this->assertEquals(1, count($websites));629 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($websites[0]['ts_created'])));630 // Updating the group to nothing631 $group = '';632 $type = 'mobileAppTest';633 API::getInstance()->updateSite($idsite, "test toto@{}", $newMainUrl, $ecommerce = 0, $ss = false, $ss_kwd = '', $ss_cat = null, $ips = null, $parametersExclude = null, $timezone = null, $currency = null, $group, $startDate = '2010-01-01', $excludedUserAgent = null, $keepUrlFragment = 1, $type);634 $websites = API::getInstance()->getSitesFromGroup($group);635 $this->assertEquals(1, count($websites));636 $this->assertEquals('2010-01-01', date('Y-m-d', strtotime($websites[0]['ts_created'])));637 // Test setting the website type638 $this->assertEquals($type, Site::getTypeFor($idsite));639 // Check Alias URLs contain only main url640 $allUrls = API::getInstance()->getSiteUrlsFromId($idsite);641 $this->assertEquals($newMainUrl, $allUrls[0]);642 $aliasUrls = array_slice($allUrls, 1);643 $this->assertEquals(array(), $aliasUrls);644 }645 /**646 * strange name and NO URL => name ok, main_url not updated647 */648 public function test_updateSite_WithStrangeName_AndNoAliasUrls_UpdatesTheName_ButNoUrls()649 {650 $idsite = API::getInstance()->addSite("site1", "http://main.url");651 $newName = "test toto@{'786'}";652 API::getInstance()->updateSite($idsite, $newName);653 $site = API::getInstance()->getSiteFromId($idsite);654 $this->assertEquals($newName, $site['name']);655 // url didn't change because parameter url NULL in updateSite656 $this->assertEquals("http://main.url", $site['main_url']);657 }658 /**659 * several urls => both main and alias are updated660 * also test the update of group field661 */662 public function test_updateSite_WithSeveralUrlsAndGroup_UpdatesGroupAndUrls()663 {664 $urls = array("http://piwiknew.com",665 "http://piwiknew.net",666 "http://piwiknew.org",667 "http://piwiknew.fr");668 $group = 'GROUP Before';669 $idsite = API::getInstance()->addSite("site1", $urls, $ecommerce = 1,670 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,671 $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group, $startDate = '2011-01-01');672 $websites = API::getInstance()->getSitesFromGroup($group);673 $this->assertEquals(1, count($websites));674 $newurls = array("http://piwiknew2.com",675 "http://piwiknew2.net",676 "http://piwiknew2.org",677 "http://piwiknew2.fr");678 $groupAfter = ' GROUP After';679 API::getInstance()->updateSite($idsite, "test toto@{}", $newurls, $ecommerce = 0,680 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null,681 $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $groupAfter);682 // no result for the group before update683 $websites = API::getInstance()->getSitesFromGroup($group);684 $this->assertEquals(0, count($websites));685 // Testing that the group was updated properly (and testing that the group value is trimmed before inserted/searched)686 $websites = API::getInstance()->getSitesFromGroup($groupAfter . ' ');687 $this->assertEquals(1, count($websites));688 $this->assertEquals('2011-01-01', date('Y-m-d', strtotime($websites[0]['ts_created'])));689 // Test fetch website groups690 $expectedGroups = array(trim($groupAfter));691 $fetched = API::getInstance()->getSitesGroups();692 $this->assertEquals($expectedGroups, $fetched);693 $allUrls = API::getInstance()->getSiteUrlsFromId($idsite);694 sort($allUrls);695 sort($newurls);696 $this->assertEquals($newurls, $allUrls);697 }698 /**699 * @expectedException \Exception700 * @expectedExceptionMessage Only 100 characters are allowed701 */702 public function test_updateSite_ShouldFailAndNotUpdateSite_IfASettingIsInvalid()703 {704 $type = MobileAppMeasurable\Type::ID;705 $idSite = $this->addSiteWithType($type, array());706 try {707 $this->updateSiteSettings($idSite, 'newSiteName', array('app_id' => str_pad('t', 589, 't')));708 } catch (Exception $e) {709 // verify nothing was updated (not even the name)710 $measurable = new Measurable($idSite);711 $this->assertNotEquals('newSiteName', $measurable->getName());712 throw $e;713 }714 }715 public function test_updateSite_ShouldSavePassedMeasurableSettings_IfSettingsAreValid()716 {717 $type = MobileAppMeasurable\Type::ID;718 $idSite = $this->addSiteWithType($type, array());719 $this->assertSame(1, $idSite);720 $this->updateSiteSettings($idSite, 'newSiteName', $settings = array('app_id' => 'org.piwik.mobile2'));721 // verify it was updated722 $measurable = new Measurable($idSite);723 $this->assertSame('newSiteName', $measurable->getName());724 $this->assertSame('org.piwik.mobile2', $measurable->getSettingValue('app_id'));725 }726 public function test_updateSite_CorreclySavesExcludedUnknownUrlSettings()727 {728 $idSite = API::getInstance()->addSite("site1", array("http://piwik.net"));729 $site = API::getInstance()->getSiteFromId($idSite);730 $this->assertEquals(0, $site['exclude_unknown_urls']);731 API::getInstance()->updateSite($idSite, $siteName = null, $urls = null, $ecommerce = null, $siteSearch = null,732 $searchKeywordParams = null, $searchCategoryParams = null, $excludedIps = null, $excludedQueryParameters = null,733 $timzeone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null,734 $keepUrlFragments = null, $type = null, $settings = null, $excludeUnknownUrls = true);735 $site = API::getInstance()->getSiteFromId($idSite);736 $this->assertEquals(1, $site['exclude_unknown_urls']);737 }738 /**739 * @expectedException Exception740 * @expectedExceptionMessage SitesManager_ExceptionDeleteSite741 */742 public function test_delete_ShouldNotDeleteASiteInCaseThereIsOnlyOneSite()743 {744 $siteId1 = $this->_addSite();745 $this->assertHasSite($siteId1);746 try {747 API::getInstance()->deleteSite($siteId1);748 $this->fail('an expected exception was not raised');749 } catch (Exception $e) {750 $this->assertHasSite($siteId1);751 throw $e;752 }753 }754 /**755 * @expectedException Exception756 * @expectedExceptionMessage website id = 99999498 not found757 */758 public function test_delete_ShouldTriggerException_IfGivenSiteDoesNotExist()759 {760 API::getInstance()->deleteSite(99999498);761 }762 public function test_delete_ShouldActuallyRemoveAnExistingSiteButOnlyTheGivenSite()763 {764 $this->_addSite();765 $siteId1 = $this->_addSite();766 $siteId2 = $this->_addSite();767 $this->assertHasSite($siteId1);768 $this->assertHasSite($siteId2);769 API::getInstance()->deleteSite($siteId1);770 $this->assertHasNotSite($siteId1);771 $this->assertHasSite($siteId2);772 }773 public function test_delete_ShouldTriggerAnEventOnceSiteWasActuallyDeleted()774 {775 $called = 0;776 $deletedSiteId = null;777 Piwik::addAction('SitesManager.deleteSite.end', function ($param) use (&$called, &$deletedSiteId) {778 $called++;779 $deletedSiteId = $param;780 });781 $this->_addSite();782 $siteId1 = $this->_addSite();783 API::getInstance()->deleteSite($siteId1);784 $this->assertSame(1, $called);785 $this->assertSame($siteId1, $deletedSiteId);786 }787 private function assertHasSite($idSite)788 {789 $model = new Model();790 $siteInfo = $model->getSiteFromId($idSite);791 $this->assertNotEmpty($siteInfo);792 }793 private function assertHasNotSite($idSite)794 {795 $model = new Model();796 $siteInfo = $model->getSiteFromId($idSite);797 $this->assertEmpty($siteInfo);798 }799 public function testGetSitesGroups()800 {801 $groups = array('group1', ' group1 ', '', 'group2');802 $expectedGroups = array('group1', '', 'group2');803 foreach ($groups as $group) {804 API::getInstance()->addSite("test toto@{}", 'http://example.org', $ecommerce = 1, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group);805 }806 $this->assertEquals($expectedGroups, API::getInstance()->getSitesGroups());807 }808 public function getInvalidTimezoneData()809 {810 return array(811 array('UTC+15'),812 array('Paris'),813 );814 }815 /**816 *817 * @dataProvider getInvalidTimezoneData818 * @expectedException \Exception819 */820 public function test_addSite_WithInvalidTimezone_ThrowsException($timezone)821 {822 API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,823 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, $ip = '', $params = '', $timezone);824 }825 /**826 * @expectedException \Exception827 */828 public function test_addSite_WithInvalidCurrency_ThrowsException()829 {830 $invalidCurrency = '€';831 API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,832 $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, '', 'UTC', $invalidCurrency);833 }834 public function test_setDefaultTimezone_AndCurrency_AndExcludedQueryParameters_AndExcludedIps_UpdatesDefaultsCorreclty()835 {836 // test that they return default values837 $defaultTimezone = API::getInstance()->getDefaultTimezone();838 $this->assertEquals('UTC', $defaultTimezone);839 $defaultCurrency = API::getInstance()->getDefaultCurrency();840 $this->assertEquals('USD', $defaultCurrency);841 $excludedIps = API::getInstance()->getExcludedIpsGlobal();842 $this->assertEquals('', $excludedIps);843 $excludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal();844 $this->assertEquals('', $excludedQueryParameters);845 // test that when not specified, defaults are set as expected846 $idsite = API::getInstance()->addSite("site1", array('http://example.org'));847 $site = new Site($idsite);848 $this->assertEquals('UTC', $site->getTimezone());849 $this->assertEquals('USD', $site->getCurrency());850 $this->assertEquals('', $site->getExcludedQueryParameters());851 $this->assertEquals('', $site->getExcludedIps());852 $this->assertEquals(false, $site->isEcommerceEnabled());853 // set the global timezone and get it854 $newDefaultTimezone = 'UTC+5.5';855 API::getInstance()->setDefaultTimezone($newDefaultTimezone);856 $defaultTimezone = API::getInstance()->getDefaultTimezone();857 $this->assertEquals($newDefaultTimezone, $defaultTimezone);858 // set the default currency and get it859 $newDefaultCurrency = 'EUR';860 API::getInstance()->setDefaultCurrency($newDefaultCurrency);861 $defaultCurrency = API::getInstance()->getDefaultCurrency();862 $this->assertEquals($newDefaultCurrency, $defaultCurrency);863 // set the global IPs to exclude and get it864 $newGlobalExcludedIps = '1.1.1.*,1.1.*.*,150.1.1.1';865 API::getInstance()->setGlobalExcludedIps($newGlobalExcludedIps);866 $globalExcludedIps = API::getInstance()->getExcludedIpsGlobal();867 $this->assertEquals($newGlobalExcludedIps, $globalExcludedIps);868 // set the global URL query params to exclude and get it869 $newGlobalExcludedQueryParameters = 'PHPSESSID,blabla, TesT';870 // removed the space871 $expectedGlobalExcludedQueryParameters = 'PHPSESSID,blabla,TesT';872 API::getInstance()->setGlobalExcludedQueryParameters($newGlobalExcludedQueryParameters);873 $globalExcludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal();874 $this->assertEquals($expectedGlobalExcludedQueryParameters, $globalExcludedQueryParameters);875 // create a website and check that default currency and default timezone are set876 // however, excluded IPs and excluded query Params are not returned877 $idsite = API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0,878 $siteSearch = 0, $searchKeywordParameters = 'test1,test2', $searchCategoryParameters = 'test2,test1',879 '', '', $newDefaultTimezone);880 $site = new Site($idsite);881 $this->assertEquals($newDefaultTimezone, $site->getTimezone());882 $this->assertEquals(date('Y-m-d'), $site->getCreationDate()->toString());883 $this->assertEquals($newDefaultCurrency, $site->getCurrency());884 $this->assertEquals('', $site->getExcludedIps());885 $this->assertEquals('', $site->getExcludedQueryParameters());886 $this->assertEquals('test1,test2', $site->getSearchKeywordParameters());887 $this->assertEquals('test2,test1', $site->getSearchCategoryParameters());888 $this->assertFalse($site->isSiteSearchEnabled());889 $this->assertFalse(Site::isSiteSearchEnabledFor($idsite));890 $this->assertFalse($site->isEcommerceEnabled());891 $this->assertFalse(Site::isEcommerceEnabledFor($idsite));892 }893 public function test_getSitesIdFromSiteUrl_AsSuperUser_ReturnsTheRequestedSiteIds()894 {895 API::getInstance()->addSite("site1", array("http://piwik.net", "http://piwik.com"));896 API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net"));897 API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org"));898 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.org');899 $this->assertTrue(count($idsites) == 1);900 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.org');901 $this->assertTrue(count($idsites) == 1);902 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');903 $this->assertTrue(count($idsites) == 2);904 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');905 $this->assertTrue(count($idsites) == 3);906 }907 public function test_getSitesIdFromSiteUrl_MatchesBothHttpAndHttpsUrls_AsSuperUser()908 {909 API::getInstance()->addSite("site1", array("https://piwik.org", "http://example.com", "fb://special-url"));910 $this->assert_getSitesIdFromSiteUrl_matchesBothHttpAndHttpsUrls();911 }912 public function test_getSitesIdFromSiteUrl_MatchesBothHttpAndHttpsUrls_AsUserWithViewPermission()913 {914 API::getInstance()->addSite("site1", array("https://piwik.org", "http://example.com", "fb://special-url"));915 APIUsersManager::getInstance()->addUser("user1", "geqgegagae", "tegst@tesgt.com", "alias");916 APIUsersManager::getInstance()->setUserAccess("user1", "view", array(1));917 // Make sure we're not Super user918 FakeAccess::$superUser = false;919 FakeAccess::$identity = 'user1';920 $this->assertFalse(Piwik::hasUserSuperUserAccess());921 $this->assert_getSitesIdFromSiteUrl_matchesBothHttpAndHttpsUrls();922 }923 private function assert_getSitesIdFromSiteUrl_matchesBothHttpAndHttpsUrls()924 {925 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.org');926 $this->assertTrue(count($idsites) == 1);927 $idsites = API::getInstance()->getSitesIdFromSiteUrl('piwik.org');928 $this->assertTrue(count($idsites) == 1);929 $idsites = API::getInstance()->getSitesIdFromSiteUrl('https://www.piwik.org');930 $this->assertTrue(count($idsites) == 1);931 $idsites = API::getInstance()->getSitesIdFromSiteUrl('https://example.com');932 $this->assertTrue(count($idsites) == 1);933 $idsites = API::getInstance()->getSitesIdFromSiteUrl("fb://special-url");934 $this->assertTrue(count($idsites) == 1);935 $idsites = API::getInstance()->getSitesIdFromSiteUrl('https://random-example.com');936 $this->assertTrue(count($idsites) == 0);937 $idsites = API::getInstance()->getSitesIdFromSiteUrl('not-found.piwik.org');938 $this->assertTrue(count($idsites) == 0);939 $idsites = API::getInstance()->getSitesIdFromSiteUrl('piwik.org/not-found/');940 $this->assertTrue(count($idsites) == 0);941 }942 public function test_getSitesIdFromSiteUrl_AsUser()943 {944 API::getInstance()->addSite("site1", array("http://www.piwik.net", "https://piwik.com"));945 API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net"));946 API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org"));947 APIUsersManager::getInstance()->addUser("user1", "geqgegagae", "tegst@tesgt.com", "alias");948 APIUsersManager::getInstance()->setUserAccess("user1", "view", array(1));949 APIUsersManager::getInstance()->addUser("user2", "geqgegagae", "tegst2@tesgt.com", "alias");950 APIUsersManager::getInstance()->setUserAccess("user2", "view", array(1));951 APIUsersManager::getInstance()->setUserAccess("user2", "admin", array(3));952 APIUsersManager::getInstance()->addUser("user3", "geqgegagae", "tegst3@tesgt.com", "alias");953 APIUsersManager::getInstance()->setUserAccess("user3", "view", array(1, 2));954 APIUsersManager::getInstance()->setUserAccess("user3", "admin", array(3));955 FakeAccess::$superUser = false;956 FakeAccess::$identity = 'user1';957 FakeAccess::setIdSitesView(array(1));958 FakeAccess::setIdSitesAdmin(array());959 $this->assertFalse(Piwik::hasUserSuperUserAccess());960 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');961 $this->assertEquals(1, count($idsites));962 // testing URL normalization963 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.com');964 $this->assertEquals(1, count($idsites));965 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');966 $this->assertEquals(1, count($idsites));967 FakeAccess::$superUser = false;968 FakeAccess::$identity = 'user2';969 FakeAccess::setIdSitesView(array(1));970 FakeAccess::setIdSitesAdmin(array(3));971 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');972 $this->assertEquals(2, count($idsites));973 FakeAccess::$superUser = false;974 FakeAccess::$identity = 'user3';975 FakeAccess::setIdSitesView(array(1, 2));976 FakeAccess::setIdSitesAdmin(array(3));977 $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com');978 $this->assertEquals(3, count($idsites));979 $idsites = API::getInstance()->getSitesIdFromSiteUrl('https://www.piwik.com');980 $this->assertEquals(3, count($idsites));981 }982 public function test_getSitesFromTimezones_ReturnsCorrectIdSites()983 {984 API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'UTC');985 $idsite2 = API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'Pacific/Auckland');986 $idsite3 = API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'Pacific/Auckland');987 $idsite4 = API::getInstance()->addSite("site3", array("http://piwik.org"), null, $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, null, null, 'UTC+10');988 $result = API::getInstance()->getSitesIdFromTimezones(array('UTC+10', 'Pacific/Auckland'));989 $this->assertEquals(array($idsite2, $idsite3, $idsite4), $result);990 }991 public function provideContainerConfig()992 {993 return array(994 'Piwik\Access' => new FakeAccess(),995 'Piwik\Plugins\MobileAppMeasurable\Type' => new Type()996 );997 }998}...

Full Screen

Full Screen

MimeTypeTest.php

Source:MimeTypeTest.php Github

copy

Full Screen

...20 {21 $cwd = getcwd();22 chdir(__DIR__.'/../Fixtures');23 try {24 $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));25 } finally {26 chdir($cwd);27 }28 }29 public function testGuessImageWithoutExtension()30 {31 $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));32 }33 public function testGuessImageWithDirectory()34 {35 $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');36 MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');37 }38 public function testGuessImageWithFileBinaryMimeTypeGuesser()39 {40 $guesser = MimeTypeGuesser::getInstance();41 $guesser->register(new FileBinaryMimeTypeGuesser());42 $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));43 }44 public function testGuessImageWithKnownExtension()45 {46 $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.gif'));47 }48 public function testGuessFileWithUnknownExtension()49 {50 $this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));51 }52 /**53 * @requires PHP 7.054 */55 public function testGuessWithDuplicatedFileType()56 {57 if ('application/zip' === MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx')) {58 $this->addToAssertionCount(1);59 return;60 }61 $this->assertSame('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'));62 }63 public function testGuessWithIncorrectPath()64 {65 $this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');66 MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/not_here');67 }68 public function testGuessWithNonReadablePath()69 {70 if ('\\' === \DIRECTORY_SEPARATOR) {71 $this->markTestSkipped('Can not verify chmod operations on Windows');72 }73 if (!getenv('USER') || 'root' === getenv('USER')) {74 $this->markTestSkipped('This test will fail if run under superuser');75 }76 $path = __DIR__.'/../Fixtures/to_delete';77 touch($path);78 @chmod($path, 0333);79 if ('0333' == substr(sprintf('%o', fileperms($path)), -4)) {80 $this->expectException('Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException');81 MimeTypeGuesser::getInstance()->guess($path);82 } else {83 $this->markTestSkipped('Can not verify chmod operations, change of file permissions failed');84 }85 }86 public static function tearDownAfterClass()87 {88 $path = __DIR__.'/../Fixtures/to_delete';89 if (file_exists($path)) {90 @chmod($path, 0666);91 @unlink($path);92 }93 }94}...

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$obj1 = with::getInstance();2$obj2 = with::getInstance();3$obj3 = with::getInstance();4$obj4 = with::getInstance();5$obj5 = with::getInstance();6$obj6 = with::getInstance();7$obj7 = with::getInstance();8$obj8 = with::getInstance();9$obj9 = with::getInstance();10$obj10 = with::getInstance();11$obj11 = with::getInstance();12$obj1->setVar1(1);13$obj2->setVar1(2);14$obj3->setVar1(3);15$obj4->setVar1(4);16$obj5->setVar1(5);17$obj6->setVar1(6);18$obj7->setVar1(7);19$obj8->setVar1(8);20$obj9->setVar1(9);21$obj10->setVar1(10);22$obj11->setVar1(11);23$obj1->getvar1();24$obj2->getvar1();25$obj3->getvar1();26$obj4->getvar1();27$obj5->getvar1();28$obj6->getvar1();29$obj7->getvar1();30$obj8->getvar1();31$obj9->getvar1();32$obj10->getvar1();33$obj11->getvar1();

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$object = with::getInstance();2$object->hello();3$object = with::getInstance();4$object->hello();5$object = with::getInstance();6$object->hello();7$object = with::getInstance();8$object->hello();9$object = with::getInstance();10$object->hello();11$object = with::getInstance();12$object->hello();13$object = with::getInstance();14$object->hello();15$object = with::getInstance();16$object->hello();17$object = with::getInstance();18$object->hello();19$object = with::getInstance();20$object->hello();21$object = with::getInstance();22$object->hello();23$object = with::getInstance();24$object->hello();25$object = with::getInstance();26$object->hello();27$object = with::getInstance();28$object->hello();29$object = with::getInstance();30$object->hello();31$object = with::getInstance();32$object->hello();33$object = with::getInstance();34$object->hello();

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$with = new with();2$with->getInstance();3$with = new with();4$with->getInstance();5$with = new with();6$with->getInstance();7$with = new with();8$with->getInstance();9$with = new with();10$with->getInstance();11$with = new with();12$with->getInstance();13$with = new with();14$with->getInstance();15$with = new with();16$with->getInstance();17$with = new with();18$with->getInstance();19$with = new with();20$with->getInstance();21$with = new with();22$with->getInstance();23$with = new with();24$with->getInstance();25$with = new with();26$with->getInstance();27$with = new with();28$with->getInstance();29$with = new with();30$with->getInstance();31$with = new with();32$with->getInstance();33$with = new with();34$with->getInstance();35$with = new with();36$with->getInstance();

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$object = with::getInstance();2$object->printData();3$object = with::getInstance();4$object->printData();5$object = with::getInstance();6$object->printData();7$object = with::getInstance();8$object->printData();9$object = with::getInstance();10$object->printData();11$object = with::getInstance();12$object->printData();13$object = with::getInstance();14$object->printData();15$object = with::getInstance();16$object->printData();17$object = with::getInstance();18$object->printData();19$object = with::getInstance();20$object->printData();21$object = with::getInstance();22$object->printData();23$object = with::getInstance();24$object->printData();25$object = with::getInstance();26$object->printData();27$object = with::getInstance();28$object->printData();29$object = with::getInstance();30$object->printData();31$object = with::getInstance();32$object->printData();33$object = with::getInstance();34$object->printData();

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$obj = Singleton::getInstance();2$obj1 = Singleton::getInstance();3$obj2 = Singleton::getInstance();4$obj3 = Singleton::getInstance();5$obj4 = Singleton::getInstance();6$obj5 = Singleton::getInstance();7$obj6 = Singleton::getInstance();8$obj7 = Singleton::getInstance();9$obj8 = Singleton::getInstance();10$obj9 = Singleton::getInstance();11$obj10 = Singleton::getInstance();12$obj11 = Singleton::getInstance();13$obj12 = Singleton::getInstance();14$obj13 = Singleton::getInstance();15$obj14 = Singleton::getInstance();16$obj15 = Singleton::getInstance();17$obj16 = Singleton::getInstance();18$obj17 = Singleton::getInstance();19$obj18 = Singleton::getInstance();20$obj19 = Singleton::getInstance();21$obj20 = Singleton::getInstance();22$obj21 = Singleton::getInstance();23$obj22 = Singleton::getInstance();24$obj23 = Singleton::getInstance();

Full Screen

Full Screen

getInstance

Using AI Code Generation

copy

Full Screen

1$with = with::getInstance();2$with->setVar('name', 'with');3echo $with->getVar('name');4$with = with::getInstance();5echo $with->getVar('name');6$with = with::getInstance();7echo $with->getVar('name');8$with = with::getInstance();9echo $with->getVar('name');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger getInstance code on LambdaTest Cloud Grid

Execute automation tests with getInstance on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful