/** * @dataProvider validateProvider */ public function testValidate($path, $isExceptionExpected, $isUserInDatabase, $isFull, $codeExists) { $ds = DIRECTORY_SEPARATOR; $data = Yaml::parse(file_get_contents($path . $ds . 'manifest.yml')); $properties['properties'] = $data['properties']; if ($isExceptionExpected) { $this->setExpectedException('Exception'); } m::getConfiguration()->allowMockingNonExistentMethods(true); //init importer $this->importer->setRootPath($path); $resolver = new Resolver($path); $this->importer->setConfiguration($resolver->resolve($data)); //objectManager $wsRepo = $this->mock('Claroline\\CoreBundle\\Repository\\WorkspaceRepository'); $this->om->shouldReceive('getRepository')->with('Claroline\\CoreBundle\\Entity\\Workspace\\Workspace')->andReturn($wsRepo); if ($codeExists) { $wsRepo->shouldReceive('findOneByCode')->once()->with($properties['properties']['code'])->andThrow('Exception'); } else { $wsRepo->shouldReceive('findOneByCode')->once()->with($properties['properties']['code'])->andReturn('ws'); } $userRepo = $this->mock('Claroline\\CoreBundle\\Repository\\UserRepository'); if ($isUserInDatabase && !$isFull) { $this->om->shouldReceive('getRepository')->andReturn($userRepo); $userRepo->shouldReceive('findOneByUsername')->andReturn('user'); } if (!$isUserInDatabase && !$isFull) { $this->om->shouldReceive('getRepository')->andReturn($userRepo); $userRepo->shouldReceive('findOneByUsername')->andThrow('Exception'); } $this->importer->validate($properties); }
/** * Assume the archive is already opened. * * @param $extractPath * @param $archive */ private function extract($extractPath, $archive) { $res = $archive->extractTo($extractPath); $archive->close(); $this->setExtractPath($extractPath); $resolver = new Resolver($extractPath); $this->data = $resolver->resolve(); }
/** * @dataProvider validateProvider */ public function testValidate($basePath, $configPath, $isExceptionExpected) { $this->importer->setRootPath($basePath); if ($isExceptionExpected) { $this->setExpectedException('Symfony\\Component\\Config\\Definition\\Exception\\InvalidConfigurationException'); } $resolver = new Resolver($basePath, $configPath); $data = $resolver->resolve(); $this->importer->validate($data); }
/** * @dataProvider validateProvider */ public function testValidate($basePath, $configPath, $isExceptionExpected, $rolefile) { if ($isExceptionExpected) { $this->setExpectedException('Symfony\\Component\\Config\\Definition\\Exception\\InvalidConfigurationException'); } $roles = Yaml::parse(file_get_contents($rolefile)); $resolver = new Resolver($basePath, $configPath); $data = $resolver->resolve(); $this->importer->setConfiguration($roles); $this->importer->validate($data); }
/** * @dataProvider validateProvider */ public function testValidate($basePath, $isExceptionExpected, $rolefile, $managerPath) { $this->importer->setConfiguration(Yaml::parse(file_get_contents($rolefile))); if ($isExceptionExpected) { $this->setExpectedException('Symfony\\Component\\Config\\Definition\\Exception\\InvalidConfigurationException'); } $resolver = new Resolver($basePath, $managerPath); $data = $resolver->resolve(); $resources['data'] = $data['data']; $this->fileImporter->shouldReceive('validate')->andReturn(true); $this->textImporter->shouldReceive('validate')->andReturn(true); $this->importer->validate($resources); }
public function testValidateGoesWell() { //@todo mock merger // $ds = DIRECTORY_SEPARATOR; $path = __DIR__ . '/../../Stub/transfert/valid/full'; $resolver = new Resolver($path); $data = $resolver->resolve(); // $data = Yaml::parse(file_get_contents($path . $ds . 'manifest.yml')); //workspace properties $properties['properties'] = $data['properties']; $this->workspacePropertiesImporter->shouldReceive('validate')->with($properties)->andReturn(true); $this->workspacePropertiesImporter->shouldReceive('getName')->andReturn('workspace_properties'); $this->workspacePropertiesImporter->shouldReceive('setRootPath')->once()->with($path); $this->workspacePropertiesImporter->shouldReceive('setConfiguration')->once()->with($data); //owner $owner['owner'] = $data['members']['owner']; $this->ownerImporter->shouldReceive('validate')->with($owner)->andReturn(true); $this->ownerImporter->shouldReceive('getName')->andReturn('owner'); $this->ownerImporter->shouldReceive('setRootPath')->once()->with($path); $this->ownerImporter->shouldReceive('setConfiguration')->once()->with($data); //users //@todo check what does the validate get $this->usersImporter->shouldReceive('validate')->andReturn(true); $this->usersImporter->shouldReceive('getName')->andReturn('user'); $this->usersImporter->shouldReceive('setRootPath')->once()->with($path); $this->usersImporter->shouldReceive('setConfiguration')->once()->with($data); //roles //@todo check what does the validate get $this->rolesImporter->shouldReceive('validate')->andReturn(true); $this->rolesImporter->shouldReceive('getName')->andReturn('roles'); $this->rolesImporter->shouldReceive('setRootPath')->once()->with($path); $this->rolesImporter->shouldReceive('setConfiguration')->once()->with($data); //groups //@todo check what does the validate get $this->groupsImporter->shouldReceive('validate')->andReturn(true); $this->groupsImporter->shouldReceive('getName')->andReturn('groups'); $this->groupsImporter->shouldReceive('setRootPath')->once()->with($path); $this->groupsImporter->shouldReceive('setConfiguration')->once()->with($data); //groups //@todo check what does the validate get $this->toolsImporter->shouldReceive('validate')->andReturn(true); $this->toolsImporter->shouldReceive('getName')->andReturn('tools'); $this->toolsImporter->shouldReceive('setRootPath')->once()->with($path); $this->toolsImporter->shouldReceive('setConfiguration')->once()->with($data); $this->manager->validate($path); }
public function getTemplateData(File $file, $refresh = false) { //from cache if (!$refresh) { return $this->importData; } $archive = new \ZipArchive(); $fileName = $file->getBasename('.zip'); $extractPath = $this->templateDirectory . DIRECTORY_SEPARATOR . $fileName; if ($archive->open($file->getPathname())) { $fs = new FileSystem(); $fs->mkdir($extractPath); if (!$archive->extractTo($extractPath)) { throw new \Exception("The workspace archive couldn't be extracted"); } $archive->close(); $resolver = new Resolver($extractPath); $this->importData = $resolver->resolve(); return $this->importData; } throw new \Exception("The workspace archive couldn't be opened"); }