/**
     * Tests that the output process works with objects.
     *
     * There should be no crash from casting errors.
     * @group templateOperators
     * @group attributeOperator
     */
    public function testDisplayVariableWithObject()
    {
        $db = eZDB::instance();

        // STEP 1: Add test folder
        $folder = new ezpObject( "folder", 2 );
        $folder->name = __METHOD__;
        $folder->publish();

        $nodeId = $folder->mainNode->node_id;

        $node = eZContentObjectTreeNode::fetch( $nodeId );
        $attrOp = new eZTemplateAttributeOperator();
        $outputTxt = '';
        $formatterMock = $this->getMock( 'ezpAttributeOperatorFormatterInterface' );
        $formatterMock->expects( $this->any() )
                      ->method( 'line' )
                      ->will( $this->returnValue( __METHOD__ ) );

        try
        {
            $attrOp->displayVariable( $node, $formatterMock, true, 2, 0, $outputTxt );
        }
        catch ( PHPUnit_Framework_Error $e )
        {
            self::fail( "eZTemplateAttributeOperator raises an error when working with objects." );
        }

        self::assertNotNull( $outputTxt, "Output text is empty." );
        // this is an approxmiate test. The output shoudl contain the name of the object it has been generated correctly.
        self::assertContains( __METHOD__, $outputTxt, "There is something wrong with the output of the attribute operator. Object name not found." );
    }
    /**
     * Unit test for eZSubtreeNotificationRule::fetchUserList()
     */
    public function testFetchUserList()
    {
        // Add a notification rule for admin on root
        $adminUserID = eZUser::fetchByName( 'admin' )->attribute( 'contentobject_id' );
        $rule = new eZSubtreeNotificationRule( array(
            'user_id' => $adminUserID,
            'use_digest' => 0,
            'node_id' => 2 ) );
        $rule->store();

        // Create a content object below node #2
        $article = new ezpObject( 'article', 2 );
        $article->title = __FUNCTION__;
        $article->publish();
        $articleContentObject = $article->object;

        $list = eZSubtreeNotificationRule::fetchUserList( array( 2, 43 ), $articleContentObject );
        $this->assertInternalType( 'array', $list,
            "Return value should have been an array" );
        $this->assertEquals( 1, count( $list ),
            "Return value should have one item" );
        $this->assertInternalType( 'array', $list[0] );
        $this->assertArrayHasKey( 'user_id', $list[0] );
        $this->assertArrayHasKey( 'use_digest', $list[0] );
        $this->assertArrayHasKey( 'address', $list[0] );
        $this->assertEquals( 14, $list[0]['user_id'] );
        $this->assertEquals( 0, $list[0]['use_digest'] );
        $this->assertEquals( '*****@*****.**', $list[0]['address'] );
    }
 /**
  * Regression test for issue #14983
  *
  * @link http://issues.ez.no/14983
  **/
 public function testIssue14983()
 {
     $className = 'eZImageType test class';
     $classIdentifier = 'ezimagetype_test_class';
     $attributeName = 'Image';
     $attributeIdentifier = 'image';
     $attributeType = 'ezimage';
     $filePath = 'tests/tests/kernel/datatypes/ezimage/ezimagetype_regression_issue14983.png';
     $class = new ezpClass($className, $classIdentifier, $className);
     $classAttribute = $class->add($attributeName, $attributeIdentifier, $attributeType);
     $class->store();
     $object = new ezpObject($classIdentifier, 2);
     $object->name = __FUNCTION__;
     $dataMap = $object->object->dataMap();
     $fileAttribute = $dataMap[$attributeIdentifier];
     $dataType = new eZImageType();
     $dataType->fromString($fileAttribute, $filePath);
     $fileAttribute->store();
     $object->publish();
     $object->refresh();
     $contentObjectAttributeID = $fileAttribute->attribute("id");
     $files = eZImageFile::fetchForContentObjectAttribute($contentObjectAttributeID);
     $file = $files[0];
     // Read stored path, move to trash, and read stored path again
     $this->assertNotEquals($file, null);
     $oldFile = $file;
     $object->object->removeThis();
     $object->refresh();
     $files = eZImageFile::fetchForContentObjectAttribute($contentObjectAttributeID);
     $file = $files[0];
     $this->assertNotEquals($oldFile, $file, 'The stored file should be renamed when trashed');
 }
