Code Duplication    Length = 44-44 lines in 2 locations

tests/model/SQLSelectTest.php 2 locations

@@ 477-520 (lines=44) @@
474
		$this->assertEquals(array('Chimp', 'Brown'), $parameters);
475
	}
476
477
	public function testSelectFirst() {
478
		// Test first from sequence
479
		$query = new SQLSelect();
480
		$query->setFrom('"SQLSelectTest_DO"');
481
		$query->setOrderBy('"Name"');
482
		$result = $query->firstRow()->execute();
483
484
		$records = array();
485
		foreach($result as $row) {
486
			$records[] = $row;
487
		}
488
489
		$this->assertCount(1, $records);
490
		$this->assertEquals('Object 1', $records[0]['Name']);
491
492
		// Test first from empty sequence
493
		$query = new SQLSelect();
494
		$query->setFrom('"SQLSelectTest_DO"');
495
		$query->setOrderBy('"Name"');
496
		$query->setWhere(array('"Name"' => 'Nonexistent Object'));
497
		$result = $query->firstRow()->execute();
498
499
		$records = array();
500
		foreach($result as $row) {
501
			$records[] = $row;
502
		}
503
504
		$this->assertCount(0, $records);
505
506
		// Test that given the last item, the 'first' in this list matches the last
507
		$query = new SQLSelect();
508
		$query->setFrom('"SQLSelectTest_DO"');
509
		$query->setOrderBy('"Name"');
510
		$query->setLimit(1, 1);
511
		$result = $query->firstRow()->execute();
512
513
		$records = array();
514
		foreach($result as $row) {
515
			$records[] = $row;
516
		}
517
518
		$this->assertCount(1, $records);
519
		$this->assertEquals('Object 2', $records[0]['Name']);
520
	}
521
522
	public function testSelectLast() {
523
		// Test last in sequence
@@ 522-565 (lines=44) @@
519
		$this->assertEquals('Object 2', $records[0]['Name']);
520
	}
521
522
	public function testSelectLast() {
523
		// Test last in sequence
524
		$query = new SQLSelect();
525
		$query->setFrom('"SQLSelectTest_DO"');
526
		$query->setOrderBy('"Name"');
527
		$result = $query->lastRow()->execute();
528
529
		$records = array();
530
		foreach($result as $row) {
531
			$records[] = $row;
532
		}
533
534
		$this->assertCount(1, $records);
535
		$this->assertEquals('Object 2', $records[0]['Name']);
536
537
		// Test last from empty sequence
538
		$query = new SQLSelect();
539
		$query->setFrom('"SQLSelectTest_DO"');
540
		$query->setOrderBy('"Name"');
541
		$query->setWhere(array("\"Name\" = 'Nonexistent Object'"));
542
		$result = $query->lastRow()->execute();
543
544
		$records = array();
545
		foreach($result as $row) {
546
			$records[] = $row;
547
		}
548
549
		$this->assertCount(0, $records);
550
551
		// Test that given the first item, the 'last' in this list matches the first
552
		$query = new SQLSelect();
553
		$query->setFrom('"SQLSelectTest_DO"');
554
		$query->setOrderBy('"Name"');
555
		$query->setLimit(1);
556
		$result = $query->lastRow()->execute();
557
558
		$records = array();
559
		foreach($result as $row) {
560
			$records[] = $row;
561
		}
562
563
		$this->assertCount(1, $records);
564
		$this->assertEquals('Object 1', $records[0]['Name']);
565
	}
566
567
	/**
568
	 * Tests aggregate() function