Code Duplication    Length = 16-20 lines in 3 locations

lib/Cake/Test/Case/Model/ModelWriteTest.php 3 locations

@@ 474-489 (lines=16) @@
471
 *
472
 * @return void
473
 */
474
	public function testCounterCacheUpdated() {
475
		$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
476
		$User = new CounterCacheUser();
477
		$Post = new CounterCachePost();
478
479
		$data = $Post->find('first', array(
480
			'conditions' => array('id' => 1),
481
			'recursive' => -1
482
		));
483
		$data[$Post->alias]['user_id'] = 301;
484
		$Post->save($data);
485
486
		$users = $User->find('all', array('order' => 'User.id'));
487
		$this->assertEquals(1, $users[0]['User']['post_count']);
488
		$this->assertEquals(2, $users[1]['User']['post_count']);
489
	}
490
491
/**
492
 * Test counter cache with models that use a non-standard (i.e. not using 'id')
@@ 497-516 (lines=20) @@
494
 *
495
 * @return void
496
 */
497
	public function testCounterCacheWithNonstandardPrimaryKey() {
498
		$this->loadFixtures(
499
			'CounterCacheUserNonstandardPrimaryKey',
500
			'CounterCachePostNonstandardPrimaryKey'
501
		);
502
503
		$User = new CounterCacheUserNonstandardPrimaryKey();
504
		$Post = new CounterCachePostNonstandardPrimaryKey();
505
506
		$data = $Post->find('first', array(
507
			'conditions' => array('pid' => 1),
508
			'recursive' => -1
509
		));
510
		$data[$Post->alias]['uid'] = 301;
511
		$Post->save($data);
512
513
		$users = $User->find('all', array('order' => 'User.uid'));
514
		$this->assertEquals(1, $users[0]['User']['post_count']);
515
		$this->assertEquals(2, $users[1]['User']['post_count']);
516
	}
517
518
/**
519
 * test Counter Cache With Self Joining table
@@ 650-665 (lines=16) @@
647
 *
648
 * @return void
649
 */
650
	public function testCounterCacheSkip() {
651
		$this->loadFixtures('CounterCacheUser', 'CounterCachePost');
652
		$User = new CounterCacheUser();
653
		$Post = new CounterCachePost();
654
655
		$data = $Post->find('first', array(
656
			'conditions' => array('id' => 1),
657
			'recursive' => -1
658
		));
659
		$data[$Post->alias]['user_id'] = 301;
660
		$Post->save($data, array('counterCache' => false));
661
662
		$users = $User->find('all', array('order' => 'User.id'));
663
		$this->assertEquals(2, $users[0]['User']['post_count']);
664
		$this->assertEquals(1, $users[1]['User']['post_count']);
665
	}
666
667
/**
668
 * test that beforeValidate returning false can abort saves.