Esempio n. 4
0
 /**
  * Regression test for issue #16078
  *
  * @link http://issues.ez.no/16078
  */
 public function testIssue16078()
 {
     $classID = 5;
     // image class, can remain hardcoded, I guess
     $baseImagePath = dirname(__FILE__) . '/ezimagefile_regression_issue16078.png';
     $parts = pathinfo($baseImagePath);
     $imagePattern = $parts['dirname'] . DIRECTORY_SEPARATOR . $parts['filename'] . '_%s_%d.' . $parts['extension'];
     $toDelete = array();
     // Create version 1
     $imagePath = sprintf($imagePattern, md5(1), 1);
     copy($baseImagePath, $imagePath);
     $toDelete[] = $imagePath;
     $image = new ezpObject('image', 43);
     $image->name = __FUNCTION__;
     $image->image = $imagePath;
     $image->publish();
     $image->refresh();
     $publishedDataMap = $image->object->dataMap();
     $files = eZImageFile::fetchForContentObjectAttribute($publishedDataMap['image']->attribute('id'));
     $publishedImagePath = $files[0];
     // Create a new image file
     $imagePath = sprintf($imagePattern, md5(2), 2);
     copy($baseImagePath, $imagePath);
     $toDelete[] = $imagePath;
     // Create version 2 in another language, and remove it
     $languageCode = 'nor-NO';
     $version = self::addTranslationDontPublish($image, $languageCode);
     $version->removeThis();
     // Check that the original file still exists
     $this->assertTrue(file_exists($publishedImagePath), 'The image file from version 1 should still exist when version 2 is removed');
     array_map('unlink', $toDelete);
     $image->purge();
 }
 /**
  * Test regression for issue #13952: Workflow cronjob gives fatal error if
  * node is moved to different location before approval.
  *
  * Test Outline
  * ------------
  * 1. Create a folder
  * 2. Approve folder
  * 3. Create child of folder
  * 4. Approve child
  * 5. Create a new version and re-publish the child
  * 6. Move child to root
  * 7. Approve child
  * 8. Run approval cronjob
  *
  * @result: Fatal error: Call to a member function attribute() on a non-object in
  *          /www/trunk/kernel/content/ezcontentoperationcollection.php on line 313
  * @expected: No fatal error
  * @link http://issues.ez.no/13952
  */
 public function testApprovalFatalErrorWhenMoving()
 {
     $anonymousObjectID = eZUser::fetchByName('anonymous')->attribute('contentobject_id');
     // STEP 1: Create a folder
     $folder = new ezpObject("folder", 2, $anonymousObjectID);
     $folder->name = "Parent folder (needs approval)";
     $folder->publish();
     // STEP 2: Approve folder
     $collaborationItem = eZCollaborationItem::fetch(1);
     $this->approveCollaborationItem($collaborationItem);
     $this->runWorkflow();
     // STEP 3: Create child of folder
     $child = new ezpObject("folder", $folder->mainNode->node_id, $anonymousObjectID);
     $child->name = "Child folder (needs approval)";
     $child->publish();
     // STEP 4: Approve child
     $collaborationItem = eZCollaborationItem::fetch(2);
     $this->approveCollaborationItem($collaborationItem);
     $this->runWorkflow();
     // STEP 5: Re-publish child
     $newVersion = $child->createNewVersion();
     ezpObject::publishContentObject($child->object, $newVersion);
     // STEP 6: Move child to root
     $child->mainNode->move(2);
     // STEP 7: Approve child again
     $collaborationItem = eZCollaborationItem::fetch(3);
     $this->approveCollaborationItem($collaborationItem);
     // STEP 8: Run approval cronjob
     $this->runWorkflow();
 }
    /**
     * @group issue18249
     */
    public function testIssue18249()
    {

        // setup a class C1 with objectrelationlist and pattern name
        $classIdentifier = strtolower( __FUNCTION__ );
        $class1 = new ezpClass(
            __FUNCTION__, $classIdentifier, '<test_name><test_relation>'
        );
        $class1->add( 'Test name', 'test_name', 'ezstring' );
        $class1->add( 'Test Relation', 'test_relation', 'ezobjectrelationlist' );
        $class1->store();

        $o1 = new ezpObject( 'article', 2, 14, 1, 'eng-GB' );
        $o1->title = 'Test_ENG';
        $o1->publish();
        $o1->addTranslation( 'xxx-XX', array( 'title' => 'Test_XXX' ) );

        $o2 = new ezpObject( $classIdentifier, 2, 14, 1, 'xxx-XX' );
        $o2->test_name = 'name_';
        $o2->test_relation = array( $o1->attribute( 'id' ) );
        $o2->publish();

        // test O2's name
        $this->assertEquals( 'name_Test_XXX', $o2->name );
    }
 /**
  * test fetchChildListByVersionStatus
  */
 public function testFetchChildListByVersionStatus()
 {
     //create object
     $top = new ezpObject('article', 2);
     $top->name = 'TOP ARTICLE';
     $top->publish();
     $child = new ezpObject('article', $top->mainNode->node_id);
     $child->name = 'THIS IS AN ARTICLE';
     $child->publish();
     $child2 = new ezpObject('article', $top->mainNode->node_id);
     $child2->name = 'THIS IS AN ARTICLE2';
     $child2->publish();
     $pendingChild = new ezpObject('article', $top->mainNode->node_id);
     $pendingChild->name = 'THIS IS A PENDING ARTICLE';
     $pendingChild->publish();
     $version = $pendingChild->currentVersion();
     $version->setAttribute('status', eZContentObjectVersion::STATUS_PENDING);
     $version->store();
     $idList = array($top->mainNode->node_id);
     $arrayResult = eZNodeAssignment::fetchChildListByVersionStatus($idList, eZContentObjectVersion::STATUS_PENDING, false);
     $this->assertEquals($pendingChild->id, $arrayResult[0]['contentobject_id']);
     $arrayResult = eZNodeAssignment::fetchChildListByVersionStatus($idList, eZContentObjectVersion::STATUS_PUBLISHED, true);
     $this->assertEquals($child->id, $arrayResult[0]->attribute('contentobject_id'));
     $countResult = eZNodeAssignment::fetchChildCountByVersionStatus($idList, eZContentObjectVersion::STATUS_PENDING);
     $this->assertEquals(1, $countResult);
     $countResult = eZNodeAssignment::fetchChildCountByVersionStatus($idList, eZContentObjectVersion::STATUS_PUBLISHED);
     $this->assertEquals(2, $countResult);
 }
 public function testUpdateAndPublishObject()
 {
     // create content object first
     $object = new ezpObject("folder", 2);
     $object->title = __FUNCTION__ . '::' . __LINE__ . '::' . time();
     $object->publish();
     $contentObjectID = $object->attribute('id');
     if ($object instanceof eZContentObject) {
         $now = date('Y/m/d H:i:s', time());
         $sectionID = 3;
         $remoteID = md5($now);
         $attributeList = array('name' => 'name ' . $now, 'short_name' => 'short_name ' . $now, 'short_description' => 'short_description' . $now, 'description' => 'description' . $now, 'show_children' => false);
         $params = array();
         $params['attributes'] = $attributeList;
         $params['remote_id'] = $remoteID;
         $params['section_id'] = $sectionID;
         $result = eZContentFunctions::updateAndPublishObject($object, $params);
         $this->assertTrue($result);
         $object = eZContentObject::fetch($contentObjectID);
         $this->assertEquals($object->attribute('section_id'), $sectionID);
         $this->assertEquals($object->attribute('remote_id'), $remoteID);
         $dataMap = $object->dataMap();
         $this->assertEquals($attributeList['name'], $dataMap['name']->content());
         $this->assertEquals($attributeList['short_name'], $dataMap['short_name']->content());
         $this->assertEquals($attributeList['short_description'], $dataMap['short_description']->content());
         $this->assertEquals($attributeList['description'], $dataMap['description']->content());
         $this->assertEquals($attributeList['show_children'], (bool) $dataMap['show_children']->content());
     }
 }
 /**
  * @param string $name
  * @return eZContentObject
  */
 protected function createImage($name)
 {
     $imageObject = new ezpObject(self::CLASS_IDENTIFIER, 2);
     $imageObject->name = $name;
     $imageObject->image = self::IMAGE_FILE_PATH;
     $imageObject->publish();
     return $this->forceFetchContentObject($imageObject->attribute('id'));
 }
 private function createObjectForRelation($title = false)
 {
     if (!$title) {
         $title = uniqid(__METHOD__);
     }
     $relatedObject = new ezpObject('article', 2, 14, 1, 'eng-GB');
     $relatedObject->title = $title;
     return $relatedObject->publish();
 }
