2008-04-08 08:17:58 +02:00
|
|
|
<?php
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @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 {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
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();
|
|
|
|
|
|
|
|
$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->assertArrayHasKey('ClassC', $classes);
|
|
|
|
$this->assertEquals('ParentClassC', $classes['ClassC']['extends']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassD', $classes);
|
|
|
|
$this->assertEquals('ParentClassD', $classes['ClassD']['extends']);
|
|
|
|
$this->assertContains('InterfaceA', $classes['ClassD']['interfaces']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassE', $classes);
|
|
|
|
$this->assertEquals('ParentClassE', $classes['ClassE']['extends']);
|
|
|
|
$this->assertContains('InterfaceA', $classes['ClassE']['interfaces']);
|
|
|
|
$this->assertContains('InterfaceB', $classes['ClassE']['interfaces']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('ClassF', $classes);
|
|
|
|
$this->assertEquals('ParentClassF', $classes['ClassF']['extends']);
|
|
|
|
$this->assertContains('InterfaceA', $classes['ClassF']['interfaces']);
|
|
|
|
$this->assertContains('InterfaceB', $classes['ClassF']['interfaces']);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
$matches = $parser->findAll($tokens);
|
|
|
|
$interfaces = array();
|
|
|
|
if($matches) foreach($matches as $match) $interfaces[$match['interfaceName']] = $match;
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('InterfaceA', $interfaces);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('InterfaceB', $interfaces);
|
|
|
|
$this->assertEquals('Something', $interfaces['InterfaceB']['extends']);
|
|
|
|
}
|
|
|
|
}
|