Exemplo n.º 1
0
 /**
  * @test
  */
 public function filterByPrefixWork()
 {
     $index1 = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $index1->setClassNames(array('\\Foo\\Bar', '\\Foo\\Baz', '\\Bar\\Baz', '\\Foo\\Blubb'));
     // We need to call sort manually!
     $index1->sort();
     $filteredIndex = $index1->filterByPrefix('\\Foo');
     $this->assertEquals(array('\\Foo\\Bar', '\\Foo\\Baz', '\\Foo\\Blubb'), $filteredIndex->getClassNames());
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotMatchedByAClassNameFilterWithRegularExpressions()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $classNameFilter = new \TYPO3\FLOW3\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\.*');
     $result = $classNameFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotBeeingConfiguredAsScopeSession()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockCompileTimeObjectManager = $this->getMock('TYPO3\\FLOW3\\Object\\CompileTimeObjectManager', array(), array(), '', FALSE);
     $mockCompileTimeObjectManager->expects($this->any())->method('getClassNamesByScope')->with(\TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_SESSION)->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $sessionObjectMethodsPointcutFilter = new \TYPO3\FLOW3\Session\Aspect\SessionObjectMethodsPointcutFilter();
     $sessionObjectMethodsPointcutFilter->injectObjectManager($mockCompileTimeObjectManager);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $sessionObjectMethodsPointcutFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotHavingTheGivenAnnotation()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockReflectionService = $this->getMock('TYPO3\\FLOW3\\Reflection\\ReflectionService', array(), array(), '', FALSE);
     $mockReflectionService->expects($this->any())->method('getClassNamesByAnnotation')->with('SomeAnnotationClass')->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $classAnnotatedWithFilter = new \TYPO3\FLOW3\Aop\Pointcut\PointcutClassAnnotatedWithFilter('SomeAnnotationClass');
     $classAnnotatedWithFilter->injectReflectionService($mockReflectionService);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $classAnnotatedWithFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
Exemplo n.º 5
0
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesExceptTheClassItselfAndAllItsSubclasses()
 {
     $testClassName = uniqid('someTestInterface');
     eval('class ' . $testClassName . ' {}');
     $availableClassNames = array($testClassName, 'TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockReflectionService = $this->getMock('TYPO3\\FLOW3\\Reflection\\ReflectionService', array(), array(), '', FALSE);
     $mockReflectionService->expects($this->any())->method('getAllSubClassNamesForClass')->with($testClassName)->will($this->returnValue(array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass')));
     $classTypeFilter = new \TYPO3\FLOW3\Aop\Pointcut\PointcutClassTypeFilter($testClassName);
     $classTypeFilter->injectReflectionService($mockReflectionService);
     $expectedClassNames = array($testClassName, 'TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $classTypeFilter->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
Exemplo n.º 6
0
 /**
  * @test
  */
 public function reduceTargetClassNamesFiltersAllClassesNotMatchedAByClassNameFilter()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $classNameFilter1 = new \TYPO3\FLOW3\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\SubSubPackage\\Class3');
     $classNameFilter2 = new \TYPO3\FLOW3\Aop\Pointcut\PointcutClassNameFilter('TestPackage\\Subpackage\\Class1');
     $methodNameFilter1 = new \TYPO3\FLOW3\Aop\Pointcut\PointcutMethodNameFilter('method2');
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $pointcutFilterComposite = new \TYPO3\FLOW3\Aop\Pointcut\PointcutFilterComposite();
     $pointcutFilterComposite->addFilter('&&', $classNameFilter1);
     $pointcutFilterComposite->addFilter('||', $classNameFilter2);
     $pointcutFilterComposite->addFilter('&&', $methodNameFilter1);
     $result = $pointcutFilterComposite->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\FLOW3\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     $classNames = $this->reflectionService->getClassesContainingMethodsAnnotatedWith($this->annotation);
     $annotatedIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $annotatedIndex->setClassNames($classNames);
     return $classNameIndex->intersect($annotatedIndex);
 }
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\FLOW3\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     $sessionClasses = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $sessionClasses->setClassNames($this->objectManager->getClassNamesByScope(ObjectConfiguration::SCOPE_SESSION));
     return $classNameIndex->intersect($sessionClasses);
 }
Exemplo n.º 9
0
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\FLOW3\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     if ($this->filters === array()) {
         $this->buildPointcutFilters();
     }
     $result = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     foreach ($this->filters as $resources) {
         foreach ($resources as $filterForResource) {
             $result->applyUnion($filterForResource->reduceTargetClassNames($classNameIndex));
         }
     }
     return $result;
 }
Exemplo n.º 10
0
 /**
  * @test
  */
 public function reduceTargetClassNamesPassesTheGivenClassNameIndexToAllResourceFiltersAndReturnsTheUnionOfTheirResults()
 {
     $availableClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4');
     sort($availableClassNames);
     $availableClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $availableClassNamesIndex->setClassNames($availableClassNames);
     $mockPointcutFilter1 = $this->getMock('\\TYPO3\\FLOW3\\Aop\\Pointcut\\PointcutFilterInterface', array(), array(), '', FALSE);
     $mockPointcutFilter1->expects($this->once())->method('reduceTargetClassNames')->with($availableClassNamesIndex)->will($this->returnValue(new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex(array('TestPackage\\Subpackage\\Class1' => TRUE))));
     $mockPointcutFilter2 = $this->getMock('\\TYPO3\\FLOW3\\Aop\\Pointcut\\PointcutFilterInterface', array(), array(), '', FALSE);
     $mockPointcutFilter2->expects($this->once())->method('reduceTargetClassNames')->with($availableClassNamesIndex)->will($this->returnValue(new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex(array('TestPackage\\Subpackage\\SubSubPackage\\Class3' => TRUE))));
     $policyFilterArray = array('role' => array('resource1' => $mockPointcutFilter1, 'resource2' => $mockPointcutFilter2));
     $policyService = $this->getAccessibleMock('TYPO3\\FLOW3\\Security\\Policy\\PolicyService', array('dummy'), array(), '', FALSE);
     $policyService->_set('filters', $policyFilterArray);
     $expectedClassNames = array('TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3');
     sort($expectedClassNames);
     $expectedClassNamesIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $expectedClassNamesIndex->setClassNames($expectedClassNames);
     $result = $policyService->reduceTargetClassNames($availableClassNamesIndex);
     $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered');
 }
Exemplo n.º 11
0
 /**
  * This method is used to optimize the matching process.
  *
  * @param \TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex
  * @return \TYPO3\FLOW3\Aop\Builder\ClassNameIndex
  */
 public function reduceTargetClassNames(\TYPO3\FLOW3\Aop\Builder\ClassNameIndex $classNameIndex)
 {
     if (interface_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllImplementationClassNamesForInterface($this->interfaceOrClassName);
     } elseif (class_exists($this->interfaceOrClassName)) {
         $classNames = $this->reflectionService->getAllSubClassNamesForClass($this->interfaceOrClassName);
         $classNames[] = $this->interfaceOrClassName;
     } else {
         $classNames = array();
     }
     $filteredIndex = new \TYPO3\FLOW3\Aop\Builder\ClassNameIndex();
     $filteredIndex->setClassNames($classNames);
     return $classNameIndex->intersect($filteredIndex);
 }