Exemplo n.º 1
0
 /**
  * Tests moving object from the end to the middle of the sorted 1:M relation (Blog:Posts)
  *
  * @test
  */
 public function movePostFromEndToTheMiddle()
 {
     $countPosts = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_post');
     $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
     $posts = clone $this->blog->getPosts();
     $postsArray = $posts->toArray();
     $latestPost = array_pop($postsArray);
     $this->blog->getPosts()->removeAll($posts);
     $counter = 0;
     $postCount = $posts->count();
     foreach ($posts as $post) {
         if ($counter != $postCount - 1) {
             $this->blog->addPost($post);
         }
         if ($counter == 4) {
             $latestPost->setTitle('MOVED POST ' . $latestPost->getTitle());
             $this->blog->addPost($latestPost);
         }
         $counter++;
     }
     $this->updateAndPersistBlog();
     $countPosts = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_blogexample_domain_model_post', 'deleted=0');
     $this->assertSame($this->numberOfRecordsInFixture, $countPosts);
     $post = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('title,sorting', 'tx_blogexample_domain_model_post', 'blog =' . $this->blog->getUid(), '', 'sorting DESC');
     $this->assertSame('Post9', $post['title']);
     $this->assertSame('10', $post['sorting']);
     $post = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('title,uid', 'tx_blogexample_domain_model_post', 'blog =' . $this->blog->getUid() . ' AND sorting=6');
     $this->assertSame('MOVED POST Post10', $post['title']);
     $this->assertSame('10', $post['uid']);
 }