Sulu\Bundle\TestBundle\Testing\SuluTestCase::initPhpcr PHP Method

initPhpcr() protected method

NOTE: We could use the document initializer here rather than manually creating the webspace nodes, but it currently adds more overhead and offers no control over *which* webspaces are created, see https://github.com/sulu-io/sulu/pull/2063 for a solution.
protected initPhpcr ( )
    protected function initPhpcr()
    {
        /** @var SessionInterface $session */
        $session = $this->getContainer()->get('sulu_document_manager.default_session');
        $liveSession = $this->getContainer()->get('sulu_document_manager.live_session');
        if ($session->nodeExists('/cmf')) {
            NodeHelper::purgeWorkspace($session);
            $session->save();
        }
        if ($liveSession->nodeExists('/cmf')) {
            NodeHelper::purgeWorkspace($liveSession);
            $liveSession->save();
        }
        if (!$this->importer) {
            $this->importer = new PHPCRImporter($session, $liveSession);
        }
        // initialize the content repository.  in order to speed things up, for
        // each process, we dump the initial state to an XML file and restore
        // it thereafter.
        $initializerDump = __DIR__ . '/../Resources/app/cache/initial.xml';
        $initializerDumpLive = __DIR__ . '/../Resources/app/cache/initial_live.xml';
        if (true === self::$workspaceInitialized) {
            $session->importXml('/', $initializerDump, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
            $session->save();
            $liveSession->importXml('/', $initializerDumpLive, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW);
            $liveSession->save();
            return;
        }
        $filesystem = new Filesystem();
        if (!$filesystem->exists(dirname($initializerDump))) {
            $filesystem->mkdir(dirname($initializerDump));
        }
        $this->getContainer()->get('sulu_document_manager.initializer')->initialize();
        $handle = fopen($initializerDump, 'w');
        $liveHandle = fopen($initializerDumpLive, 'w');
        $session->exportSystemView('/cmf', $handle, false, false);
        $liveSession->exportSystemView('/cmf', $liveHandle, false, false);
        fclose($handle);
        self::$workspaceInitialized = true;
    }

Usage Example

 protected function setUp()
 {
     parent::initPhpcr();
     $this->mapper = $this->getContainer()->get('sulu.content.mapper');
     $this->structureManager = $this->getContainer()->get('sulu.content.structure_manager');
     $this->serializer = $this->getContainer()->get('jms_serializer');
     $this->sessionManager = $this->getContainer()->get('sulu.phpcr.session');
     $this->dataCache = new ArrayCache();
     $this->changesCache = new ArrayCache();
     $this->cache = new DoctrineCacheProvider($this->mapper, $this->structureManager, $this->serializer, $this->dataCache, $this->changesCache);
 }
All Usage Examples Of Sulu\Bundle\TestBundle\Testing\SuluTestCase::initPhpcr