/** * @test */ public function findPresetByDimensionValuesWithoutExistingUriSegmentReturnsNull() { $source = new ConfigurationContentDimensionPresetSource(); $source->setConfiguration($this->validConfiguration); $preset = $source->findPresetByDimensionValues('language', array('ja_JP', 'mul_ZZ')); $this->assertNull($preset); }
/** * @dataProvider contextPathsAndRequestPathsDataProvider * @test */ public function resolveConsidersDimensionValuesPassedViaTheContextPathForRenderingTheUrl($contextPath, $expectedUriPath) { $this->contentDimensionPresetSource->setConfiguration(array('language' => array('default' => 'en_US', 'defaultPreset' => 'en_US', 'presets' => array('en_US' => array('label' => 'English (US)', 'values' => array('en_US'), 'uriSegment' => 'en'), 'de_DE' => array('label' => 'Deutsch', 'values' => array('de_DE', 'en_US'), 'uriSegment' => 'de'))), 'country' => array('default' => 'global', 'defaultPreset' => 'global', 'presets' => array('global' => array('label' => 'Global', 'values' => array('global'), 'uriSegment' => 'global'), 'us' => array('label' => 'USA', 'values' => array('us'), 'uriSegment' => 'us'), 'de' => array('label' => 'Deutschland', 'values' => array('de'), 'uriSegment' => 'de'))))); $mockContext = $this->buildMockContext(array('workspaceName' => 'live')); $mockContext->mockSite = $this->getMockBuilder(Site::class)->disableOriginalConstructor()->getMock(); $mockSiteNode = $this->buildSiteNode($mockContext, '/sites/examplecom'); $mockSiteNode->expects($this->any())->method('getContextPath')->will($this->returnValue('/sites/examplecom')); $mockContext->mockSiteNode = $mockSiteNode; $mockSubNode = $this->buildSubNode($mockContext->mockSiteNode, 'features'); $mockSubNode->mockProperties['uriPathSegment'] = 'features'; $mockSubNode->expects($this->any())->method('getContextPath')->will($this->returnValue('/sites/examplecom/features')); $mockContext->expects($this->any())->method('getNode')->will($this->returnCallback(function ($nodePath) use($mockSubNode, $mockSiteNode) { switch ($nodePath) { case '/sites/examplecom/features': return $mockSubNode; case '/sites/examplecom': return $mockSiteNode; default: return null; } })); $routeValues = array('node' => $contextPath); $this->assertTrue($this->routePartHandler->resolve($routeValues)); $this->assertSame($expectedUriPath, $this->routePartHandler->getValue()); }
/** * Return the presets in the correct order, taking possibly-overridden presets into account * * @return array * @throws TypoScriptException */ protected function getPresetsInCorrectOrder() { $dimension = $this->getDimension(); $allDimensions = $this->configurationContentDimensionPresetSource->getAllPresets(); if (!isset($allDimensions[$dimension])) { throw new TypoScriptException(sprintf('Dimension "%s" was referenced, but not configured.', $dimension), 1415880445); } $allPresetsOfChosenDimension = $allDimensions[$dimension]['presets']; $presetNames = $this->getPresets(); if ($presetNames === NULL) { $presetNames = array_keys($allPresetsOfChosenDimension); } elseif (!is_array($presetNames)) { throw new TypoScriptException('The configured preset in TypoScript was no array.', 1415888652); } $resultingPresets = array(); foreach ($presetNames as $presetName) { if (!isset($allPresetsOfChosenDimension[$presetName])) { throw new TypoScriptException(sprintf('The preset name "%s" does not exist in the chosen dimension. Valid values are: %s', $presetName, implode(', ', array_keys($allPresetsOfChosenDimension))), 1415889492); } $resultingPresets[$presetName] = $allPresetsOfChosenDimension[$presetName]; } return $resultingPresets; }
/** * * @param array $allowedCombination * @param $allDimensionPresets * @return null|NodeInterface */ protected function findAcceptableNode(array $allowedCombination, array $allDimensionPresets) { $pinnedDimensionName = $this->getDimension(); foreach ($allowedCombination[$pinnedDimensionName] as $allowedPresetIdentifier) { $acceptableCombination = [$pinnedDimensionName => $allDimensionPresets[$pinnedDimensionName]['presets'][$allowedPresetIdentifier]['values']]; $allowedAdditionalPresets = $this->configurationContentDimensionPresetSource->getAllowedDimensionPresetsAccordingToPreselection('country', [$pinnedDimensionName => $allowedPresetIdentifier]); foreach ($allowedAdditionalPresets as $allowedAdditionalDimensionName => $allowedAdditionalPreset) { $acceptableCombination[$allowedAdditionalDimensionName] = $allowedAdditionalPreset['presets'][$allowedAdditionalPreset['defaultPreset']]['values']; } $nodeInDimensions = $this->getNodeInDimensions($acceptableCombination, []); if ($nodeInDimensions !== null) { return $nodeInDimensions; } } return null; }