/**
  * Ensure with and without filters, we get expected output
  */
 public function testGetChildren()
 {
     $config = $this->objFromFixture('SiteConfig', 'default');
     $parent = $this->objFromFixture('SiteTree', 'sitetreetest-page-1');
     $children = $parent->Children()->toArray();
     $models = array_merge(array($parent), $children);
     // Fake a rebuild task - Populate the object-cache with our fixture data
     foreach ($models as $model) {
         $service = new CacheableNavigationService('Live', $config, $model);
         $service->refreshCachedPage();
     }
     // Fetch the cache
     $objCache = $service->getObjectCache();
     $siteMap = $objCache->get_site_map();
     // Default: No custom filters passed - return everything
     $children = $siteMap[1]->getChildren();
     $this->assertEquals(2, $children->count());
     // Default: No custom filters passed - return everything
     $children = $siteMap[1]->getChildren(true, null);
     $this->assertEquals(2, $children->count());
     // Default: No custom filters passed - return everything
     $children = $siteMap[1]->getChildren(true, array());
     $this->assertEquals(2, $children->count());
     // Default: No custom filters passed - return everything
     $children = $siteMap[1]->getChildren(false, array());
     $this->assertEquals(2, $children->count());
     // Don't filter and still no filters passed
     $children = $siteMap[1]->getChildren(false, null);
     $this->assertEquals(2, $children->count());
     // Don't filter and filters passed
     $children = $siteMap[1]->getChildren(false, array('Title' => 'This is a child page 2'));
     $this->assertEquals(1, $children->count());
     // Do filter and filters passed
     $children = $siteMap[1]->getChildren(true, array('Title' => 'This is a child page 1'));
     $this->assertEquals(2, $children->count());
     // Do filter and filters passed
     $children = $siteMap[1]->getChildren(true, array('Title' => 'This is a child page 2'));
     $this->assertEquals(2, $children->count());
     // Do filter and filters passed
     $children = $siteMap[1]->getChildren(false, array('Title' => 'This is a child page 2'));
     $this->assertEquals(1, $children->count());
     // Do filter and "bad" filter passed
     $children = $siteMap[1]->getChildren(false, array('Title' => 'This is a child page null'));
     $this->assertEquals(0, $children->count());
     $children = $siteMap[1]->getChildren(true, array('Dummy' => null));
     $this->assertEquals(2, $children->count());
     $children = $siteMap[1]->getChildren(false, array('Dummy' => null));
     $this->assertEquals(2, $children->count());
 }
 /**
  * 
  */
 public function testCompleteBuild()
 {
     $model = $this->objFromFixture('SiteTree', 'servicetest-page-1');
     $service = new CacheableNavigationService('Live', null, $model);
     // Cache should be empty
     $cachable = $service->getCacheableFrontEnd()->load($service->getIdentifier());
     $this->assertFalse($cachable->get_completed());
     // Populate the cache with a page
     $service->refreshCachedPage();
     // Set it to complete and re-test
     $service->completeBuild();
     $cachable = $service->getCacheableFrontEnd()->load($service->getIdentifier());
     $this->assertTrue($cachable->get_completed());
 }
 /**
  * 
  * @param array $modes
  * @param boolean $forceRemoval Whether to unset() children in {@link CacheableSiteTree::removeChild()}.
  * @return void
  */
 public function refreshPageCache($modes, $forceRemoval = false)
 {
     // Increase memory to max-allowable
     CacheableConfig::configure_memory_limit();
     //get the unlocked cached Navigation first
     $siteConfig = $this->owner->getSiteConfig();
     if (!$siteConfig->exists()) {
         $siteConfig = SiteConfig::current_site_config();
     }
     foreach ($modes as $stage => $mode) {
         $service = new CacheableNavigationService($mode, $siteConfig);
         $cache_frontend = $service->getCacheableFrontEnd();
         $id = $service->getIdentifier();
         $cached = $cache_frontend->load($id);
         if ($cached) {
             $cached_site_config = $cached->get_site_config();
             if (!$cached_site_config) {
                 $service->refreshCachedConfig();
             }
             $versioned = Versioned::get_one_by_stage(get_class($this->owner), $stage, "\"SiteTree\".\"ID\" = '" . $this->owner->ID . "'");
             if ($versioned) {
                 $service->set_model($versioned);
                 $service->refreshCachedPage($forceRemoval);
             }
         }
     }
 }