public function tearDown()
 {
     parent::tearDown();
     Subsite::$strict_subdomain_matching = $this->origStrictSubdomainMatching;
 }
 function testStrictSubdomainMatching()
 {
     // Clear existing fixtures
     foreach (DataObject::get('Subsite') as $subsite) {
         $subsite->delete();
     }
     foreach (DataObject::get('SubsiteDomain') as $domain) {
         $domain->delete();
     }
     // Much more expressive than YML in this case
     $subsite1 = $this->createSubsiteWithDomains(array('example.org' => true, 'example.com' => false, '*.wildcard.com' => false));
     $subsite2 = $this->createSubsiteWithDomains(array('www.example.org' => true, 'www.wildcard.com' => false));
     Subsite::$strict_subdomain_matching = false;
     $this->assertEquals($subsite1->ID, Subsite::getSubsiteIDForDomain('example.org'), 'Exact matches without strict checking when not using www prefix');
     $this->assertEquals($subsite1->ID, Subsite::getSubsiteIDForDomain('www.example.org'), 'Matches without strict checking when using www prefix, still matching first domain regardless of www prefix  (falling back to subsite primary key ordering)');
     $this->assertEquals($subsite1->ID, Subsite::getSubsiteIDForDomain('www.example.com'), 'Fuzzy matches without strict checking with www prefix');
     $this->assertEquals(0, Subsite::getSubsiteIDForDomain('www.wildcard.com'), 'Doesn\'t match www prefix without strict check, even if a wildcard subdomain is in place');
     Subsite::$strict_subdomain_matching = true;
     $this->assertEquals($subsite1->ID, Subsite::getSubsiteIDForDomain('example.org'), 'Matches with strict checking when not using www prefix');
     $this->assertEquals($subsite2->ID, Subsite::getSubsiteIDForDomain('www.example.org'), 'Matches with strict checking when using www prefix');
     $this->assertEquals(0, Subsite::getSubsiteIDForDomain('www.example.com'), 'Doesn\'t fuzzy match with strict checking when using www prefix');
     $failed = false;
     try {
         Subsite::getSubsiteIDForDomain('www.wildcard.com');
     } catch (UnexpectedValueException $e) {
         $failed = true;
     }
     $this->assertTrue($failed, 'Fails on multiple matches with strict checking and wildcard vs. www');
 }