2008-04-08 08:17:58 +02:00
|
|
|
<?php
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2008-04-08 08:17:58 +02:00
|
|
|
class TokenisedRegularExpressionTest extends SapphireTest {
|
|
|
|
function getTokens() {
|
|
|
|
return token_get_all(<<<PHP
|
|
|
|
<?php
|
|
|
|
|
|
|
|
class ClassA {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassB{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassC extends ParentClassC {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassD extends ParentClassD
|
|
|
|
implements InterfaceA {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InterfaceA {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InterfaceB extends Something{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassE extends ParentClassE
|
|
|
|
implements InterfaceA,InterfaceB {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassF extends ParentClassF
|
|
|
|
implements InterfaceA, InterfaceB {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-19 05:52:20 +02:00
|
|
|
interface InterfaceC extends InterfaceA, InterfaceB {
|
|
|
|
}
|
|
|
|
interface InterfaceD extends InterfaceA, InterfaceB, InterfaceC {
|
|
|
|
}
|
2012-02-12 21:22:11 +01:00
|
|
|
|
2011-12-17 02:03:53 +01:00
|
|
|
PHP
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNamespaceTokens() {
|
|
|
|
return token_get_all(<<<PHP
|
|
|
|
<?php
|
|
|
|
|
2012-03-24 04:38:57 +01:00
|
|
|
namespace silverstripe\\test;
|
2011-12-17 02:03:53 +01:00
|
|
|
|
|
|
|
class ClassA {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassB extends ParentClassB {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassC extends \\ParentClassC {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassD extends subtest\\ParentClassD {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassE implements InterfaceE {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassF implements \\InterfaceF {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class ClassG implements subtest\\InterfaceG {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-12 21:22:11 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
PHP
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testClassDefParser() {
|
2011-03-22 10:47:55 +01:00
|
|
|
$parser = SS_ClassManifest::get_class_parser();
|
2008-04-08 08:17:58 +02:00
|
|
|
|
|
|
|
$tokens = $this->getTokens();
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$matches = $parser->findAll($tokens);
|
|
|
|
$classes = array();
|
|
|
|
if($matches) foreach($matches as $match) $classes[$match['className']] = $match;
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('ClassA', $classes);
|
|
|
|
$this->assertArrayHasKey('ClassB', $classes);
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('ClassC', $classes);
|
2011-12-17 02:03:53 +01:00
|
|
|
$this->assertEquals(array('ParentClassC'), $classes['ClassC']['extends']);
|
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('ClassD', $classes);
|
2011-12-17 02:03:53 +01:00
|
|
|
$this->assertEquals(array('ParentClassD'), $classes['ClassD']['extends']);
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertContains('InterfaceA', $classes['ClassD']['interfaces']);
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('ClassE', $classes);
|
2011-12-17 02:03:53 +01:00
|
|
|
$this->assertEquals(array('ParentClassE'), $classes['ClassE']['extends']);
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertContains('InterfaceA', $classes['ClassE']['interfaces']);
|
|
|
|
$this->assertContains('InterfaceB', $classes['ClassE']['interfaces']);
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('ClassF', $classes);
|
2011-12-17 02:03:53 +01:00
|
|
|
$this->assertEquals(array('ParentClassF'), $classes['ClassF']['extends']);
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertContains('InterfaceA', $classes['ClassF']['interfaces']);
|
|
|
|
$this->assertContains('InterfaceB', $classes['ClassF']['interfaces']);
|
|
|
|
}
|
2011-12-17 02:03:53 +01:00
|
|
|
|
|
|
|
function testNamesapcedClassDefParser() {
|
|
|
|
$parser = SS_ClassManifest::get_namespaced_class_parser();
|
|
|
|
|
|
|
|
$tokens = $this->getNamespaceTokens();
|
|
|
|
|
|
|
|
$matches = $parser->findAll($tokens);
|
|
|
|
|
|
|
|
$classes = array();
|
|
|
|
if($matches) foreach($matches as $match) $classes[$match['className']] = $match;
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassA', $classes);
|
|
|
|
$this->assertArrayHasKey('ClassB', $classes);
|
|
|
|
$this->assertEquals(array('ParentClassB'), $classes['ClassB']['extends']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassC', $classes);
|
|
|
|
$this->assertEquals(array('\\', 'ParentClassC'), $classes['ClassC']['extends']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassD', $classes);
|
|
|
|
$this->assertEquals(array('subtest', '\\', 'ParentClassD'), $classes['ClassD']['extends']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassE', $classes);
|
|
|
|
$this->assertContains('InterfaceE', $classes['ClassE']['interfaces']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassF', $classes);
|
|
|
|
$this->assertEquals(array('\\', 'InterfaceF'), $classes['ClassF']['interfaces']);
|
|
|
|
}
|
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
function testInterfaceDefParser() {
|
2011-03-22 10:47:55 +01:00
|
|
|
$parser = SS_ClassManifest::get_interface_parser();
|
2008-04-08 08:17:58 +02:00
|
|
|
|
|
|
|
$tokens = $this->getTokens();
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$matches = $parser->findAll($tokens);
|
|
|
|
$interfaces = array();
|
|
|
|
if($matches) foreach($matches as $match) $interfaces[$match['interfaceName']] = $match;
|
2011-12-17 02:03:53 +01:00
|
|
|
|
2008-04-08 08:17:58 +02:00
|
|
|
$this->assertArrayHasKey('InterfaceA', $interfaces);
|
|
|
|
$this->assertArrayHasKey('InterfaceB', $interfaces);
|
2011-04-19 05:52:20 +02:00
|
|
|
$this->assertArrayHasKey('InterfaceC', $interfaces);
|
|
|
|
$this->assertArrayHasKey('InterfaceD', $interfaces);
|
2008-04-08 08:17:58 +02:00
|
|
|
}
|
2011-12-17 02:03:53 +01:00
|
|
|
|
|
|
|
function testNamespaceDefParser() {
|
|
|
|
$parser = SS_ClassManifest::get_namespace_parser();
|
|
|
|
|
|
|
|
$namespacedTokens = $this->getNamespaceTokens();
|
|
|
|
$tokens = $this->getTokens();
|
|
|
|
|
|
|
|
$namespacedMatches = $parser->findAll($namespacedTokens);
|
|
|
|
$matches = $parser->findAll($tokens);
|
|
|
|
|
|
|
|
$this->assertEquals(array(), $matches);
|
2012-03-24 04:38:57 +01:00
|
|
|
$this->assertEquals(array('silverstripe', '\\', 'test'), $namespacedMatches[0]['namespaceName']);
|
2011-12-17 02:03:53 +01:00
|
|
|
}
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|