Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implemented: Transaction test for LocationService.

  • Loading branch information...
commit 2b063158a395c5466ecbfa3b51878673c2281242 1 parent 7061209
Tobias Schlitt authored March 22, 2012
44  eZ/Publish/API/Repository/Tests/LocationServiceTest.php
@@ -254,6 +254,50 @@ public function testCreateLocationThrowsInvalidArgumentExceptionRemoteIdExists()
254 254
     }
255 255
 
256 256
     /**
  257
+     * Test for the createLocation() method.
  258
+     *
  259
+     * @return void
  260
+     * @see \eZ\Publish\API\Repository\LocationService::createLocation()
  261
+     * 
  262
+     */
  263
+    public function testCreateLocationInTransactionWithRollback()
  264
+    {
  265
+        $repository = $this->getRepository();
  266
+
  267
+        /* BEGIN: Use Case */;
  268
+        $contentService = $repository->getContentService();
  269
+        $locationService = $repository->getLocationService();
  270
+
  271
+        $repository->beginTransaction();
  272
+
  273
+        // ContentInfo for "How to use eZ Publish"
  274
+        $contentInfo = $contentService->loadContentInfo( 108 );
  275
+
  276
+        $locationCreate = $locationService->newLocationCreateStruct( 5 );
  277
+        $locationCreate->remoteId = 'sindelfingen';
  278
+
  279
+        $createdLocationId = $locationService->createLocation(
  280
+            $contentInfo,
  281
+            $locationCreate
  282
+        )->id;
  283
+
  284
+        $repository->rollback();
  285
+
  286
+        try
  287
+        {
  288
+            // Throws exception since creation of location was rolled back
  289
+            $location = $locationService->loadLocation( $createdLocationId );
  290
+        }
  291
+        catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
  292
+        {
  293
+            return;
  294
+        }
  295
+        /* END: Use Case */
  296
+
  297
+        $this->fail( 'Objects still exists after rollback.' );
  298
+    }
  299
+
  300
+    /**
257 301
      * Test for the loadLocation() method.
258 302
      *
259 303
      * @return \eZ\Publish\API\Repository\Values\Content\Location
7  eZ/Publish/API/Repository/Tests/Stubs/LocationServiceStub.php
@@ -113,7 +113,7 @@ public function createLocation( ContentInfo $contentInfo, LocationCreateStruct $
113 113
 
114 114
         $data['contentInfo'] = $contentInfo;
115 115
 
116  
-        $data['id']          = $this->nextLocationId++;
  116
+        $data['id']          = ++$this->nextLocationId;
117 117
         $data['pathString']  = $parentLocation->pathString . $data['id'] . '/';
118 118
         $data['depth']       = substr_count( $data['pathString'], '/' ) - 2;
119 119
         $data['childCount']  = 0;
@@ -870,15 +870,18 @@ public function __rollback()
870 870
      */
871 871
     private function initFromFixture()
872 872
     {
  873
+        $this->locations      = array();
  874
+        $this->nextLocationId = 0;
  875
+
873 876
         list(
874 877
             $locations,
875 878
             $this->nextLocationId
876 879
         ) = $this->repository->loadFixture( 'Location' );
877 880
 
878  
-        ++$this->nextGroupId;
879 881
         foreach ( $locations as $location )
880 882
         {
881 883
             $this->locations[$location->id] = $location;
  884
+            $this->nextLocationId = max( $this->nextLocationId, $location->id );
882 885
         }
883 886
         $this->calculateChildCounts();
884 887
     }

0 notes on commit 2b06315

Please sign in to comment.
Something went wrong with that request. Please try again.