-
-
Save jpingo/9da209ded0918c2e704b to your computer and use it in GitHub Desktop.
Public API Relation List Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @group SeleneseTest | |
* @group eZPublishAPITest | |
* @group eZPublishRealtionsListTest | |
* @group AutomatedSeleneseTest | |
* @group FailingTest | |
* @group NotComplete | |
* This test is not fully completed due to issue EZP-20489 | |
* | |
* | |
* @author João Pingo <joao.pingo@ez.no> | |
* @see {@link https://github.com/ezsystems/ezp-next/blob/master/eZ/Publish/API/Repository/Tests/FieldType/RelationListIntegrationTest.php} | |
*/ | |
class eZPublishAPIRelationsList extends eZPublishAPITest | |
{ | |
protected function testChangesAnyData() | |
{ | |
return true; | |
} | |
// tc-1240: Create an "Object Relations" class using public API | |
function testTC1240CreateAnObjectRelationsListClass() | |
{ | |
$this->runTestStages(); | |
} | |
// tc-1240: Part1 - (Public API) create "News" folder | |
function _testTC1240CreateAnObjectRelationsListClass__stage1() | |
{ | |
//Create News folder | |
$folder = $this->api->newContent( 'folder' ); | |
$folder->setField( 'name', 'News' ); | |
$this->api->saveContent( $folder ); | |
} | |
// tc-1240: Part2 (Public API) - Create a "Object Relations" class using eZ Publish API calls | |
function _testTC1240CreateAnObjectRelationsListClass__stage2() | |
{ | |
$class = $this->api->newContentType( 'a_relations_class', 'A Relations Class' ); | |
$relAttr = $this->api->newFieldDefinition( 'obj_rels', 'Object Relations', 'ezobjectrelationlist' ); | |
$location = $this->api->getContentInfoByPath( '/News' ); | |
$relAttr->isRequired = true; | |
$relAttr->isSearchable = false; | |
$relAttr->fieldGroup = 'meta'; | |
$relAttr->position = 2; | |
/* Verify that exception is throw if non existing node is chosen for defautlt location step 2 tc-1240 | |
* $relAttr->fieldSettings = array( | |
* 'selectionMethod' => 1, | |
* 'selectionDefaultLocation' => 999 | |
); | |
* Check issue EZP-20489 | |
*/ | |
$relAttr->fieldSettings = array( | |
'selectionMethod' => 1, | |
'selectionDefaultLocation' => $location->mainLocationId, | |
); | |
$class->addFieldDefinition( $relAttr ); | |
$this->api->saveContentType( $class ); | |
} | |
// tc-1241:Update an "Object Relations" class using public API | |
function testTC1241UpdateAnObjectRelationsListClass() | |
{ | |
$this->runTestStages(); | |
} | |
// tc-1241: Part1 - (Public API) create an article within "News" folder and a "Object Relations" class using selenium | |
function _testTC1241UpdateAnObjectRelationsListClass__stage1() | |
{ | |
// Create Folder | |
$folder = $this->api->newContent( 'folder' ); | |
$folder->setField( 'name', 'News' ); | |
$this->api->saveContent( $folder ); | |
// Create Article | |
$location = $this->api->getLocationByPath( '/News' ); | |
$article = $this->api->newContent( 'article' ); | |
$article->setField( 'title', 'Article 1' ); | |
$article->setField( 'intro', '<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">Sum of Article 1</paragraph></section>'); | |
$this->api->saveContent( $article, $location); | |
//Create Class | |
$this->_testTC1240CreateAnObjectRelationsListClass__stage2(); | |
//Update and add new attribute to class | |
$classUpdate = $this->api->getContentTypeToUpdate( 'a_relations_class' ); | |
$newAttr = $this->api->newFieldDefinition( 'obj_rels_2', 'Object Relations 2', 'ezobjectrelationlist' ); | |
$newAttr->fieldSettings = array( | |
'selectionMethod' => 0, | |
'selectionDefaultLocation' => '', | |
'selectionContentTypes' => array( 'folder' ), | |
); | |
$newAttr->isRequired = true; | |
$newAttr->isSearchable = false; | |
$newAttr->position = 3; | |
$classUpdate->addField( $newAttr ); | |
$this->api->saveContentTypeUpdate( $classUpdate ); | |
} | |
// tc-1241_ Part2 - (Public API) - Update the created class using API calls | |
function _testTC1241UpdateAnObjectRelationsListClass__stage2() | |
{ | |
// Update Attribute #2 | |
$classUpdate = $this->api->getContentTypeToUpdate( 'a_relations_class' ); | |
$fieldUpdate = $classUpdate->getFieldDefinitionToUpdate( 'obj_rels' ); | |
// Set the updated properties: | |
$fieldUpdate->names = array( $this->api->lang => 'This is a Object Relations test updated'); | |
$fieldUpdate->identifier = 'obj_rels_updated'; | |
$fieldUpdate->fieldGroup = ''; | |
$fieldUpdate->fieldSettings = array( | |
'selectionMethod' => 0, | |
'selectionDefaultLocation' => '', | |
'selectionContentTypes' => array( 'folder', 'article' ), | |
); | |
$classUpdate->saveFieldDefinitionUpdate( $fieldUpdate ); | |
//Remove attribute #3 | |
$classUpdate->removeField( 'obj_rels_2' ); | |
$this->api->saveContentTypeUpdate( $classUpdate ); | |
} | |
//tc-1242 Delete an Object Relations Class using Public API | |
function testTC1242DeleteAnObjectRelationsListClass() | |
{ | |
$this->runTestStages(); | |
} | |
//tc-1242: Part1 - (Public API) create an "Object Relations" class using selenium | |
function _testTC1242DeleteAnObjectRelationsListClass__stage1() | |
{ | |
$this->_testTC1240CreateAnObjectRelationsListClass__stage1(); | |
$this->_testTC1240CreateAnObjectRelationsListClass__stage2(); | |
} | |
function _testTC1242DeleteAnObjectRelationsListClass__stage2() | |
{ | |
$this->api->deleteContentType('a_relations_class'); | |
} | |
//tc-1500: Create an "Object Relations" object using public API | |
function testTC1500CreateAnObjectRelationsListObject() | |
{ | |
$this->runTestStages(); | |
} | |
//tc-1500: Part1 Create Objects (Public API) | |
function _testTC1500CreateAnObjectRelationsListObject__stage1() | |
{ | |
//Create News folder | |
$folderNews = $this->api->newContent( 'folder' ); | |
$folderNews->setField( 'name', 'News' ); | |
$this->api->saveContent( $folderNews ); | |
//Create Conference folder | |
$folderConference = $this->api->newContent( 'folder' ); | |
$folderConference->setField( 'name', 'Conference'); | |
$this->api->saveContent($folderConference); | |
//Create Article 1 News | |
$locationNews = $this->api->getLocationByPath( '/News' ); | |
$articleNews = $this->api->newContent( 'article' ); | |
$articleNews->setField( 'title', 'Article 1 News' ); | |
$articleNews->setField( 'intro', '<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">Sum of Article 1 News</paragraph></section>'); | |
$this->api->saveContent( $articleNews, $locationNews ); | |
//Create Article 2 Conference | |
$locationConference = $this->api->getLocationByPath( '/Conference' ); | |
$articleConference = $this->api->newContent( 'article' ); | |
$articleConference->setField( 'title', 'Article 2 Conference' ); | |
$articleConference->setField( 'intro', '<?xml version="1.0" encoding="utf-8"?> | |
<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">Sum of Article 1 Conference</paragraph></section>'); | |
$this->api->saveContent( $articleConference, $locationConference ); | |
} | |
//tc-1500: Part2 Create Class (Public API) | |
function _testTC1500CreateAnObjectRelationsListObject__stage2() | |
{ | |
$this->_testTC1240CreateAnObjectRelationsListClass__stage2(); | |
} | |
//tc-1500: Part3 (Public API) Create an Object Relations Object | |
function _testTC1500CreateAnObjectRelationsListObject__stage3() | |
{ | |
$infoNewsId = $this->api->getContentInfoByPath('/News')->id; | |
$infoArticle1NewsId = $this->api->getContentInfoByPath( '/News/Article-1-News' )->id; | |
$infoConferenceId = $this->api->getContentInfoByPath( '/Conference' )->id; | |
$infoArticle2ConferenceId = $this->api->getContentInfoByPath( '/Conference/Article-2-Conference' )->id; | |
$locationArray = array( $infoNewsId, $infoArticle1NewsId, $infoConferenceId, $infoArticle2ConferenceId ); | |
$locationRoot = $this->api->getLocationByPath( '/' ); | |
$relationListObject = $this->api->newContent( 'a_relations_class' ); | |
$relationListObject->setField( 'name', 'Object Relations Object'); | |
// Verify that required if required empty | |
$relationListObject->setField( 'obj_rels', array() ); | |
try | |
{ | |
$this->api->saveContent($relationListObject, $locationRoot); | |
$this->assertTrue( false, 'Required field \'obj_rels\' value is empty' ); | |
} | |
catch ( eZ\Publish\Core\Base\Exceptions\ContentValidationException $e) | |
{ | |
$this->assertEquals( $e->getMessage(), 'Required field \'obj_rels\' value is empty', | |
'Message from exception was not as expected' ); | |
} | |
/* | |
* $relationListObject->setField( 'obj_rels', array( '999' ) ); | |
* Check issue EZP-20489 | |
*/ | |
$relationListObject->setField( 'obj_rels', $locationArray ); | |
$this->api->saveContent($relationListObject, $locationRoot); | |
} | |
// tc-1505:Update an "Object Relations" Object | |
function testTC1505UpdateAnObjectRelationsListObject() | |
{ | |
$this->runTestStages(); | |
} | |
//tc-1505: Part1 (Public API) Create Class and Object | |
function _testTC1505UpdateAnObjectRelationsListObject__stage1() | |
{ | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage1(); | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage2(); | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage3(); | |
} | |
//tc-1505: Part2 (Public API) Change Created Object | |
function _testTC1505UpdateAnObjectRelationsListObject__stage2() | |
{ | |
$infoNewsId = $this->api->getContentInfoByPath('/News')->id; | |
$infoArticle2ConferenceId = $this->api->getContentInfoByPath( '/Conference/Article-2-Conference' )->id; | |
$locationArray = array( $infoNewsId, $infoArticle2ConferenceId ); | |
$contentInfo = $this->api->getContentInfoByPath( '/Object-Relations-Object' ); | |
$contentUpdate = $this->api->getContentToUpdate( $contentInfo ); | |
$contentUpdate->setField( 'name', 'Object Relations Object Updated'); | |
$contentUpdate->setField( 'obj_rels', $locationArray ); | |
$this->api->saveContentUpdate( $contentUpdate ); | |
} | |
function testTC1506DeleteAnObjectRelationsListObject() | |
{ | |
$this->runTestStages(); | |
} | |
//tc-1505: Part1 (Public API) Create Class and Object | |
function _testTC1506DeleteAnObjectRelationsListObject__stage1() | |
{ | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage1(); | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage2(); | |
$this->_testTC1500CreateAnObjectRelationsListObject__stage3(); | |
} | |
//tc-1505: Part2 (Public API) Change Created Object | |
function _testTC1506DeleteAnObjectRelationsListObject__stage2() | |
{ | |
$contentInfo = $this->api->getContentInfoByPath( '/Object-Relations-Object' ); | |
$this->api->deleteContent( $contentInfo ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment