コード例 #1
0
ファイル: RelationTest.php プロジェクト: allipierre/Typo3
 /**
  * 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']);
 }
コード例 #2
0
ファイル: RelationTest.php プロジェクト: khanhdeux/typo3test
    /**
     * Test if adjusting existing mm relations do not relations with other objects
     *
     * @test
     */
    public function adjustingMmRelationWithTablesnameAndFieldnameFieldDoNotTouchOtherRelations()
    {
        /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
        $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
        /** @var \ExtbaseTeam\BlogExample\Domain\Model\Post $post */
        $post = $postRepository->findByUid(1);
        // Move category down
        foreach ($post->getCategories() as $category) {
            $post->removeCategory($category);
            $post->addCategory($category);
            break;
        }
        $postRepository->update($post);
        $this->persistentManager->persistAll();
        // re-fetch Post and Blog
        $newBlogCategoryCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid_local', 'sys_category_record_mm', 'tablenames = "tx_blogexample_domain_model_blog"
			AND fieldname = "categories"
			AND uid_foreign = ' . $this->blog->getUid() . '');
        $this->assertSame($this->blog->getCategories()->count(), $newBlogCategoryCount);
    }