Esempio n. 11
0
 public function tearDown()
 {
     $this->solrSearch->removeObject($this->object->object);
     $this->object->remove();
     $this->object = null;
     $this->solrSearch = null;
     ezpINIHelper::restoreINISettings();
     parent::tearDown();
 }
Esempio n. 12
0
 /**
  * Creates an article in eZ Publish in the folder $folderId,
  * with title $articleTitle and summary $articleIntro and returns its ID.
  *
  * @param int $folderId
  * @param string $articleName
  * @param string $articleIntro
  * @return int The ID of the article created
  */
 public function createEZPArticle($folderId, $articleTitle, $articleIntro)
 {
     $object = new ezpObject('article', $folderId);
     $object->title = $articleTitle;
     $object->intro = $articleIntro;
     $object->publish();
     $objectId = (int) $object->attribute('id');
     return $objectId;
 }
    /**
     * Test to verify that eznode_assignment entres get removed.
     *
     * @link http://issues.ez.no/15478
     */
    public function testRemoveAssignments()
    {
        $db = eZDB::instance();

        $testSet = array();

        $folder = new ezpObject( "folder", 2 );
        $folder->name = __FUNCTION__;
        $folder->publish();
        $testSet[] = $folder;

        $childOne = new ezpObject( "folder", $folder->mainNode->node_id );
        $childOne->name = "ChildOne";
        $childOne->publish();
        $testSet[] = $childOne;

        $childTwo = new ezpObject( "folder", $folder->mainNode->node_id );
        $childTwo->name = "ChildTwo";
        $childTwo->publish();
        $testSet[] = $childTwo;

        $subChildOne = new ezpObject( 'article', $childOne->mainNode->node_id );
        $subChildOne->title = "SubChild";
        $subChildOne->publish();
        $testSet[] = $subChildOne;

        $subChildTwo = new ezpObject( 'article', $childOne->mainNode->node_id );
        $subChildTwo->title = "SubChildOther";
        $subChildTwo->publish();
        $testSet[] = $subChildTwo;

        $subChildThree = new ezpObject( 'article', $childOne->mainNode->node_id );
        $subChildThree->title = "SubChildThird";
        $subChildThree->publish();
        $testSet[] = $subChildThree;

        // Let's add another placement here
        $newPlacementSubChildOne = $subChildOne->addNode( $childTwo->mainNode->node_id );
        $testSet[] = $newPlacementSubChildOne;

        // $this->debugBasicNodeInfo( $testSet );

        $coId = $newPlacementSubChildOne->attribute( 'contentobject_id' );

        eZContentOperationCollection::removeAssignment( $childTwo->mainNode->node_id, $childTwo->id, array( $newPlacementSubChildOne ), false );

        $checkSql = "SELECT * FROM eznode_assignment WHERE contentobject_id = {$coId}";
        $result = $db->arrayQuery( $checkSql );

        // After removing one of the assignments, the number of node
        // assignments for the content object should be only one.
        $numberOfAssignments = count( $result );

        self::assertEquals( 1, $numberOfAssignments, "The number of node assignments are not correct, eznode_assignment table not cleaned up correctly." );
    }
 /**
  * Regression test for issue #15263
  * Content object name/url of imported content classes aren't generated correctly
  *
  * @url http://issues.ez.no/15263
  *
  * @outline
  * 1) Expire and force generation of class attribute cache
  * 2) Load a test package
  * 3) Install the package
  * 4) Publish an object of the imported class
  * 5) The object name / url alias shouldn't be the expected one
  **/
 public function testIssue15263()
 {
     $adminUser = eZUser::fetchByName('admin');
     $previousUser = eZUser::currentUser();
     eZUser::setCurrentlyLoggedInUser($adminUser, $adminUser->attribute('contentobject_id'));
     // 1) Expire and force generation of class attribute cache
     $handler = eZExpiryHandler::instance();
     $handler->setTimestamp('class-identifier-cache', time() - 1);
     $handler->store();
     eZContentClassAttribute::classAttributeIdentifierByID(1);
     // 1) Load a test package
     $packageName = 'ezpackage_regression_testIssue15223.ezpkg';
     $packageFilename = dirname(__FILE__) . DIRECTORY_SEPARATOR . $packageName;
     $packageImportTried = false;
     while (!$packageImportTried) {
         $package = eZPackage::import($packageFilename, $packageName);
         if (!$package instanceof eZPackage) {
             if ($package === eZPackage::STATUS_ALREADY_EXISTS) {
                 $packageToRemove = eZPackage::fetch($packageName);
                 $packageToRemove->remove();
             } else {
                 self::fail("An error occured loading the package '{$packageFilename}'");
             }
         }
         $packageImportTried = true;
     }
     // 2) Install the package
     $installParameters = array('site_access_map' => array('*' => false), 'top_nodes_map' => array('*' => 2), 'design_map' => array('*' => false), 'restore_dates' => true, 'user_id' => $adminUser->attribute('contentobject_id'), 'non-interactive' => true, 'language_map' => $package->defaultLanguageMap());
     $result = $package->install($installParameters);
     // 3) Publish an object of the imported class
     $object = new ezpObject('test_issue_15523', 2, $adminUser->attribute('contentobject_id'), 1);
     $object->myname = __METHOD__;
     $object->myothername = __METHOD__;
     $publishedObjectID = $object->publish();
     unset($object);
     // 4) Test data from the publish object
     $publishedNodeArray = eZContentObjectTreeNode::fetchByContentObjectID($publishedObjectID);
     if (count($publishedNodeArray) != 1) {
         $this->fail("An error occured fetching node for object #{$publishedObjectID}");
     }
     $publishedNode = $publishedNodeArray[0];
     if (!$publishedNode instanceof eZContentObjectTreeNode) {
         $this->fail("An error occured fetching node for object #{$publishedObjectID}");
     } else {
         $this->assertEquals("eZPackageRegression::testIssue15263", $publishedNode->attribute('name'));
         $this->assertEquals("eZPackageRegression-testIssue15263", $publishedNode->attribute('url_alias'));
     }
     // Remove the installed package & restore the logged in user
     $package->remove();
     eZUser::setCurrentlyLoggedInUser($previousUser, $previousUser->attribute('contentobject_id'));
 }
 public function createObject(ezpDatatypeTestDataSet $dataSet)
 {
     static $counter = 0;
     $this->object = new ezpObject($this->class->identifier, 2);
     $this->object->title = "{$this->datatype} test #" . ++$counter;
     $dataMap = $this->object->dataMap();
     $this->attribute = $dataMap[$this->attributeIdentifier];
     try {
         $attribute = $this->attribute->fromString($dataSet->fromString);
     } catch (PHPUnit_Framework_Error_Notice $e) {
         self::fail("A notice has been thrown when calling fromString: " . $e->getMessage());
     }
     $this->object->publish();
 }
 /**
  * Test scenario for issue #13552: Broken datamap caching when copying
  * content objects
  *
  * This test verifies that the content object attributes are fresh and not
  * cached versions of the original object. We can achieve this by comparing
  * the content object attribute ids, and make sure they are not the same.
  *
  */
 public function testDataMapFreshOnCopyObject()
 {
     $folder = new ezpObject("folder", 2);
     $folder->name = __FUNCTION__;
     $folder->short_description = "123";
     $folder->publish();
     $attrObj1 = self::compareObjectAttributeIds($folder->object);
     $newObject = self::copyObject($folder->object, 2);
     $attrObjCopy = self::compareObjectAttributeIds($newObject);
     $res = array_intersect_assoc($attrObj1, $attrObjCopy);
     // If the intersection of key-valye pairs in the two arrays are empty,
     // all the attribute ids are different in the two objects, and we have
     // fresh copy
     self::assertTrue(empty($res), "The copied object does contain fresh content object attributes");
 }
    /**
     * Regression test for issue #14983
     *
     * @link http://issues.ez.no/14983
     */
    public function testIssue14983()
    {
        $className = 'eZBinaryFileType test class';
        $classIdentifier = 'ezbinaryfiletype_test_class';
        $attributeName = 'File';
        $attributeIdentifier = 'file';
        $attributeType = 'ezbinaryfile';
        $filePath = 'tests/tests/kernel/datatypes/ezbinaryfile/ezbinaryfiletype_regression_issue14983.txt';

        $class = new ezpClass( $className, $classIdentifier, $className );
        $classAttribute = $class->add( $attributeName, $attributeIdentifier, $attributeType );
        $class->store();

        $object = new ezpObject( $classIdentifier, 2 );
        $object->name = __FUNCTION__;
        {
            $dataMap = $object->object->dataMap();
            $fileAttribute = $dataMap[$attributeIdentifier];
            {
                $dataType = new eZBinaryFileType();
                $dataType->fromString( $fileAttribute, $filePath );
            }
            $fileAttribute->store();
        }
        $object->publish();
        $object->refresh();

        $contentObjectAttributeID = $fileAttribute->attribute( "id" );
        $files = eZBinaryFile::fetch( $contentObjectAttributeID );
        foreach ( $files as $file )
        {
            // Read stored path, move to trash, and read stored path again
            $this->assertNotEquals( $file, null );

            $storedFileInfo = $file->storedFileInfo();
            $storedFilePath = $storedFileInfo['filepath'];
            $version = $file->attribute( 'version' );

            $object->object->removeThis();
            $object->refresh();
            $file = eZBinaryFile::fetch( $contentObjectAttributeID, $version );

            $storedFileInfo = $file->storedFileInfo();
            $storedFilePathAfterTrash = $storedFileInfo['filepath'];

            $this->assertNotEquals( $storedFilePath, $storedFilePathAfterTrash, 'The stored file should be renamed when trashed' );
        }
    }
 public function tearDown()
 {
     if (self::ldapIsEnabled()) {
         $this->mainGroup->remove();
     }
     parent::tearDown();
 }
 /**
  * Regression test for issue 16400
  * @link http://issues.ez.no/16400
  * @return unknown_type
  */
 public function testIssue16400()
 {
     $className = 'Media test class';
     $classIdentifier = 'media_test_class';
     $filePath = 'tests/tests/kernel/datatypes/ezmedia/ezmediatype_regression_issue16400.flv';
     eZFile::create($filePath);
     $attributeName = 'Media';
     $attributeIdentifier = 'media';
     $attributeType = 'ezmedia';
     //1. test method fetchByContentObjectID
     $class = new ezpClass($className, $classIdentifier, $className);
     $class->add($attributeName, $attributeIdentifier, $attributeType);
     $attribute = $class->class->fetchAttributeByIdentifier($attributeIdentifier);
     $attribute->setAttribute('can_translate', 0);
     $class->store();
     $object = new ezpObject($classIdentifier, 2);
     $dataMap = $object->object->dataMap();
     $fileAttribute = $dataMap[$attributeIdentifier];
     $dataType = new eZMediaType();
     $dataType->fromString($fileAttribute, $filePath);
     $fileAttribute->store();
     $object->publish();
     $object->refresh();
     //verify fetchByContentObjectID
     $mediaObject = eZMedia::fetch($fileAttribute->attribute('id'), 1);
     $medias = eZMedia::fetchByContentObjectID($object->object->attribute('id'));
     $this->assertEquals($mediaObject->attribute('filename'), $medias[0]->attribute('filename'));
     $medias = eZMedia::fetchByContentObjectID($object->object->attribute('id'), $fileAttribute->attribute('language_code'));
     $this->assertEquals($mediaObject->attribute('filename'), $medias[0]->attribute('filename'));
     //2. test issue
     // create translation
     $contentObject = $object->object;
     $storedFileName = $mediaObject->attribute('filename');
     $version = $contentObject->createNewVersionIn('nor-NO', $fileAttribute->attribute('language_code'));
     $version->setAttribute('status', eZContentObjectVersion::STATUS_INTERNAL_DRAFT);
     $version->store();
     $version->removeThis();
     $sys = eZSys::instance();
     $dir = $sys->storageDirectory();
     //verify the file is deleted
     $storedFilePath = $dir . '/original/video/' . $storedFileName;
     $file = eZClusterFileHandler::instance($storedFilePath);
     $this->assertTrue($file->exists($storedFilePath));
     if ($file->exists($storedFilePath)) {
         unlink($storedFilePath);
     }
 }
 public function testSendActivationEmail()
 {
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('email', '*****@*****.**');
     $subscriber->setAttribute('user_id', 10);
     $subscriber->store();
     $contentObject = new ezpObject('article');
     $contentObject->publish();
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('subscriber_type', 'ezcomcomment');
     $subscription->setAttribute('enabled', 0);
     $subscription->setAttribute('content_id', '10_2');
     $hashString = ezcomUtility::instance()->generateSubscriptionHashString($subscription);
     $subscription->setAttribute('hash_string', $hashString);
     $subscription->store();
     //         $result = ezcomSubscriptionManager::sendActivationEmail( $contentObject, $subscriber, $subscription );
     //         $this->assertTrue( $result );
 }
 public function testIssue18249()
 {
     // setup a class C1 with objectrelationlist and pattern name
     $class1 = new ezpClass('TestClass1', 'testclass1', '<test_name><test_relation>');
     $class1->add('Test name', 'test_name', 'ezstring');
     $class1->add('Test Relation', 'test_relation', 'ezobjectrelationlist');
     $class1->store();
     // create an object O1 with eng and nor
     $o1 = new ezpObject('article', false, 14, 1, 'nor-NO');
     $o1->title = 'Test_NOR';
     $o1->publish();
     $o1->addTranslation('nor-NO', array('title' => 'Test_NOR'));
     // create an object O2 based on C1 with Nor
     $o2 = new ezpObject('testclass1', false, 14, 1, 'nor-NO');
     $o2->test_name = 'name_';
     $o2->test_relation = array($o1->attribute('id'));
     $o2->publish();
     // test O2's name
     $this->assertEquals('name_Test_NOR', $o2->name);
 }
 /**
  * Tests that the output process works with objects.
  * 
  * There should be no crash from casting errors.
  *
  */
 public function testDisplayVariableWithObject()
 {
     $db = eZDB::instance();
     // STEP 1: Add test folder
     $folder = new ezpObject("folder", 2);
     $folder->name = __FUNCTION__;
     $folder->publish();
     $nodeId = $folder->mainNode->node_id;
     $node = eZContentObjectTreeNode::fetch($nodeId);
     $attrOp = new eZTemplateAttributeOperator();
     $outputTxt = '';
     try {
         $attrOp->displayVariable($node, false, true, 2, 0, $outputTxt);
     } catch (PHPUnit_Framework_Error $e) {
         self::fail("eZTemplateAttributeOperator raises an error when working with objects.");
     }
     self::assertNotNull($outputTxt, "Output text is empty.");
     // this is an approxmiate test. The output shoudl contain the name of the object it has been generated correctly.
     self::assertContains(__FUNCTION__, $outputTxt, "There is something wrong with the output of the attribute operator. Object name not found.");
 }
 /**
  * Regression test for issue #15155
  *
  * @link http://issues.ez.no/15155
  */
 public function testIssue15155()
 {
     // figure out the max versions for images
     $contentINI = eZINI::instance('content.ini');
     $versionlimit = $contentINI->variable('VersionManagement', 'DefaultVersionHistoryLimit');
     $limitList = eZContentClass::classIDByIdentifier($contentINI->variable('VersionManagement', 'VersionHistoryClass'));
     $classID = 5;
     // image class, can remain hardcoded, I guess
     foreach ($limitList as $key => $value) {
         if ($classID == $key) {
             $versionlimit = $value;
         }
     }
     if ($versionlimit < 2) {
         $versionlimit = 2;
     }
     $baseImagePath = dirname(__FILE__) . '/ezimagealiashandler_regression_issue15155.png';
     $parts = pathinfo($baseImagePath);
     $imagePattern = $parts['dirname'] . DIRECTORY_SEPARATOR . $parts['filename'] . '_%s_%d.' . $parts['extension'];
     $toDelete = array();
     // Create version 1
     $imagePath = sprintf($imagePattern, md5(1), 1);
     copy($baseImagePath, $imagePath);
     $toDelete[] = $imagePath;
     $image = new ezpObject('image', 43);
     $image->name = __FUNCTION__;
     $image->image = $imagePath;
     $image->publish();
     $image->refresh();
     $contentObjectID = $image->object->attribute('id');
     $dataMap = eZContentObject::fetch($contentObjectID)->dataMap();
     $originalAliases[1] = $image->image->imageAlias('original');
     for ($i = 2; $i <= 20; $i++) {
         // Create a new image file
         $imagePath = sprintf($imagePattern, md5($i), $i);
         copy($baseImagePath, $imagePath);
         $toDelete[] = $imagePath;
         $newVersion = $image->createNewVersion();
         $dataMap = $newVersion->dataMap();
         $dataMap['image']->fromString($imagePath);
         ezpObject::publishContentObject($image->object, $newVersion);
         $image->refresh();
         $originalAliases[$i] = $image->image->imageAlias('original');
         if ($i > $versionlimit) {
             $removeVersion = $i - $versionlimit;
             $aliasPath = $originalAliases[$removeVersion]['url'];
             $this->assertFalse(file_exists($aliasPath), "Alias {$aliasPath} for version {$removeVersion} should have been removed");
         }
     }
     array_map('unlink', $toDelete);
     $image->purge();
 }
