本文整理汇总了PHP中SiteTree::hasMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::hasMethod方法的具体用法?PHP SiteTree::hasMethod怎么用?PHP SiteTree::hasMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::hasMethod方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHasmethodBehaviour
function testHasmethodBehaviour() {
/* SiteTree should have all of the methods that Versioned has, because Versioned is listed in SiteTree's
* extensions */
$st = new SiteTree();
$cc = new ContentController($st);
$this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish");
$this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion");
/* This relationship should be case-insensitive, too */
$this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh");
$this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn");
/* In a similar manner, all of SiteTree's methods should be available on ContentController, because $failover is set */
$this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView");
$this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent");
/* This 'method copying' is transitive, so all of Versioned's methods should be available on ContentControler.
* Once again, this is case-insensitive */
$this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn");
/* The above examples make use of SiteTree, Versioned and ContentController. Let's test defineMethods() more
* directly, with some sample objects */
$objs = array();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
// All these methods should exist and return true
$trueMethods = array('testMethod','otherMethod','someMethod','t1cMethod','normalMethod');
foreach($objs as $i => $obj) {
foreach($trueMethods as $method) {
$methodU = strtoupper($method);
$methodL = strtoupper($method);
$this->assertTrue($obj->hasMethod($method), "Test that obj#$i has method $method");
$this->assertTrue($obj->hasMethod($methodU), "Test that obj#$i has method $methodU");
$this->assertTrue($obj->hasMethod($methodL), "Test that obj#$i has method $methodL");
$this->assertTrue($obj->$method(), "Test that obj#$i can call method $method");
$this->assertTrue($obj->$methodU(), "Test that obj#$i can call method $methodU");
$this->assertTrue($obj->$methodL(), "Test that obj#$i can call method $methodL");
}
$this->assertTrue($obj->hasMethod('Wrapping'), "Test that obj#$i has method Wrapping");
$this->assertTrue($obj->hasMethod('WRAPPING'), "Test that obj#$i has method WRAPPING");
$this->assertTrue($obj->hasMethod('wrapping'), "Test that obj#$i has method wrapping");
$this->assertEquals("Wrapping", $obj->Wrapping(), "Test that obj#$i can call method Wrapping");
$this->assertEquals("Wrapping", $obj->WRAPPING(), "Test that obj#$i can call method WRAPPIGN");
$this->assertEquals("Wrapping", $obj->wrapping(), "Test that obj#$i can call method wrapping");
}
}
示例2: testHasMethod
function testHasMethod()
{
$st = new SiteTree();
$cc = new ContentController($st);
// Check that Versiond methods exist on SiteTree
$this->assertTrue($st->hasMethod('publish'), "Test SiteTree has publish");
$this->assertTrue($st->hasMethod('migrateVersion'), "Test SiteTree has migrateVersion");
// Check for different casing
$this->assertTrue($st->hasMethod('PuBliSh'), "Test SiteTree has PuBliSh");
$this->assertTrue($st->hasMethod('MiGratEVersIOn'), "Test SiteTree has MiGratEVersIOn");
// Check that SiteTree methods exist on ContentController (test failover)
$this->assertTrue($cc->hasMethod('canView'), "Test ContentController has canView");
$this->assertTrue($cc->hasMethod('linkorcurrent'), "Test ContentController has linkorcurrent");
$this->assertTrue($cc->hasMethod('MiGratEVersIOn'), "Test ContentController has MiGratEVersIOn");
// Make use of the test object below. 1st instantiation is different from subsequent, so create a few
$objs = array();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
$objs[] = new ObjectTest_T2();
// All these methods should exist and return true
$trueMethods = array('testMethod', 'otherMethod', 'someMethod', 't1cMethod', 'normalMethod');
foreach ($objs as $i => $obj) {
foreach ($trueMethods as $method) {
$methodU = strtoupper($method);
$methodL = strtoupper($method);
$this->assertTrue($obj->hasMethod($method), "Test that obj#{$i} has method {$method}");
$this->assertTrue($obj->hasMethod($methodU), "Test that obj#{$i} has method {$methodU}");
$this->assertTrue($obj->hasMethod($methodL), "Test that obj#{$i} has method {$methodL}");
$this->assertTrue($obj->{$method}(), "Test that obj#{$i} can call method {$method}");
$this->assertTrue($obj->{$methodU}(), "Test that obj#{$i} can call method {$methodU}");
$this->assertTrue($obj->{$methodL}(), "Test that obj#{$i} can call method {$methodL}");
}
$this->assertTrue($obj->hasMethod('Wrapping'), "Test that obj#{$i} has method Wrapping");
$this->assertTrue($obj->hasMethod('WRAPPING'), "Test that obj#{$i} has method WRAPPING");
$this->assertTrue($obj->hasMethod('wrapping'), "Test that obj#{$i} has method wrapping");
$this->assertEquals("Wrapping", $obj->Wrapping(), "Test that obj#{$i} can call method Wrapping");
$this->assertEquals("Wrapping", $obj->WRAPPING(), "Test that obj#{$i} can call method WRAPPIGN");
$this->assertEquals("Wrapping", $obj->wrapping(), "Test that obj#{$i} can call method wrapping");
}
}
示例3: getPageHierarchy
/**
* Builds a hierarchy from the current page to the top product group page
* or holder.
*
* @param SiteTree $currPage The page to start from
*
* @return array
*
* @author Sascha Koehler <skoehler@pixeltricks.de>
* @since 18.10.2012
*/
public static function getPageHierarchy($currPage)
{
if (!array_key_exists('SiteTree_' . $currPage->ID, self::$pageHierarchy)) {
$level = 0;
$hierarchy = array('SiteTree_' . $currPage->ID => array('Page' => $currPage, 'Level' => $level));
while ($currPage->hasMethod('getParent') && $currPage->getParent()) {
$parent = $currPage->getParent();
if ($parent) {
$level++;
$hierarchy['SiteTree_' . $parent->ID] = array('Page' => $parent, 'Level' => $level);
$currPage = $parent;
} else {
break;
}
}
self::$pageHierarchy['SiteTree_' . $currPage->ID] = array();
foreach ($hierarchy as $pageID => $pageInfo) {
self::$pageHierarchy['SiteTree_' . $currPage->ID][$pageID] = array('Page' => $pageInfo['Page'], 'Level' => ($pageInfo['Level'] - $level) * -1);
}
}
return self::$pageHierarchy['SiteTree_' . $currPage->ID];
}