connection = ConnectionManager::get('test'); Configure::write('App.namespace', 'TestApp'); } /** * teardown * * @return void */ public function tearDown() { parent::tearDown(); TableRegistry::clear(); } /** * Test saving new records sets uuids * * @return void */ public function testSaveNew() { $entity = new \Cake\ORM\Entity([ 'name' => 'shiny new', 'published' => true, ]); $table = TableRegistry::get('uuiditems'); $this->assertSame($entity, $table->save($entity)); $this->assertRegExp('/^[a-f0-9-]{36}$/', $entity->id, 'Should be 36 characters'); $row = $table->find('all')->where(['id' => $entity->id])->first(); $row->id = strtolower($row->id); $this->assertEquals($entity->toArray(), $row->toArray()); } /** * Test saving existing records works * * @return void */ public function testSaveUpdate() { $id = '481fc6d0-b920-43e0-a40d-6d1740cf8569'; $entity = new \Cake\ORM\Entity([ 'id' => $id, 'name' => 'shiny update', 'published' => true, ]); $table = TableRegistry::get('uuiditems'); $this->assertSame($entity, $table->save($entity)); $this->assertEquals($id, $entity->id, 'Should be 36 characters'); $row = $table->find('all')->where(['id' => $entity->id])->first(); $row->id = strtolower($row->id); $this->assertEquals($entity->toArray(), $row->toArray()); } /** * Test delete with string pk. * * @return void */ public function testDelete() { $id = '481fc6d0-b920-43e0-a40d-6d1740cf8569'; $table = TableRegistry::get('uuiditems'); $entity = $table->find('all')->where(['id' => $id])->first(); $this->assertTrue($table->delete($entity)); $query = $table->find('all')->where(['id' => $id]); $this->assertCount(0, $query->execute(), 'No rows left'); } }