Esempio n. 24
0
 /**
  * Regression test for issue #17781
  * @link http://issues.ez.no/17781
  * @group issue17781
  */
 public function testRestoreImageTrashed()
 {
     $this->imageObject->refresh();
     $dataMap = $this->imageObject->dataMap();
     self::assertArrayHasKey("image", $dataMap);
     $untrashedBasename = $dataMap["image"]->content()->directoryPath();
     unset($dataMap);
     /*
      * 1. Move the object to trash with eZContentObject::removeThis()
      * 2. Refresh (clear in-memory cache...)
      * 3. Artificially restore the object attributes
      * 4. Refresh
      */
     $this->imageObject->removeThis();
     // Now image dir is different (see self::testIssue14983())
     $this->imageObject->refresh();
     $this->imageObject->restoreObjectAttributes();
     $this->imageObject->refresh();
     $dataMap = $this->imageObject->dataMap();
     self::assertArrayHasKey("image", $dataMap);
     self::assertSame($untrashedBasename, $dataMap["image"]->content()->directoryPath());
 }
 /**
  * Unit test for eZContentObject::relatedObjects()
  *
  * Outline:
  * 1) Create a content class with ezobjectrelation attribute
  * 2) Create object of that class and relate to another object through the attribute
  * 3) Check that object loaded by eZContentObject::relatedObjects() is the correct one
  */
 public function testRelatedObjectsWithAttributeId()
 {
     // Create a test content class
     $class = new ezpClass(__FUNCTION__, __FUNCTION__, 'name');
     $class->add('Name', 'name', 'ezstring');
     $attributeId = $class->add('Single relation #1', 'relation', 'ezobjectrelation')->attribute('id');
     $class->store();
     // Create an article we will relate our object to
     $article = new ezpObject('article', 2);
     $article->title = "Related object #1 for " . __FUNCTION__;
     $article->publish();
     // Create a test object with attribute relation to created article
     $object = new ezpObject(__FUNCTION__, 2);
     $object->name = __FUNCTION__;
     $object->relation = $article->attribute('id');
     $object->publish();
     $contentObject = eZContentObject::fetch($object->attribute('id'));
     $relatedObjects = $contentObject->relatedObjects(false, false, $attributeId);
     $this->assertCount(1, $relatedObjects);
     $this->assertInstanceOf("eZContentObject", $relatedObjects[0]);
     $this->assertEquals($article->attribute('id'), $relatedObjects[0]->attribute("id"), "Related object is not the expected object");
 }
     if ($pid == -1) {
         error_log('Could not launch new job, exiting');
     } else {
         if ($pid > 1) {
             $currentJobs[] = $pid;
         } else {
             $exitStatus = 0;
             //Error code if you need to or whatever
             $myPid = getmypid();
             // No need if the DB ain't initialized before forking
             $db = eZDB::instance(false, false, true);
             eZDB::setInstance($db);
             // suppress error output due to fatal DB errors
             // exceptions from the DB layer would allow for better information output
             fclose(STDERR);
             $object = new ezpObject($optContentClass, $optParentNode);
             $object->title = "Wait Timeout Test, pid {$myPid}\n";
             if ($optGenerateContent === true) {
                 $object->body = file_get_contents('xmltextsource.txt');
             }
             $object->publish();
             eZExecution::cleanExit();
         }
     }
 }
 if ($script->verboseOutputLevel() > 0) {
     $cli->output("Main process: waiting for children...");
 }
 $errors = 0;
 while (!empty($currentJobs)) {
     foreach ($currentJobs as $index => $pid) {
 /**
  * Creates an article in eZ Publish in the folder $folderId,
  * with title $articleTitle and summary $articleIntro and returns its ID.
  *
  * @param int $folderId
  * @param string $articleName
  * @param string $articleIntro
  * @return ezpObject
  */
 public function createEZPArticle($folderId, $articleTitle, $articleIntro, $articleRemoteID)
 {
     $object = new ezpObject('article', $folderId);
     $object->title = $articleTitle;
     $object->intro = $articleIntro;
     $object->publish();
     // Update object RemoteID
     $object->setAttribute('remote_id', $articleRemoteID);
     $object->store();
     return $object;
 }
 /**
  * Test for issue #14370: Inserting non break space doesn't work
  * 
  * @note Test depends on template output!!
  * @link http://issues.ez.no/14370
  */
 public function testNonBreakSpace()
 {
     $xmlData = '<paragraph>esp&nbsp;ace</paragraph>';
     // Step 1: Create folder
     $folder = new ezpObject("folder", 2);
     $folder->name = "Non breaking space Test";
     $folder->short_description = $xmlData;
     $folder->publish();
     $xhtml = $folder->short_description->attribute('output')->attribute('output_text');
     self::assertEquals('<p>esp&nbsp;ace</p>', $xhtml);
 }
    /**
     * Regression test for issue {@see #17632 http://issues.ez.no/17632}
     *
     * In a multi language environment, a node fetched with a language other than the prioritized one(s) will return the
     * URL alias in the prioritized language
     */
    public function testIssue17632()
    {
        $bkpLanguages = eZContentLanguage::prioritizedLanguageCodes();

        $strNameEngGB = __FUNCTION__ . " eng-GB";
        $strNameFreFR = __FUNCTION__ . " fre-FR";

        // add a secondary language
        $locale = eZLocale::instance( 'fre-FR' );
        $translation = eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );

        // set the prioritize language list to contain english
        // ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'SiteLanguageList', array( 'fre-FR' ) );
        eZContentLanguage::setPrioritizedLanguages( array( 'fre-FR' ) );

        // Create an object with data in fre-FR and eng-GB
        $folder = new ezpObject( 'folder', 2, 14, 1, 'eng-GB' );
        $folder->publish();

        // Workaround as setting folder->name directly doesn't produce the expected result
        $folder->addTranslation( 'eng-GB', array( 'name' => $strNameEngGB ) );
        $folder->addTranslation( 'fre-FR', array( 'name' => $strNameFreFR ) );

        $nodeId = $folder->main_node_id;

        // fetch the node with no default parameters. Should return the french URL Alias
        $node = eZContentObjectTreeNode::fetch( $nodeId );
        self::assertEquals( 'testIssue17632-fre-FR' , $node->attribute( 'url_alias' ) );

        // fetch the node in english. Should return the english URL Alias
        $node = eZContentObjectTreeNode::fetch( $nodeId, 'eng-GB' );
        self::assertEquals( 'testIssue17632-eng-GB' , $node->attribute( 'url_alias' ) );

        ezpINIHelper::restoreINISettings();
        eZContentLanguage::setPrioritizedLanguages( $bkpLanguages );
    }
 /**
  * Helper method that creates and returns a ezcontentobject of class 'link'
  *
  * @param string $url
  * @return ezcontentobject $link
  */
 private function createNewLinkObject($url)
 {
     $link = new ezpObject("link", 2);
     $link->name = __FUNCTION__ . mt_rand();
     $link->location = array("", $url);
     $link->publish();
     return $link;
 }