本文整理汇总了PHP中CSSContentParser::getByXpath方法的典型用法代码示例。如果您正苦于以下问题:PHP CSSContentParser::getByXpath方法的具体用法?PHP CSSContentParser::getByXpath怎么用?PHP CSSContentParser::getByXpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSSContentParser
的用法示例。
在下文中一共展示了CSSContentParser::getByXpath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNestedEditForm
function testNestedEditForm()
{
$this->logInWithPermission('ADMIN');
$group = $this->objFromFixture('GridFieldDetailFormTest_PeopleGroup', 'group');
$person = $group->People()->First();
$category = $person->Categories()->First();
// Get first form (GridField managing PeopleGroup)
$response = $this->get('GridFieldDetailFormTest_GroupController');
$this->assertFalse($response->isError());
$parser = new CSSContentParser($response->getBody());
$groupEditLink = $parser->getByXpath('//tr[contains(@class, "ss-gridfield-item") and contains(@data-id, "' . $group->ID . '")]//a');
$this->assertEquals('GridFieldDetailFormTest_GroupController/Form/field/testfield/item/' . $group->ID . '/edit', (string) $groupEditLink[0]['href']);
// Get second level form (GridField managing Person)
$response = $this->get((string) $groupEditLink[0]['href']);
$this->assertFalse($response->isError());
$parser = new CSSContentParser($response->getBody());
$personEditLink = $parser->getByXpath('//fieldset[@id="Form_ItemEditForm_People"]//tr[contains(@class, "ss-gridfield-item") and contains(@data-id, "' . $person->ID . '")]//a');
$this->assertEquals(sprintf('GridFieldDetailFormTest_GroupController/Form/field/testfield/item/%d/ItemEditForm/field/People/item/%d/edit', $group->ID, $person->ID), (string) $personEditLink[0]['href']);
// Get third level form (GridField managing Category)
$response = $this->get((string) $personEditLink[0]['href']);
$this->assertFalse($response->isError());
$parser = new CSSContentParser($response->getBody());
$categoryEditLink = $parser->getByXpath('//fieldset[@id="Form_ItemEditForm_Categories"]//tr[contains(@class, "ss-gridfield-item") and contains(@data-id, "' . $category->ID . '")]//a');
$this->assertEquals(sprintf('GridFieldDetailFormTest_GroupController/Form/field/testfield/item/%d/ItemEditForm/field/People/item/%d/ItemEditForm/field/Categories/item/%d/edit', $group->ID, $person->ID, $category->ID), (string) $categoryEditLink[0]['href']);
// Fourth level form would be a Category detail view
}
示例2: testResizedImageInsertion
public function testResizedImageInsertion()
{
$obj = new HtmlEditorFieldTest_Object();
$editor = new HtmlEditorField('Content');
/*
* Following stuff is neccessary to
* a) use the proper filename for the image we are referencing
* b) not confuse the "existing" filesystem by our test
*/
$imageFile = $this->objFromFixture('Image', 'example_image');
$imageFile->Filename = FRAMEWORK_DIR . '/' . $imageFile->Filename;
$origUpdateFilesystem = Config::inst()->get('File', 'update_filesystem');
Config::inst()->update('File', 'update_filesystem', false);
$imageFile->write();
Config::inst()->update('File', 'update_filesystem', $origUpdateFilesystem);
/*
* End of test bet setting
*/
$editor->setValue('<img src="assets/HTMLEditorFieldTest_example.jpg" width="10" height="20" />');
$editor->saveInto($obj);
$parser = new CSSContentParser($obj->Content);
$xml = $parser->getByXpath('//img');
$this->assertEquals('', (string) $xml[0]['alt'], 'Alt tags are added by default.');
$this->assertEquals('', (string) $xml[0]['title'], 'Title tags are added by default.');
$this->assertEquals(10, (int) $xml[0]['width'], 'Width tag of resized image is set.');
$this->assertEquals(20, (int) $xml[0]['height'], 'Height tag of resized image is set.');
$neededFilename = 'assets/_resampled/ResizedImage' . Convert::base64url_encode(array(10, 20)) . '/HTMLEditorFieldTest_example.jpg';
$this->assertEquals($neededFilename, (string) $xml[0]['src'], 'Correct URL of resized image is set.');
$this->assertTrue(file_exists(BASE_PATH . DIRECTORY_SEPARATOR . $neededFilename), 'File for resized image exists');
$this->assertEquals(false, $obj->HasBrokenFile, 'Referenced image file exists.');
}
示例3: testFieldWithDisabledItems
public function testFieldWithDisabledItems()
{
$articleWithTags = $this->objFromFixture('ListboxFieldTest_Article', 'articlewithtags');
$tag1 = $this->objFromFixture('ListboxFieldTest_Tag', 'tag1');
$tag2 = $this->objFromFixture('ListboxFieldTest_Tag', 'tag2');
$tag3 = $this->objFromFixture('ListboxFieldTest_Tag', 'tag3');
$field = new ListboxField("Tags", "Test field", DataObject::get("ListboxFieldTest_Tag")->map()->toArray());
$field->setValue(null, $articleWithTags);
$field->setDisabledItems(array($tag1->ID, $tag3->ID));
$p = new CSSContentParser($field->Field());
$tag1xml = $p->getByXpath('//option[@value=' . $tag1->ID . ']');
$tag2xml = $p->getByXpath('//option[@value=' . $tag2->ID . ']');
$tag3xml = $p->getByXpath('//option[@value=' . $tag3->ID . ']');
$this->assertEquals('selected', (string) $tag1xml[0]['selected']);
$this->assertEquals('disabled', (string) $tag1xml[0]['disabled']);
$this->assertEquals('selected', (string) $tag2xml[0]['selected']);
$this->assertNull($tag2xml[0]['disabled']);
$this->assertNull($tag3xml[0]['selected']);
$this->assertEquals('disabled', (string) $tag3xml[0]['disabled']);
}
示例4: testImageInsertion
public function testImageInsertion()
{
$obj = new HtmlEditorFieldTest_Object();
$editor = new HtmlEditorField('Content');
$editor->setValue('<img src="assets/example.jpg" />');
$editor->saveInto($obj);
$parser = new CSSContentParser($obj->Content);
$xml = $parser->getByXpath('//img');
$this->assertEquals('', $xml[0]['alt'], 'Alt tags are added by default.');
$this->assertEquals('', $xml[0]['title'], 'Title tags are added by default.');
$editor->setValue('<img src="assets/example.jpg" alt="foo" title="bar" />');
$editor->saveInto($obj);
$parser = new CSSContentParser($obj->Content);
$xml = $parser->getByXpath('//img');
$this->assertEquals('foo', $xml[0]['alt'], 'Alt tags are preserved.');
$this->assertEquals('bar', $xml[0]['title'], 'Title tags are preserved.');
}
示例5: testResizedImageInsertion
public function testResizedImageInsertion()
{
$obj = new HtmlEditorFieldTest_Object();
$editor = new HtmlEditorField('Content');
$fileID = $this->idFromFixture('Image', 'example_image');
$editor->setValue(sprintf('<img src="assets/HTMLEditorFieldTest_example.jpg" width="10" height="20" data-fileid="%d" />', $fileID));
$editor->saveInto($obj);
$parser = new CSSContentParser($obj->Content);
$xml = $parser->getByXpath('//img');
$this->assertEquals('', (string) $xml[0]['alt'], 'Alt tags are added by default.');
$this->assertEquals('', (string) $xml[0]['title'], 'Title tags are added by default.');
$this->assertEquals(10, (int) $xml[0]['width'], 'Width tag of resized image is set.');
$this->assertEquals(20, (int) $xml[0]['height'], 'Height tag of resized image is set.');
$neededFilename = '/assets/HtmlEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example__ResizedImageWzEwLDIwXQ.jpg';
$this->assertEquals($neededFilename, (string) $xml[0]['src'], 'Correct URL of resized image is set.');
$this->assertTrue(file_exists(BASE_PATH . DIRECTORY_SEPARATOR . $neededFilename), 'File for resized image exists');
$this->assertEquals(false, $obj->HasBrokenFile, 'Referenced image file exists.');
}
示例6: getNodeClassFromTree
/**
* Get the HTML class attribute from a node in the sitetree
*
* @param $html
* @param $node
* @return string
*/
protected function getNodeClassFromTree($html, $node)
{
$parser = new CSSContentParser($html);
$xpath = '//ul/li[@id="' . $node->ID . '"]';
$object = $parser->getByXpath($xpath);
foreach ($object[0]->attributes() as $key => $attr) {
if ($key == 'class') {
return (string) $attr;
}
}
return '';
}
示例7: testEmailException
public function testEmailException()
{
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
SS_Log::add_writer($testEmailWriter, SS_Log::ERR);
// Trigger exception handling mechanism
try {
$this->exceptionGenerator();
} catch (Exception $exception) {
// Mimics exceptionHandler, but without the exit(1)
SS_Log::log(array('errno' => E_USER_ERROR, 'errstr' => "Uncaught " . get_class($exception) . ": " . $exception->getMessage(), 'errfile' => $exception->getFile(), 'errline' => $exception->getLine(), 'errcontext' => $exception->getTrace()), SS_Log::ERR);
}
// Ensure email is sent
$this->assertEmailSent('test@test.com');
// Begin parsing of email body
$email = $this->findEmail('test@test.com');
$parser = new CSSContentParser($email['htmlContent']);
// Check that the first three lines of the stacktrace are correct
$stacktrace = $parser->getByXpath('//body/div[1]/ul[1]');
$this->assertContains('<b>SS_LogTest->exceptionGeneratorThrower()</b>', $stacktrace[0]->li[0]->asXML());
$this->assertContains('<b>SS_LogTest->exceptionGenerator()</b>', $stacktrace[0]->li[1]->asXML());
$this->assertContains('<b>SS_LogTest->testEmailException()</b>', $stacktrace[0]->li[2]->asXML());
}
示例8: testSelectOptionsRendering
function testSelectOptionsRendering()
{
$obj1 = $this->objFromFixture('TableListFieldTest_Obj', 'one');
$obj2 = $this->objFromFixture('TableListFieldTest_Obj', 'two');
$obj3 = $this->objFromFixture('TableListFieldTest_Obj', 'three');
$table = new TableListField("Tester", "TableListFieldTest_Obj", array("A" => "Col A"));
$table->Markable = true;
$table->addSelectOptions(array("F" => "FieldF"));
$tableHTML = $table->FieldHolder();
$p = new CSSContentParser($tableHTML);
$this->assertContains('rel="F"', $tableHTML);
$tbody = $p->getByXpath('//tbody');
$this->assertContains('markingcheckbox F', (string) $tbody[0]->tr[0]->td[0]['class']);
$this->assertContains('markingcheckbox', (string) $tbody[0]->tr[1]->td[0]['class']);
$this->assertContains('markingcheckbox F', (string) $tbody[0]->tr[2]->td[0]['class']);
}